Skip to content

Instantly share code, notes, and snippets.

@JoeValenti
Created February 28, 2015 23:54
Show Gist options
  • Save JoeValenti/2549d84c2425c2b56283 to your computer and use it in GitHub Desktop.
Save JoeValenti/2549d84c2425c2b56283 to your computer and use it in GitHub Desktop.
import java.text.DecimalFormat;
import java.util.Scanner;
public class PayAmmount {
public static void main(String[] args) {
double payRate, hoursWorked, totalPay;
Scanner keyScan = new Scanner(System.in);
Payroll myPayRoll;
// User input
System.out.print("What is your rate of pay: ");
payRate = keyScan.nextDouble();
System.out.print("How many hours did you work this week: ");
hoursWorked = keyScan.nextDouble();
myPayRoll = new Payroll(payRate,hoursWorked);
DecimalFormat moneyFormat = new DecimalFormat("$###,##0.00");
System.out.print("My pay check this week will be: ");
System.out.println(moneyFormat.format(myPayRoll.getPayRate()));
}
}
public class Payroll {
//Declare Variables
private double payRate;
private double hoursWorked;
private double totalPay;
public Payroll(double hourlyWage, double hours){
payRate = hourlyWage;
hoursWorked = hours;
if (hours > 40){
hours = (hours *1.5);
}
}
public void calcPay(){
totalPay = payRate * hoursWorked;
}
public double getHours(){
return hoursWorked;
}
public double getPayRate(){
return (payRate*hoursWorked);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment