You are on page 1of 2

/*

* To change this license header, choose License Headers in Project Properties.


* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package studentassignment5;
import java.util.Scanner;
import java.text.DecimalFormat;
/**
*
* @author student
*/
public class studentAssignment5 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
//list variables
double months= 0.0; //the total number of months worded
double startingRate = 7.25; //the starting per-hour pay rate
double hours = 80.0; //the number of hours worked per month
boolean valid = false;
boolean isTrue = false;
double minWage = 7.25; //minimum wage
double newRate; //new per-hour pay rate after x amount of raises
double salary; //the monthly salary earned
double newSalary; //calculated Salary with the newRate
double totalSalary = 0.0; //running total of monthly salaries
//create a decimal format object for displaying output
DecimalFormat time = new DecimalFormat("##.##");
DecimalFormat dollar = new DecimalFormat("###,###,###.00");
//get input
while (!valid)
{
//create scanner object for reading input
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the total number of months worked: ");
months = keyboard.nextDouble();
if (months < 0)
{
System.out.println(" You need to enter a positive number "
+ " for the amount of months worked ");
break;
}
else
valid = true;
}
//verify the input
System.out.println("You are going to be paid for: " + time.format(months)
+ " months. ");
while (!isTrue) {
//get input for starting pay rate
System.out.print("Enter your starting per-hour pay rate: ");
Scanner key = new Scanner(System.in);
startingRate = key.nextDouble();
if (startingRate > minWage || startingRate == minWage)

isTrue = true;
if (minWage > startingRate)
{
System.out.println("You have to enter an amount greater than"
+ " that of minimum wage ($7.25/hr.) ");
}
}
System.out.println("Your starting pay-per-hour-rate is going to be: $ "
+ dollar.format(startingRate));
//calculate salary
salary = startingRate * hours;
//calculate new hourly rate for number of months given
for (int x=0; x<months; x++)
{
newRate = startingRate + x;
newSalary = newRate * hours;
System.out.println("Your salary for month " + (x+1)
+ " is going to be: $ " + dollar.format(newSalary));
totalSalary += newSalary; //running total of all months
}
//display salary for each month and total for all months
System.out.println("Your total salary earned for " + time.format(months)
+ " months worked is: $ " + dollar.format(totalSalary));
}
//end program
}

You might also like