• Post Reply Bookmark Topic Watch Topic
  • New Topic

How can i make this work  RSS feed

 
Paul Dyer
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a java book which i am going through for a University course. Im in the 1st year so my programming is not brilliant. I have spent way to long on this question which is to design and build a program which will input the number of workers followed by their name, hours worked, hourly rate of pay, overtime rate of pay, status married or single for each. The main program must use seperate methods and appropriate parimeters. Ok so im stuck on the first part. I would like to put the number of workers in, then ask for the names of that number of workers. I know that i need to implement some sort of counter in there maybe using a for loop but it will not compile. I have only used a for loop with a number it will work towards and not a number to count off another input. I hope you get me and any help would be appreciated. Thanks. Here is my terrible work so far.

 
Ash Jon
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Dyer wrote:I have a java book which i am going through for a University course. Im in the 1st year so my programming is not brilliant. I have spent way to long on this question which is to design and build a program which will input the number of workers followed by their name, hours worked, hourly rate of pay, overtime rate of pay, status married or single for each. The main program must use seperate methods and appropriate parimeters. Ok so im stuck on the first part. I would like to put the number of workers in, then ask for the names of that number of workers. I know that i need to implement some sort of counter in there maybe using a for loop but it will not compile. I have only used a for loop with a number it will work towards and not a number to count off another input. I hope you get me and any help would be appreciated. Thanks. Here is my terrible work so far.



Hi Paul. Have you studied the Object Orientated Programming topic for Java yet? If not, you would need to start there.

For example:



NOTE: This is not directly what is asked of you in the assignment question, but this should help to get you started,

Hope it helps,
Ash
 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, welcome to the Ranch!

One small admin matter: Please UseCodeTags to format your code nicely. It makes it much easier to read. I've gone in and done it for you this time :-)

You are right, you need a counter - and you need to keep that counter separate from the total number of workers the user just input!
What you've done in your code is overwritten the number of workers you just read in from the user with the number "1" to start looping.

Simplest fix: declare a new variable to keep track of which worker we are dealing with. If we are just going to use it within the loop, then lets declare it there.
The standard template for a for loop is:

This declares a variable 'i', starts it at 0, and goes up to 'count' executing what is in the braces once for each value.
But what is count? It should be the number of times you want to loop, which in this case is the number you just input: workers.


Next you will need a place to store ALL of the workers names.
The 'name' variable you have declared will store one of them.
To store multiple names, you will probably need an Array.
 
Paul Dyer
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies peeps i was not expecting a reply that quick. I am on a chapter in the book which is called sub programs, arrays are the next chapter and looking through this chapter there is nothing on oriented programming. I will try to implement the for loop the way Stefan has advised me. Here is the exact question.

Design, build and test a program to input the number of workers followed by their name, hours worked, hourly rate of pay, overtime rate of pay, status (married or single) for each. The main program must use separate methods and appropriate parameters. Suggested methods include:

calculate the gross pay (overtime rate is paid for any number of hours above 40)
calculate the amount of tax paid(25% if married and 30% if single)
display all the details as a payslip on the computer screen

HINT: You can pass String parameters too!

i have considered maybe i asked the first question wrong or i dont understand the question.

The chapters i studied before sub programs are getting started, The bricks and mortar of programming, beginning with design, selection, loops. When i have a problem i usually look back through my programs and they do normally answer that task, somehow. Sorry to go on and i do really appreciate the help. Ill jump on the for loop and try to get it to compile. Really appreciated. Thank you
 
Paul Dyer
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im not sure on how to use code tags but here it is and working i should be ok with the rest. Thanks again

 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again

The code tags work like ↑ that. Well, you can read about them here and for advanced use here (scroll to the bottom). I deleted some excess blank lines which don't add to legibility.
 
Paul Dyer
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ty i will make sure i do this in the future. You peeps are really helpful
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Dyer wrote:Ty i will make sure i do this in the future. You peeps are really helpful


While you're going through the links Campbell gave you, you might like to also check out this page
 
Paul Dyer
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will take more care in the future and apologize for using short hand words.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!