Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

simple Java payroll problem

Posted on 2004-09-21
18
Medium Priority
?
1,094 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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.
Suggested Courses

876 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