473,802 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I need help with my homework!

1 New Member
I need to modify my current program so that is uses a class to store and retrieve the employees name, hourly rate, and number of hourse worked. Use a constructor to initialize the employee information, and a method within that class to calculate the weekly pay. Once stop is entered as the employee name the application should terminiate. Below is my previous code and some of what I think I need for this assignment. Any help would be great. Thanks.
Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner; //program uses class Scanner
  2.  
  3. public class EmployeePayroll2
  4. {
  5.    //main method begins execution of Java Application
  6.    public static void main(String args[])
  7.     {
  8.     //create scanner to obtain input from command window
  9.     Scanner input= new Scanner ( System.in);
  10.  
  11.  
  12.     String employeeName=""; //input employee name
  13.     double hourlyRate; //employees hourly rate
  14.     double hoursWorked; //hours worked for the week
  15.     double sum; //employees weekly pay
  16.  
  17.  
  18.  
  19.  
  20.     System.out.print("Enter Name of Employee:");//prompt
  21.     employeeName=input.next();//read name from user
  22.  
  23.  
  24.     while (!employeeName.equals("stop")) //ends program after entering stop
  25.     { 
  26.  
  27.     System.out.print("Enter hourly rate:");//prompt
  28.     hourlyRate = input.nextDouble(); //read rate from user
  29.  
  30.  
  31.     while (hourlyRate<0.0) //starts while loop to be sure number entered is positive
  32.     {
  33.     System.out.print("Hourly rate must be a positive number. Please enter a positive hourly rate:");//prompt
  34.     hourlyRate=input.nextDouble();//read first number 
  35.     input.nextLine();//prompt user for input
  36.     }//end while
  37.  
  38.     System.out.print("Enter hours worked:");//prompt
  39.     hoursWorked = input.nextDouble(); //read hours worked from user
  40.  
  41.  
  42.     while (hoursWorked<0.0) //Is number entered positive
  43.     {
  44.  
  45.     System.out.print("Hours worked must be a positive number. Please enter a positive number of hours:");//prompt
  46.     hoursWorked=input.nextDouble();//read second number
  47.     input.nextLine();//prompt
  48.  
  49.  
  50.     }
  51.     sum= hourlyRate * hoursWorked; //multiply numbers
  52.  
  53.     System.out.printf("The employee %s was paid $ %.2f this week", employeeName, sum);
  54.     //display name and sum
  55.  
  56.     System.out.print("Enter Name of Employee-Enter stop to end:");//prompt
  57.     employeeName=input.nextLine();//read name form user
  58.  
  59.     }//end while loop
  60.  
  61.  
  62.  
  63.       }//end method main
  64.  
  65.  }//end class EmployeePayroll2
  66.  
  67.  
  68. New stuff I know it is horrible!
  69.  
  70. public class Employee 
  71. {
  72.  
  73. private String employeeName; //input employee name
  74. private double hourlyRate;//employees hourly rate
  75. private int hoursWorked; //employee hours worked
  76.  
  77.  
  78. public Employee(String employeeName, double hourlyRate, int hoursWorked){
  79. // constructor for an employee object 
  80. employeeName = employeeName;
  81. hourlyRate = hourlyRate;
  82. hoursWorked = hoursWorked;
  83. }
  84.  
  85. public Employee(String employeeName, double hourlyRate){
  86. // overload of the constructor to set a default 40 hour work week
  87.  
  88. }
  89.  
  90. // get methods
  91.  
  92. public String getemployeeName(){
  93. return employeeName;
  94. }
  95.  
  96. public int gethoursWorked(){
  97. return hoursWorked;
  98. }
  99.  
  100. public double gethourlyRate(){
  101. return hourlyRate;
  102. }
  103.  
  104. // getter method to calculate and return the total
  105.  
  106. public double getTotal(){
  107. return (hoursWorked * hourlyRate);
  108. }
  109. }
Feb 15 '08 #1
1 1762
BigDaddyLH
1,216 Recognized Expert Top Contributor
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Feb 15 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1935
by: Bobby | last post by:
Hello everyone I have a question. The school I am working for is in the beginning process of having a webpage that will direct students to download there homework and be able to view there info like test scores and etc(the homework and info page will reside on our webservers at the school on the local intranet network). Now what I need is a way for the students to go to a login page and when logging in will be automatically directed to...
3
1406
by: Bobby | last post by:
I asked around about my problem, but so far no one has replied to me so I dont know if its possible or maybe i was posting in the wronng groups. Ok well I have a asp script going on my works website. The script basically is a logon script that gives a default page for each user (in my jobs case our students). Now the script had code in it giving the admininstrator an oppurtunity to send users a text message about news and whathaveya to...
31
2648
by: mark | last post by:
Hello- i am trying to make the function addbitwise more efficient. the code below takes an array of binary numbers (of size 5) and performs bitwise addition. it looks ugly and it is not elegant but it appears to work. using time, i measured it takes .041s to execute, which i admit isnt much. but, the problem is that this procedure will be called many, many times in my project (probably at least a few thousand times, if not more) so...
15
2290
by: carr4895 | last post by:
Hello. I was wondering if someone could help me too with a login form. Upon startup, I have to display a password screen and it should accept a user name and password. User name can be anything non-blank. If there is no user name, an appropriate error message must be displayed. All of the following passwords are valid IT160, VB2Manager, BackDoor. No other password is valid. It must allow the user to enter the password in any case. If...
1
1942
by: simonalexander | last post by:
I have got a homework task to do and I have started the work but I cannot finish it.Can someone please help me finish the code. The help given is much appreciated. The actual specifications are here: The task for this project is to write a simulator program for a robot designed to move packages around in a warehouse environment. The input to your program (from standard input) will contain a map of the environment in its original...
31
3153
by: Martin Jørgensen | last post by:
Hi, I've had a introductory C++ course in the spring and haven't programmed in C++ for a couple of months now (but I have been programmed in C since january). So I decided to do my conversion utility in C++, before I forget everything. But it doesn't compile: ------------
4
2514
by: sara | last post by:
i am studying a computer engineering and i started taking programming using C++ since month i have question i think it`s easy for you all *prof.programmer* but it`s bit diffecult for me plzz i need your help. (: this is the question: ** A new telephone communication company needs a billing calculation program. The cost of a call is based on the following three inputs that should be entered by the user, and they are explained as follows.
9
1313
by: Kodiak | last post by:
I am trying to write some javascript code in which you enter some text in one text box and the text will also appear in the second text box. For example, if I write the word "Test" both text boxes should have the same word in them. I need to be able to see the work actually being typed out in both text boxes as well. If I trye the letter T then both text boxes should have the same result all the type. If I delete the letter T then both...
1
1486
by: JoshPierce | last post by:
I want to allow users of my program to click File>Save and have a save dialog open and allow them to save all of their input. here is the background of my program. I have a program that allows students to calculate their grades as the class progresses. I want them to be able to type in their information and i already have the program written for them to be able to calculate everything via different types of work based on weights for homework...
8
29172
by: garyrowell | last post by:
I have been at this programme for hours trying to work out what is wrong. Any help would be very much appricated. Here is the breif I received. The program This week you are going to write three classes: Card.java, Deck.java and DeckTester.java. The specification for each class is given below. Card.Java This is a simple class that represents a playing card. Card has two attributes: • rank which is a String that represents the value...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10536
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10304
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10063
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9114
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.