Results 1 to 3 of 3
Thread: Method Error
- 08-01-2013, 11:41 PM #1
Member
- Join Date
- Aug 2013
- Posts
- 2
- Rep Power
- 0
Method Error
Java Code:import java.util.Scanner; public class RevisedPayroll { /** * main method begins execution of Java application */ public static void main(String[] args) { Scanner reader = new Scanner (System.in); double PayRate; double RegHours; double WeeklyPay; double RegPay; double Response; System.out.println("Employee name: "); String Name = reader.nextLine(); // read text if (Response == '2') { System.out.println( "Thank You! Have a nice day!" ); } else if (Response == '1') { System.out.print("Rate of pay: ");//user input prompt PayRate = reader.nextDouble();//read numbers System.out.println("Reg hours worked: ");//user input prompt RegHours = reader.nextDouble();//read numbers RegPay = PayRate * RegHours;//calculation WeeklyPay = RegPay;//calculation while( WeeklyPay <= -1) { System.out.println( "Payroll cannot be a negative number" ); } System.out.println(Name);//prints text System.out.printf("$%.2f\n", WeeklyPay); System.out.println( "Would you like to do another employee? 1 = yes, 2 = no"); Response = reader.nextDouble(); //Read Reply } }//end method main }//end class RevisedPayroll
The Problem
Hello, my problem is that I get an error saying the variable might not be initialized on line 21. All I am saying is that I need help finding a solution to this problem.
(Response == '2')
^
ErrorLast edited by JohnSalx28; 08-01-2013 at 11:45 PM.
- 08-02-2013, 01:39 AM #2
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: Method Error
You have a number of problems in your code.
1. Response is a double but you are trying to compare it to a character.
2. Response has not been assigned any value (assuming it is coming from the user).
3. Your while loop will continue for ever if WeeklyPay is ever <= -1
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 08-02-2013, 06:21 AM #3
Similar Threads
-
Help me I get this error: Error: Main method not found in class Position
By lo2 in forum New To JavaReplies: 8Last Post: 11-22-2012, 08:16 AM -
main method not found error in class . wat s the error?
By kirankumaragnihotram in forum New To JavaReplies: 10Last Post: 06-29-2012, 12:26 PM -
Why am i getting this error in my method?
By bdl1127 in forum New To JavaReplies: 1Last Post: 03-12-2012, 11:12 PM -
what does this error method mean?
By berkeley in forum New To JavaReplies: 1Last Post: 06-03-2010, 12:19 PM -
static method sparks error on overriding non-static method
By MuslimCoder in forum New To JavaReplies: 1Last Post: 02-10-2009, 11:03 AM
Bookmarks