Link to home
Start Free TrialLog in
Avatar of Brayn66
Brayn66

asked on

simple Java payroll problem

Any help would be appreciated!!
I am taking an introductory course in Java.
I am currently working on a payroll calculation problem.
This particular program should use method readDouble in the Keyboard reader class to gather user inputs(double).
The program must execute in the Terminal I/O from the user inputs.
I am having problems compiling my source code because of some errors (apparently two) that I cannot fiqure out.
I am trying to write a program that calculates weekly pay based on user inputs of the three variables listed below.
The following is my source code...     (with compile errors to follow)



import terminalIO.KeyboardReader;

public class KeyboardReader {
      public static void main( String [ ] args) {
      KeyboardReader reader = new KeyboardReader();

double hourlyRate;      
double regularHours;
double overtimeHours;

//get user imputs

System.out.print("Please enter your hourly pay rate:  \"");
hourlyRate = reader.readDouble();         // hourly rate entered by the user.
system.out.print

System.out.print("Please enter the amount of regular hours worked:  \"");
regularHours = reader.readDouble();       // regular number of hours worked entered by the user.
system.out.print

System.out.print("Please enter the amount of overtime hours worked:  \"");
overtimeHours = reader.readDouble();      // overtime hours worked entered by the user.
System.out.println("");

double overtimeRate = (hourlyrate * 1.5);
double weeklyPay = (hourlyrate * regularhours + overtimerate);

System.out.print("The total weekly pay is:$  \"");
weeklyPay = reader.readDouble();
System.out.println("");

      }
}




The following are the errors I receive when I try to compile it:

C:\ex\newweeklypay.java:20: ';' expected
System.out.print("Please enter the amount of regular hours worked:  \"");
          ^
C:\ex\newweeklypay.java:24: ';' expected
System.out.print("Please enter the amount of overtime hours worked:  \"");
          ^
2 errors
Tool completed with exit code 1


The circumflex (hats?) is under the method selector and this is probably an issue.?.?
I am frustrated, lauren

ps-thanks again
Avatar of Mick Barry
Mick Barry
Flag of Australia image

> system.out.print

this line is causing the errors, if you want to print a new line then use:L

System.out.println();

(there are two places this needs to be changed)
Avatar of Brayn66
Brayn66

ASKER


I have corrected the case sensitivity issue with the system.out.print

I changed them to:  System.out.println(); and get the following errors when trying to compile:

C:\ex\keyboardreader.java:4: class KeyboardReader is public, should be declared in a file named KeyboardReader.java
public class KeyboardReader {
       ^
C:\ex\keyboardreader.java:2: KeyboardReader is already defined in this compilation unit
import TerminalIO.KeyboardReader;
^
C:\ex\keyboardreader.java:17: cannot resolve symbol
symbol  : method readDouble ()
location: class KeyboardReader
hourlyRate = reader.readDouble();         // hourly rate entered by the user.
                   ^
C:\ex\keyboardreader.java:21: cannot resolve symbol
symbol  : method readDouble ()
location: class KeyboardReader
regularHours = reader.readDouble();       // regular number of hours worked entered by the user.
                     ^
C:\ex\keyboardreader.java:25: cannot resolve symbol
symbol  : method readDouble ()
location: class KeyboardReader
overtimeHours = reader.readDouble();      // overtime hours worked entered by the user.
                      ^
C:\ex\keyboardreader.java:28: cannot resolve symbol
symbol  : variable hourlyrate
location: class KeyboardReader
double overtimeRate = (hourlyrate * 1.5);
                       ^
C:\ex\keyboardreader.java:32: cannot resolve symbol
symbol  : method readDouble ()
location: class KeyboardReader
weeklyPay = reader.readDouble();
                  ^
7 errors

Tool completed with exit code 1



I don't know what happened this time!? lauren
> C:\ex\keyboardreader.java:4: class KeyboardReader is public, should be declared in a file named KeyboardReader.java

filename needs to be same as poublic class name (case sensitive)

> C:\ex\keyboardreader.java:2: KeyboardReader is already defined in this compilation unit

I'd suggest using a different class name for your class.
Avatar of Brayn66

ASKER

I have named the public class name: newweeklypay
My file name: newweeklypay.java

When I compile, I get the following errors:

C:\ex\newweeklypay.java:7: package terminalIO does not exist
import terminalIO.KeyboardReader;
                          ^
C:\ex\newweeklypay.java:12: cannot resolve symbol
symbol  : class KeyboardReader
location: class newweeklypay
      KeyboardReader reader = new KeyboardReader();
               ^
C:\ex\newweeklypay.java:12: cannot resolve symbol
symbol  : class KeyboardReader
location: class newweeklypay
      KeyboardReader reader = new KeyboardReader();
                                                             ^
3 errors
Tool completed with exit code 1

as you can see, the carrot(^)is under the letter K and I am not understanding why.

Thanks, lauren
> C:\ex\newweeklypay.java:7: package terminalIO does not exist

It cannot find the terminalIO package (containing the KeyboardReader class).
Where is that class currently?
Avatar of Brayn66

ASKER

I don't know.
I am copying examples from the book using a temperature conversion program that ask for a user input in the terminal io.

lauren
Well to use that class you need to have it available somwhere.
Avatar of Brayn66

ASKER

How do I get this class to make it available to use?
> import terminalIO.KeyboardReader;

actually I think that should be:

import TerminalIO.KeyboardReader;
Avatar of Brayn66

ASKER

I have this part:
 import TerminalIO.KeyboardReader;
               ...correct I think.
just to make surewe are on the same sheet here is the source code:


import TerminalIO.KeyboardReader;

public class newweeklypay {
      public static void main( String [] args) {

      KeyboardReader reader = new KeyboardReader();

double hourlyRate;
double regularHours;
double overtimeHours;

//get user imputs

System.out.println("Please enter your hourly pay rate:  \"");
hourlyRate = reader.readDouble();         // hourly rate entered by the user.
System.out.println

System.out.println("Please enter the amount of regular hours worked:  \"");
regularHours = reader.readDouble();       // regular number of hours worked entered by the user.
System.out.println

System.out.println("Please enter the amount of overtime hours worked:  \"");
overtimeHours = reader.readDouble();      // overtime hours worked entered by the user.
System.out.println("");

double overtimeRate = (hourlyRate * 1.5);
double weeklyPay = (hourlyRate * regularHours + overtimeRate);

System.out.println("The total weekly pay is:$  \"");
weeklyPay = reader.readDouble();
System.out.println("");

      }
}

-------------
Here's the errors when I compile:

C:\ex\newweeklypay.java:24: ';' expected
System.out.println("Please enter the amount of regular hours worked:  \"");
         ^
C:\ex\newweeklypay.java:28: ';' expected
System.out.println("Please enter the amount of overtime hours worked:  \"");
          ^
2 errors
Tool completed with exit code 1


--------------
Should I have the class name as: newweeklypay?  This is also what the filename is (newweeklypay.java)

thanks
 
> System.out.println

you've still got problem I described earlier.
Avatar of Brayn66

ASKER

I have corrected and now the terminal IO appears and ask for the inputs(as described in the program).
All seems well until the calculation should occur.

the last thing that comes up is :


The total weekly pay is:$   "
Press any key to continue........


Do you know if it is calculating and if it is, why won't it display??

lauren
Avatar of Brayn66

ASKER

All I lack on this program is getting the calculated results to display. Any ideas? Lauren
because you never actually print it out :)

System.out.println("The total weekly pay is:$  \"");
weeklyPay = reader.readDouble();
System.out.println("");
Avatar of Brayn66

ASKER

I apologize but I don't understand.

My assignment states:
"Wite a program that takes as imputs the hourly wage, total regular hours and total overtime hours and displays an employee's total weekly pay".

Do you think that my formulas are correctly written?

I thought that the results of the formulas calulationed would display in the window as the result.?.?

I feek like it is something minor dealing with the displaying of the calculations OR the calculations are not happening at this point.

thanks! lauren

ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Brayn66

ASKER

You were right all along. One unknown mistake led to the correction of another.
I had not put the output variable in the last statement for it to display in the Terminal IO.
A huge oversight on my part.
I have learned from you and appreciate it.
lauren
no worries :)