Solved

simple Java payroll problem

Posted on 2004-09-21
18
1,074 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mapAB Challlenge 35 89
pairs challenge 5 45
reasons why a "inside Menu" would not appear for a web server 6 45
JAVA part two 5 41
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

747 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now