Solved

simple Java payroll problem

Posted on 2004-09-21
18
1,087 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:Brayn66
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 9
18 Comments
 
LVL 92

Expert Comment

by:objects
ID: 12118875
> 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)
0
 

Author Comment

by:Brayn66
ID: 12119078

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
0
 
LVL 92

Expert Comment

by:objects
ID: 12119099
> 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.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:Brayn66
ID: 12119296
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
0
 
LVL 92

Expert Comment

by:objects
ID: 12119402
> 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?
0
 

Author Comment

by:Brayn66
ID: 12119469
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
0
 
LVL 92

Expert Comment

by:objects
ID: 12119509
Well to use that class you need to have it available somwhere.
0
 

Author Comment

by:Brayn66
ID: 12119517
How do I get this class to make it available to use?
0
 
LVL 92

Expert Comment

by:objects
ID: 12119521
> import terminalIO.KeyboardReader;

actually I think that should be:

import TerminalIO.KeyboardReader;
0
 

Author Comment

by:Brayn66
ID: 12119605
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
 
0
 
LVL 92

Expert Comment

by:objects
ID: 12119616
> System.out.println

you've still got problem I described earlier.
0
 

Author Comment

by:Brayn66
ID: 12119678
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
0
 

Author Comment

by:Brayn66
ID: 12119723
All I lack on this program is getting the calculated results to display. Any ideas? Lauren
0
 
LVL 92

Expert Comment

by:objects
ID: 12119787
because you never actually print it out :)

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

Author Comment

by:Brayn66
ID: 12121796
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

0
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 12121832
you need to actually print out the result, it doesn't happen automatically:

eg.

System.out.println("The total weekly pay is:$"+weeklyPay);
0
 

Author Comment

by:Brayn66
ID: 12128030
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
0
 
LVL 92

Expert Comment

by:objects
ID: 12128785
no worries :)
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question