Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Illegal start of expression.

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Illegal start of expression.

    This is my code i cant get passed one part that used to work and now doesnt. i dont know what I changed

    import java.util.*;
    public class Assign4b{
    public static void main(String[] args){
    Scanner input = new Scanner(System.in);
    processEmployeePay(input, getEmployeeCnt(input));
    double hours = 0.0;

    int employees;
    employees = getEmployeeCnt(input);

    }
    public static int getEmployeeCnt(Scanner input){
    System.out.print("How many employees are there: ");
    return result = input.nextInt();
    }

    public static void processEmployeePay(Scanner input, int employees){
    double hours = 0.0;
    double pay = 0.0;
    String name = "";
    double grossPay = 0.0;
    String topName = "";
    double topHours = 0.0;

    for(int i = 1; i <= employees; i++){
    System.out.print("Enter employee, hours worked, pay rate, and name seperated by a space: ");
    hours = input.nextDouble();
    pay = input.nextDouble();
    name = input.nextLine();
    grossPay = getGrossPay(hours, pay);

    for (int i = 1; i <= employees; i++){
    if (hours > tophours){
    hours = topHours;
    name = topName;

    displayEmployeePay(name, grossPay, hours, pay);
    }
    //call method that print congratulations(hours, name)
    }
    }

    public static double getGrossPay(double hours, double pay){
    double total= 0.0;
    if (hours <= 40){
    total = (pay * hours);
    }
    if (hours > 40 && hours < 48){
    total = (40 * pay) + ((hours - 40) * (pay * 1.5));
    }
    if (hours >= 48){
    total = ((pay * 2) * hours) + (40 * pay) + ((hours - 40) * (pay * 1.5));
    }
    return total;
    }
    public static void displayEmployeePay(String name, double grossPay, double hours, double pay){
    System.out.println("Employee name: \t" + name);
    System.out.println(" Hours Worked: \t" + hours);
    System.out.println(" Pay rate: \t" + pay);
    System.out.println(" Gross Pay: \t" + grossPay);
    System.out.println();
    }
    public static topEmployee(String topName, double topHours){
    if (topHours > 56){
    System.out.println("WOW!!!! What a Dynamo!" +topName+ "Worked "
    +topHours+ "Hours This WEEK!");
    } if else (topHours > 48){
    System.out.println(+topName+ "is Such a WorkHorse! Looks Like You Worked "
    +topHours+ "Hours this WEEK!");
    } if else (topHours > 40){
    System.out.println("Well, Good For YOU"+topName+", Who Worked "
    +topHours+"Hours this WEEL!");
    }
    else (topHours <= 40){
    System.out.println("Most hours but no one worked over 40: "+topName+"Worked "
    +topHours+ "Hours this WEEK!");
    }
    }
    }


    all the billion errors


    Assign4b.java:51: error: illegal start of expression
    public static double getGrossPay(double hours, double pay){
    ^
    Assign4b.java:51: error: illegal start of expression
    public static double getGrossPay(double hours, double pay){
    ^
    Assign4b.java:51: error: ';' expected
    public static double getGrossPay(double hours, double pay){
    ^
    Assign4b.java:51: error: '.class' expected
    public static double getGrossPay(double hours, double pay){
    ^
    Assign4b.java:51: error: ';' expected
    public static double getGrossPay(double hours, double pay){
    ^
    Assign4b.java:51: error: ';' expected
    public static double getGrossPay(double hours, double pay){
    ^
    Assign4b.java:64: error: illegal start of expression
    public static void displayEmployeePay(String name, double grossPay, double hours, double pay){
    ^
    Assign4b.java:64: error: illegal start of expression
    public static void displayEmployeePay(String name, double grossPay, double hours, double pay){
    ^
    Assign4b.java:64: error: ';' expected
    public static void displayEmployeePay(String name, double grossPay, double hours, double pay){
    ^
    Assign4b.java:64: error: ')' expected
    public static void displayEmployeePay(String name, double grossPay, double hours, double pay){
    ^
    Assign4b.java:64: error: illegal start of expression
    public static void displayEmployeePay(String name, double grossPay, double hours, double pay){
    ^
    Assign4b.java:64: error: ';' expected
    public static void displayEmployeePay(String name, double grossPay, double hours, double pay){
    ^
    Assign4b.java:64: error: not a statement
    public static void displayEmployeePay(String name, double grossPay, double hours, double pay){
    ^
    Assign4b.java:64: error: ';' expected
    public static void displayEmployeePay(String name, double grossPay, double hours, double pay){
    ^
    Assign4b.java:64: error: <identifier> expected
    public static void displayEmployeePay(String name, double grossPay, double hours, double pay){
    ^
    Assign4b.java:64: error: not a statement
    public static void displayEmployeePay(String name, double grossPay, double hours, double pay){
    ^
    Assign4b.java:64: error: ';' expected
    public static void displayEmployeePay(String name, double grossPay, double hours, double pay){
    ^
    Assign4b.java:71: error: illegal start of expression
    public static topEmployee(String topName, double topHours){
    ^
    Assign4b.java:71: error: illegal start of expression
    public static topEmployee(String topName, double topHours){
    ^
    Assign4b.java:71: error: ';' expected
    public static topEmployee(String topName, double topHours){
    ^
    Assign4b.java:71: error: <identifier> expected
    public static topEmployee(String topName, double topHours){
    ^
    Assign4b.java:71: error: not a statement
    public static topEmployee(String topName, double topHours){
    ^
    Assign4b.java:71: error: ';' expected
    public static topEmployee(String topName, double topHours){
    ^
    Assign4b.java:75: error: '(' expected
    } if else (topHours > 48){
    ^
    Assign4b.java:75: error: illegal start of expression
    } if else (topHours > 48){
    ^
    Assign4b.java:75: error: ')' expected
    } if else (topHours > 48){
    ^
    Assign4b.java:75: error: not a statement
    } if else (topHours > 48){
    ^
    Assign4b.java:75: error: ';' expected
    } if else (topHours > 48){
    ^
    Assign4b.java:78: error: '(' expected
    } if else (topHours > 40){
    ^
    Assign4b.java:78: error: illegal start of expression
    } if else (topHours > 40){
    ^
    Assign4b.java:78: error: ')' expected
    } if else (topHours > 40){
    ^
    Assign4b.java:78: error: not a statement
    } if else (topHours > 40){
    ^
    Assign4b.java:78: error: ';' expected
    } if else (topHours > 40){
    ^
    Assign4b.java:82: error: 'else' without 'if'
    else (topHours <= 40){
    ^
    Assign4b.java:82: error: not a statement
    else (topHours <= 40){
    ^
    Assign4b.java:82: error: ';' expected
    else (topHours <= 40){
    ^
    Assign4b.java:87: error: reached end of file while parsing
    }


  2. #2
    Member
    Join Date
    Jul 2013
    Location
    Franklin, TN
    Posts
    47
    Thanks
    3
    Thanked 4 Times in 4 Posts

    Default Re: Illegal start of expression.

    Hi.

    Can you please put your code in [CODE] tags so we can read it more clearly. Also just a picture of the command prompt and/or compiler you are using should be satisfactory This will assist the community in helping you further.

  3. #3
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Illegal start of expression.

    Quote Originally Posted by finding_my_inner_geek View Post
    all the billion errors
    Always treat the code as if there is exactly one error, the first error reported. Many times (and I think this is such a case) the first error causes a problem that makes the compiler see errors that are not errors. Correcting the first error will put things back into order. So work on the first error, correct it, then try to compile and run again. If there is an error then work on it.
    Without looking over the code, I would say to look at the {}'s to make sure there is not one missing or an extra one where it shouldn't be

Similar Threads

  1. illegal start of expression
    By JoeSmo in forum What's Wrong With My Code?
    Replies: 8
    Last Post: May 4th, 2013, 02:39 PM
  2. Illegal start of expression
    By Tedstriker in forum What's Wrong With My Code?
    Replies: 22
    Last Post: April 14th, 2013, 06:31 AM
  3. Illegal start of expression!
    By NoobOfTheMonth in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 11th, 2013, 09:53 PM
  4. Help With illegal start of expression
    By inshal in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 9th, 2013, 01:20 PM
  5. need help with illegal start of expression
    By inshal in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 9th, 2013, 11:25 AM