Results 1 to 3 of 3

Thread: Method Error

  1. #1
    JohnSalx28 is offline Member
    Join Date
    Aug 2013
    Rep Power

    Default 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 (;               
    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')
    Last edited by JohnSalx28; 08-01-2013 at 11:45 PM.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default 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

    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Method Error

    4. Variable names should start with a lowercase letter.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 8
    Last Post: 11-22-2012, 08:16 AM
  2. main method not found error in class . wat s the error?
    By kirankumaragnihotram in forum New To Java
    Replies: 10
    Last Post: 06-29-2012, 12:26 PM
  3. Why am i getting this error in my method?
    By bdl1127 in forum New To Java
    Replies: 1
    Last Post: 03-12-2012, 11:12 PM
  4. what does this error method mean?
    By berkeley in forum New To Java
    Replies: 1
    Last Post: 06-03-2010, 12:19 PM
  5. Replies: 1
    Last Post: 02-10-2009, 11:03 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts