Saturday, October 4, 2014

Unreported exception java.io.IOException; must be caught or declared to be thrown
















Thank you for taking the time to help. I really appreciate it.
















I am getting the above error and am not sure which direction to proceed. In the class, the only way we have discussed getting user input is by System.in.read. I have searched and apparently found better methods for getting user input, but wanted to stick with what has been presented thus far.
















Assignment Directions:















1. Create a new class named “valuemethod”















2. Create a new method named “Main”















3. In Main Write the code that will call the method EnterPay and YearlySal















4. Create a new method named “EnterPay”















5. In the EnterPay method Write the code that asks the user to input their hourly wage. Use the formula to calculate their yearly salary: wage * 2040. Return the yearly salary to the main method















6. In the main method write the code that will display this: “Your yearly salary is:
























Java Code:




















package valuemethod;

public class Valuemethod
{

public static void main(String[] args)

//throws java.io.IOException -- moved to EnterPay
{
//double HourlyWage = EnterPay();
double YearlySal = EnterPay();
System.out.println ("Your yearly salary is: $" + YearlySal + "." );
}

public static double EnterPay()
throws java.io.IOException
{
double HourlyWage = 0;
double YearlySal = 0;

{
System.out.print("Enter your hourly wage:");
HourlyWage = (double) System.in.read();
}
YearlySal = HourlyWage*2040;
return YearlySal;
}

}

































No comments:

Post a Comment