Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- * Program: Prog
- *
- * Programmer: An Huynh
- * Date: X/X/X
- * School: Green Hope High School
- *
- * Description:
- *
- *
- * Learned:
- *
- * Difficulties:
- */
- package com.company;
- //import java.util.*;
- //import java.io.*;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Scanner;
- public class Prog213a {
- public static void main(String[] args) {
- //Initializing and declaring objects and variables
- double hoursDay, totalHours = 0, totalCash = 0, dayWeek = 0, week = 0, earnDay = 0;
- //Sets up scanner to read from file
- Scanner inFile = null;
- try {
- inFile = new Scanner(new File("C:\\Users\\Cyber\\Desktop\\AP Computer Science\\Text Files\\Prog213a.dat"));
- } catch (FileNotFoundException e) {
- System.out.println("File not found!");
- //Stop program if no file found
- System.exit(0);
- }
- //Prints Header
- System.out.print("Hours Worked:");
- do { //Loop that runs through numbers in file
- hoursDay = inFile.nextInt();
- totalHours += hoursDay;
- dayWeek++;
- //Prints hours worked that day
- System.out.print(" " + hoursDay);
- if (totalHours < 40) {//Checks if 40 hour limit has been passed
- if(hoursDay > 8) {//Checks if worked for more than 8 hours in a day
- earnDay += 8.0 * 30.0;
- hoursDay -= 8;
- earnDay += hoursDay * (30.0 + 25.50);
- }else {//Runs if worked for less than 8 hours;
- earnDay += hoursDay * 30.00;
- }
- } else {//Runs if worked for more than 40 hours
- if(hoursDay > 8) {//Checks if worked for more than 8 hours in a day
- earnDay += 8.0 * 30.0;
- hoursDay -= 8;
- earnDay += hoursDay * (30.00 + 15.00 + 25.50);
- }else {//Runs if worked for less than 8 hours;
- totalCash += hoursDay * (30.00 + 15.00);
- }
- }
- if (dayWeek == 5) {//Checks if its Saturday
- earnDay *= 2.25;
- } else if (dayWeek == 6) {//Checks if its Sunday
- earnDay *= 1.5;
- }
- //Calculates total money earned
- totalCash += earnDay;
- earnDay = 0;
- if (dayWeek >= 7) { //Resets everything at end of week and prints weekly statement
- week++;
- System.out.println("\nWeek #" + week + " $" + totalCash + "\n");
- dayWeek = 0;
- totalHours = 0;
- totalCash = 0;
- System.out.print("Hours Worked:");
- }
- } while(inFile.hasNext() != false); //Ends loop if no more lines left in text file.]
- System.out.println("Hours Worked: End of reading from code");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement