Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. /*
  2. *
  3. * Program: Prog
  4. *
  5. * Programmer: An Huynh
  6. * Date: X/X/X
  7. * School: Green Hope High School
  8. *
  9. * Description:
  10. *
  11. *
  12. * Learned:
  13. *
  14. * Difficulties:
  15. */
  16. package com.company;
  17. //import java.util.*;
  18. //import java.io.*;
  19.  
  20. import java.io.File;
  21. import java.io.FileNotFoundException;
  22. import java.util.Scanner;
  23.  
  24. public class Prog213a {
  25. public static void main(String[] args) {
  26. //Initializing and declaring objects and variables
  27. double hoursDay, totalHours = 0, totalCash = 0, dayWeek = 0, week = 0, earnDay = 0;
  28.  
  29. //Sets up scanner to read from file
  30. Scanner inFile = null;
  31. try {
  32. inFile = new Scanner(new File("C:\\Users\\Cyber\\Desktop\\AP Computer Science\\Text Files\\Prog213a.dat"));
  33. } catch (FileNotFoundException e) {
  34. System.out.println("File not found!");
  35.  
  36. //Stop program if no file found
  37. System.exit(0);
  38. }
  39. //Prints Header
  40. System.out.print("Hours Worked:");
  41.  
  42. do { //Loop that runs through numbers in file
  43. hoursDay = inFile.nextInt();
  44. totalHours += hoursDay;
  45. dayWeek++;
  46.  
  47. //Prints hours worked that day
  48. System.out.print(" " + hoursDay);
  49.  
  50. if (totalHours < 40) {//Checks if 40 hour limit has been passed
  51. if(hoursDay > 8) {//Checks if worked for more than 8 hours in a day
  52. earnDay += 8.0 * 30.0;
  53. hoursDay -= 8;
  54. earnDay += hoursDay * (30.0 + 25.50);
  55. }else {//Runs if worked for less than 8 hours;
  56. earnDay += hoursDay * 30.00;
  57. }
  58. } else {//Runs if worked for more than 40 hours
  59. if(hoursDay > 8) {//Checks if worked for more than 8 hours in a day
  60. earnDay += 8.0 * 30.0;
  61. hoursDay -= 8;
  62. earnDay += hoursDay * (30.00 + 15.00 + 25.50);
  63. }else {//Runs if worked for less than 8 hours;
  64. totalCash += hoursDay * (30.00 + 15.00);
  65. }
  66. }
  67.  
  68. if (dayWeek == 5) {//Checks if its Saturday
  69. earnDay *= 2.25;
  70. } else if (dayWeek == 6) {//Checks if its Sunday
  71. earnDay *= 1.5;
  72. }
  73.  
  74. //Calculates total money earned
  75. totalCash += earnDay;
  76. earnDay = 0;
  77.  
  78. if (dayWeek >= 7) { //Resets everything at end of week and prints weekly statement
  79. week++;
  80. System.out.println("\nWeek #" + week + " $" + totalCash + "\n");
  81. dayWeek = 0;
  82. totalHours = 0;
  83. totalCash = 0;
  84. System.out.print("Hours Worked:");
  85. }
  86. } while(inFile.hasNext() != false); //Ends loop if no more lines left in text file.]
  87.  
  88. System.out.println("Hours Worked: End of reading from code");
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement