Results 1 to 5 of 5
Thread: Error: { Expected in my code
- 10-23-2012, 03:20 AM #1
Member
- Join Date
- Oct 2012
- Posts
- 5
- Rep Power
- 0
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
- 10-23-2012, 06:50 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,538
- Rep Power
- 11
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.)
- 10-23-2012, 02:11 PM #3
Member
- Join Date
- Oct 2012
- Posts
- 5
- Rep Power
- 0
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!
- 10-23-2012, 03:49 PM #4
Re: Error: { Expected in my code
Why do they call it rush hour when nothing moves? - Robin Williams
- 10-23-2012, 06:22 PM #5
Member
- Join Date
- Oct 2012
- Posts
- 5
- Rep Power
- 0
Re: Error: { Expected in my code
If anyone wants to know, I know what I did wrong.
My String needs to be declared as
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.Java Code:private static String name;
Last edited by Mattiscool; 10-23-2012 at 06:23 PM. Reason: [\CODE] instead of [/CODE]
Similar Threads
-
Expected out put is not getting in this java thread code
By helioshilary in forum New To JavaReplies: 1Last Post: 06-28-2011, 04:16 PM -
';' expected error
By collwill in forum New To JavaReplies: 3Last Post: 05-03-2011, 07:51 AM -
Error Object Expected, Code 0
By martinmilroy in forum Java AppletsReplies: 0Last Post: 04-14-2011, 09:07 AM -
Error: ')' expected
By baltimore in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:32 AM -
My error is: ')' expected
By silvia in forum New To JavaReplies: 1Last Post: 07-18-2007, 04:49 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks