Skip to content

Instantly share code, notes, and snippets.

@LordNairu
Last active December 28, 2015 15:08
Show Gist options
  • Save LordNairu/7519193 to your computer and use it in GitHub Desktop.
Save LordNairu/7519193 to your computer and use it in GitHub Desktop.
package qub.ac.uk.practical.week5;
public class PracticalFiveQuestionOne {
/**
* Constant rate of pay.
*/
public static final double PAY_RATE = 10.25;
/**
* A method which calculates wages from an array
* @param args
*/
public static void main(String[] args) {
// declaring variables
double realWeekly=0;
int totalHours=0;
// Designing array for day and hours worked
String [] dayArray = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};
int [] payArray = { 8, 7, 9, 7, 4 };
// Looping to print day and hours worked
for (int counter=0; counter < payArray.length; counter++){
System.out.printf(dayArray[counter]);
System.out.print(": ");
System.out.println(payArray[counter]);
}
// Calculate total hours worked in an enhanced for
for (int hours : payArray)
{
totalHours += hours;
}
// Add up and print out
realWeekly = totalHours * PAY_RATE;
System.out.println("\nTotal Hours Worked: " + totalHours);
System.out.println("Weekly Wage: " + realWeekly);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment