Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › need some serious help.
New Posts  All Forums:Forum Nav:

need some serious help.

post #1 of 10
Thread Starter 

 

not sure if right section but...
 
so i gotten this assignment from my CSC professor as homework. now i've missed last few classes due to sickness and i've been trying to catch up so i really need to hand this in.
 

 

Quote:
Write a Java program that will input an integer representing number of hours a person worked and a double representing the hourly rate. (use JOptionPane). Calculate the pay. (multiply hours times rate). Print the pay. If the pay is more that 500, then print a message that the bonus is 100.00; else the bonus is 60.00. Add the bonus to the pay and print the total.

 

i been trying to give it a go to the best of my knowledge(as well as the power of google) so i figured i'd ask OCN for some help.
 
- yes i am a programming noob/nub/newb, etc, etc. as this is a intro class
- the professor uses jCreator
- i need something "basic" enough that i would be able to understand and replicate on any given day.
 
so far i've only gotten up to here, but will work on it as this thread hopefully get some views and replies.
 
**
update = so i gotten the code down to do everything the assignment asked for.
 
Add the bonus to the pay and print the total.  << how to get this though?
 

 


Edited by DF is BUSY - 2/17/12 at 12:55pm
post #2 of 10
Well, if you want to add the bonus to the pay simply do an
Code:
if(pay>500)
{
pay=pay+100.00; 
}
else
{
pay=pay+60.00;
}

Then print the total on screen.
First Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k @4.5Ghz Gigabyte Z68X-UD7 B3 MSI 6950 G.Skill Sniper 2x4GB 
Hard DriveHard DriveHard DriveCooling
Crucial M4 64GB Samsung SpinPoint 250GB Hitachi 1TB Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows Server 2012 Samsung S22B300 22' ViewSonic VA703B 17" CM Quickfire TK 
PowerCaseMouse
Corsair HX850 NZXT Phantom Mionix Naos 3200 
  hide details  
Reply
First Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k @4.5Ghz Gigabyte Z68X-UD7 B3 MSI 6950 G.Skill Sniper 2x4GB 
Hard DriveHard DriveHard DriveCooling
Crucial M4 64GB Samsung SpinPoint 250GB Hitachi 1TB Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows Server 2012 Samsung S22B300 22' ViewSonic VA703B 17" CM Quickfire TK 
PowerCaseMouse
Corsair HX850 NZXT Phantom Mionix Naos 3200 
  hide details  
Reply
post #3 of 10
Thread Starter 
Quote:
Originally Posted by Barbaroti View Post

Well, if you want to add the bonus to the pay simply do an
Code:
if(pay>500)
{
pay=pay+100.00; 
}
else
{
pay=pay+60.00;
}
Then print the total on screen.

 

1) wrote that in, nothing happened

2) print total on screen using something like system.out.println?
 

 

post #4 of 10
Well, can I see the code you have in right now?
First Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k @4.5Ghz Gigabyte Z68X-UD7 B3 MSI 6950 G.Skill Sniper 2x4GB 
Hard DriveHard DriveHard DriveCooling
Crucial M4 64GB Samsung SpinPoint 250GB Hitachi 1TB Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows Server 2012 Samsung S22B300 22' ViewSonic VA703B 17" CM Quickfire TK 
PowerCaseMouse
Corsair HX850 NZXT Phantom Mionix Naos 3200 
  hide details  
Reply
First Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k @4.5Ghz Gigabyte Z68X-UD7 B3 MSI 6950 G.Skill Sniper 2x4GB 
Hard DriveHard DriveHard DriveCooling
Crucial M4 64GB Samsung SpinPoint 250GB Hitachi 1TB Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows Server 2012 Samsung S22B300 22' ViewSonic VA703B 17" CM Quickfire TK 
PowerCaseMouse
Corsair HX850 NZXT Phantom Mionix Naos 3200 
  hide details  
Reply
post #5 of 10
Thread Starter 

 

 

Quote:
/* Write a Java program that will input an integer representing number of hours a person worked, 
 * and a double representing the hourly rate.
 * Calculate the pay.
 * Print the pay.
 * If the pay is more than 500, then print a message that the bonus is 100.00;
 * else the bonus is 60.00.
*/
 
// Add the bonus to the pay and print the total.
 
 
 
 import javax.swing.JOptionPane;
 import java.text.DecimalFormat;
 
 public class feb16hw
 {
  public static void main (String[] args)
  {
  DecimalFormat twoD = new DecimalFormat("0.00");
  double hourlyrate, pay;
  int hoursworked;
  String payStr;
 
  payStr = JOptionPane.showInputDialog("Please enter hours worked.");
  hoursworked   = Integer.parseInt( payStr );
 
  payStr = JOptionPane.showInputDialog("Please enter hourly rate.");
  hourlyrate   = Double.parseDouble( payStr);
 
  pay  = (hoursworked * hourlyrate);
  {
  System.out.println("Your total pay is " + twoD.format(pay));
  }
 
  if ( pay > 500)
  {
 
  System.out.println("Bonus is 100.00");
  }
  else
  {
 
  System.out.println("Bonus is 60.00");
  }
  {
 
  }
  }
 }

^

- running this in jCreator correctly prompts me to input "hours worked" following a prompt to input "hourly rate"

- it then prints my "total pay" as well as the "bonus".

 

i just cant seem to figure out how to make java add "pay" and "bonus" together.

 

 

 

( what is the command to post something in a code format for overclock.net? ) lol


Edited by DF is BUSY - 2/17/12 at 1:40pm
post #6 of 10
change the if/else to this:
Code:
if (pay > 500)
 {
    total = pay + 100.00;
    System.out.println("Bonus is 100.00");
} 
else
{
   total = pay + 60.00;
   System.out.println("Bonus is 60.00");
}

System.out.println("Total is " + twoD.format(total));

Don't use >= in the if, as your hw says that it has to be bigger than 500.00, so you can't include it in the 100.00 bonus

Edit: For codes, you can use the Code tag, it's to the right of the spoiler one
Edited by Barbaroti - 2/17/12 at 1:32pm
First Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k @4.5Ghz Gigabyte Z68X-UD7 B3 MSI 6950 G.Skill Sniper 2x4GB 
Hard DriveHard DriveHard DriveCooling
Crucial M4 64GB Samsung SpinPoint 250GB Hitachi 1TB Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows Server 2012 Samsung S22B300 22' ViewSonic VA703B 17" CM Quickfire TK 
PowerCaseMouse
Corsair HX850 NZXT Phantom Mionix Naos 3200 
  hide details  
Reply
First Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k @4.5Ghz Gigabyte Z68X-UD7 B3 MSI 6950 G.Skill Sniper 2x4GB 
Hard DriveHard DriveHard DriveCooling
Crucial M4 64GB Samsung SpinPoint 250GB Hitachi 1TB Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows Server 2012 Samsung S22B300 22' ViewSonic VA703B 17" CM Quickfire TK 
PowerCaseMouse
Corsair HX850 NZXT Phantom Mionix Naos 3200 
  hide details  
Reply
post #7 of 10
Thread Starter 


 

Quote:
Originally Posted by Barbaroti View Post

change the if/else to this:
Code:
if (pay > 500)
 {
    total = pay + 100.00;
    System.out.println("Bonus is 100.00");
} 
else
{
   total = pay + 60.00;
   System.out.println("Bonus is 60.00");
}
System.out.println("Total is " + twoD.format(total));
Don't use >= in the if, as your hw says that it has to be bigger than 500.00, so you can't include it in the 100.00 bonus
Edit: For codes, you can use the Code tag, it's to the right of the spoiler one


 

line 35,40,44

 

"cannot find symbol variable total"

post #8 of 10
Change your double declaration to this:
Code:
double hoursworked, hourlyrate, pay, total;

You also need to declare total as it's a new variable
First Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k @4.5Ghz Gigabyte Z68X-UD7 B3 MSI 6950 G.Skill Sniper 2x4GB 
Hard DriveHard DriveHard DriveCooling
Crucial M4 64GB Samsung SpinPoint 250GB Hitachi 1TB Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows Server 2012 Samsung S22B300 22' ViewSonic VA703B 17" CM Quickfire TK 
PowerCaseMouse
Corsair HX850 NZXT Phantom Mionix Naos 3200 
  hide details  
Reply
First Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k @4.5Ghz Gigabyte Z68X-UD7 B3 MSI 6950 G.Skill Sniper 2x4GB 
Hard DriveHard DriveHard DriveCooling
Crucial M4 64GB Samsung SpinPoint 250GB Hitachi 1TB Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows Server 2012 Samsung S22B300 22' ViewSonic VA703B 17" CM Quickfire TK 
PowerCaseMouse
Corsair HX850 NZXT Phantom Mionix Naos 3200 
  hide details  
Reply
post #9 of 10
Thread Starter 

ah! yes i forgot to declare the total variable.

 

>.< basics =[

 

 

and thanks man everything worked out at the end! appreciate taking out time to help me with this!

 

+rep

post #10 of 10
Sure np, glad to have been of help thumb.gif
First Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k @4.5Ghz Gigabyte Z68X-UD7 B3 MSI 6950 G.Skill Sniper 2x4GB 
Hard DriveHard DriveHard DriveCooling
Crucial M4 64GB Samsung SpinPoint 250GB Hitachi 1TB Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows Server 2012 Samsung S22B300 22' ViewSonic VA703B 17" CM Quickfire TK 
PowerCaseMouse
Corsair HX850 NZXT Phantom Mionix Naos 3200 
  hide details  
Reply
First Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k @4.5Ghz Gigabyte Z68X-UD7 B3 MSI 6950 G.Skill Sniper 2x4GB 
Hard DriveHard DriveHard DriveCooling
Crucial M4 64GB Samsung SpinPoint 250GB Hitachi 1TB Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows Server 2012 Samsung S22B300 22' ViewSonic VA703B 17" CM Quickfire TK 
PowerCaseMouse
Corsair HX850 NZXT Phantom Mionix Naos 3200 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › need some serious help.