Results 1 to 5 of 5
  1. #1
    Mattiscool is offline Member
    Join Date
    Oct 2012
    Posts
    5
    Rep Power
    0

    Default Error: { Expected in my code

    As you will undoubtedly see, I'm very new to Java.
    I'm trying to write a code that uses methods to input user data (about pay and work hours) and manipulate that data to give you your full pay.
    Here's the code, the error is on line 5 (Error: { Expected)
    Thanks for the help!

    Java Code:
    import java.util.*;
    import javax.swing.*; 
    import java.awt.*;
    
    public class Project7.4Revision     <-- The error line
      {
      String name;
    static final double overtimePay;
    private static double regularHours;
    private static double overtimeHours;
    private static double regularWage;
    private static double totalWage;
    private static double employeeID;
      
    public static void main(String[] args)
    
    {
    setData();
    calcTotalWage();
    printResults();
    }
    
    public static void setData() //Get all the Data
    {
    Scanner scanner = new Scanner(System.in);
    System.out.print("Enter Name Here: "); //Have user input name
    name = scanner.nextLine();
    
    System.out.print("Employee ID Please, " + name + ": ");
    employeeID = reader.nextDouble(); //Have user input Employee ID
    
    System.out.print("Number of regular hours please: "); //Have user input # of hours worked
    regularHours = reader.nextDouble();
    
    System.out.print("Wage please (In Dollars/Hour): "); //Have user input normal wage
    regularWage = reader.nextDouble();
    
    System.out.print("Numbe of overtime hours please: "); //Have user input # of overtime hours
    overtimeHours = reader.nextDouble();
    
    overtimePay = 1.5;
    }
    public static void calcTotalWage()
    {
    totalWage = (regularHours * regularWage) + (overtimeHours * overtimePay);
    }
    public static void printResults() //Show the results
    {
    System.out.println("Greetings " + name);
    System.out.println("Your Employee ID is " + employeeID);
    System.out.println("With your " + regularHours + " of nonovertime pay at " + regularWage + "$");
    System.out.println("And your " + overtimeHours + " of overtime pay at " + overtimePay + "$");
    System.out.println("You made " + totalWage + "$");
    }
    }
    Last edited by Mattiscool; 10-23-2012 at 05:16 PM. Reason: Didn't wrap code

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Error: { Expected in my code

    Take the dot out of the classname. What happens? (You'll have to change the .java filename to match the new class name.)

  3. #3
    Mattiscool is offline Member
    Join Date
    Oct 2012
    Posts
    5
    Rep Power
    0

    Default Re: Error: { Expected in my code

    I get a whole bunch of errors; I changed the name and basically remade the file so it was called "k," as that is much easier of a name to work with.
    Now I'm getting about 8 errors.
    Error: non-static variable name cannot be referenced from static context
    The line is: name = scanner.nextLine();
    Error: non-static variable name cannot be referenced from static context
    The line is: System.out.print("Employee ID Please, " + name + ": ");
    Error: Cannot Find Symbol
    The line is: employeeID = reader.nextDouble();
    Error: Cannot Find Symbol
    The line is: regularHours = reader.nextDouble();
    Error: Cannot Find Symbol
    The line is: regularWage = reader.nextDouble();
    Error: Cannot Find Symbol
    The line is: overtimeHours = reader.nextDouble();
    Error: Cannot assign a value to final variable overtimePay
    The line is: overtimePay = 1.5; (I got rid of this by removing the "final" when declaring the overtimePay variable.
    Error: non-static variable name cannot be referenced from static context
    The line is: System.out.println("Greetings " + name);
    I think I'm screwing something up with the string "name." I have no idea what I would have done wrong, because all of my basic syntax is correct, so I must have structured the program wrong.
    Thanks for helping me find all these other errors, I think if I fix them then the program should run!

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: Error: { Expected in my code

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

  5. #5
    Mattiscool is offline Member
    Join Date
    Oct 2012
    Posts
    5
    Rep Power
    0

    Default Re: Error: { Expected in my code

    If anyone wants to know, I know what I did wrong.
    My String needs to be declared as
    Java Code:
     private static String name;
    I also created a Scanner object named scanner, but in my program I kept doing reader.next...(); which doesn't make since, since the scanner is scanner, not reader.
    Last edited by Mattiscool; 10-23-2012 at 06:23 PM. Reason: [\CODE] instead of [/CODE]

Similar Threads

  1. Expected out put is not getting in this java thread code
    By helioshilary in forum New To Java
    Replies: 1
    Last Post: 06-28-2011, 04:16 PM
  2. ';' expected error
    By collwill in forum New To Java
    Replies: 3
    Last Post: 05-03-2011, 07:51 AM
  3. Error Object Expected, Code 0
    By martinmilroy in forum Java Applets
    Replies: 0
    Last Post: 04-14-2011, 09:07 AM
  4. Error: ')' expected
    By baltimore in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:32 AM
  5. My error is: ')' expected
    By silvia in forum New To Java
    Replies: 1
    Last Post: 07-18-2007, 04:49 PM

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
  •