Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.21 KB | None | 0 0
  1. /*
  2. * The purpose of this program is to read a clients file from a database regarding their cellphone usage
  3. * the month.
  4. * The program reads in the info and prints out in receipt form for the user who requests the
  5. * information and gives a basic overview of where charges are made.
  6. * The program is for users who are on a basic $15/month plan including access Fees and emergency
  7. * services costs
  8. * "T" Out oing text
  9. * "X" Incoming text (always free)
  10. * "I" Incoming call
  11. * "O" Outgoing call
  12. * @Authors Colin Smith & Edriane Moreno
  13. * v2.0
  14. */
  15. import java.util.Scanner;
  16. import java.io.*;
  17. public class Assignment3
  18. {
  19. public static void main (String [] args) throws IOException
  20. {
  21. // Prompt user to enter name of the datafile they are looking for
  22. String dataFile;
  23. Scanner in = new Scanner (System.in);
  24. System.out.print ("Enter the data filename: ");
  25. dataFile = in.nextLine();
  26. File file = new File ("c:/temp/" + dataFile + ".txt"); // user does not need to input ".txt"
  27. Scanner dfile = new Scanner (file);
  28.  
  29. // Declare variables required for the program to run
  30. double cellUse, gst, totBeforeTax = 0, totAfterTax = 0, txtOutfee = 0, minsOverCost, txtOverCost;
  31. int cDay = 0, cLength = 0, txtIncounter = 0, txtOutcounter = 0, minCounter = 0, minsOver = 0,
  32. txtOver = 0;
  33. String name, acctNum, invNum, date, address, city, province, postCode, typeIn,
  34. cDate = " ", cHour = " ", cMin = " ";
  35. char type;
  36.  
  37. //final values as they values do not change
  38. final double emerAccFee = 0.50, sysAccFee = 6.95, monFee = 15.00, minInPlanCost = 0,
  39. txtRecievedCost = 0, txtSentInPlanCost = 0;
  40. final int txtInPlan = 20, minInPlan = 50;
  41.  
  42. //Reads in data from text file
  43. acctNum = dfile.nextLine();
  44. invNum = dfile.nextLine();
  45. date = dfile.nextLine();
  46. name = dfile.nextLine();
  47. address = dfile.nextLine();
  48. city = dfile.nextLine();
  49. province = dfile.nextLine();
  50. postCode = dfile.nextLine();
  51.  
  52. //Print out name, acct number, and invoice number of client requesting information
  53. System.out.println (name);
  54. System.out.println ("Cellnet Account Summary: " + date);
  55. System.out.println ("Account Number: " + acctNum);
  56. System.out.println ("Invoice Number: " + invNum);
  57. while (dfile.hasNext())
  58. {
  59. typeIn = dfile.next();
  60. type = typeIn.toUpperCase().charAt(0);
  61. switch (type)
  62. {
  63. case 'T': //outgoing text
  64. cDate = dfile.next();
  65. cHour = dfile.next();
  66. cMin = dfile.next();
  67. txtOutcounter += 1;
  68. break;
  69.  
  70. case 'X': //incoming text
  71. cDate = dfile.next();
  72. cHour = dfile.next();
  73. cMin = dfile.next();
  74. txtIncounter += 1;
  75. break;
  76.  
  77. case 'I': //incoming calls
  78. cDate = dfile.next();
  79. cHour = dfile.next();
  80. cMin = dfile.next();
  81. cLength = dfile.nextInt();
  82. minCounter += cLength;
  83. break;
  84.  
  85. case 'O': //outgoing calls
  86. cDate = dfile.next();
  87. cHour = dfile.next();
  88. cMin = dfile.next();
  89. cLength = dfile.nextInt();
  90. minCounter += cLength;
  91. break;
  92.  
  93. //error check
  94. default:
  95. System.out.print ("Error: Invalid Type");
  96. break;
  97.  
  98. }
  99. }
  100. //cellphone Usage calculations
  101. if (txtOutcounter > 20)
  102. {
  103. txtOver = txtOutcounter;
  104. txtOver -= txtInPlan;
  105. }
  106. if (minCounter > 50)
  107. {
  108. minsOver = minCounter;
  109. minsOver -= minInPlan;
  110. }
  111. minsOverCost = minsOver * 0.2;
  112. txtOverCost = txtOver * 0.1;
  113. cellUse = txtOverCost + minsOverCost;
  114. totBeforeTax = cellUse + monFee + sysAccFee + emerAccFee;
  115. gst = totBeforeTax * 0.05;
  116. totAfterTax = totBeforeTax + gst;
  117.  
  118. System.out.println (" "); // creates space between printed lines for visual clarity
  119. System.out.println (name);
  120. System.out.println (address);
  121. System.out.println (city + ", " + province);
  122. System.out.println (postCode);
  123. // Regular charges section
  124. System.out.println ("Regular Charges");
  125. System.out.println (" "); // creates space between printed lines for visual clarity
  126. System.out.printf ("%35s%10s\n", "Description", "Cost");
  127. System.out.printf ("%35s%10.2f\n", "Cellnet usage (see below)", cellUse);
  128. System.out.printf ("%35s%10.2f\n", "Monthly Fee", monFee);
  129. System.out.printf ("%35s%10.2f\n", "System Access Fee", sysAccFee);
  130. System.out.printf ("%35s%10.2f\n", "9-1-1 Emergency Access Fee", emerAccFee);
  131. System.out.printf ("%35s%10.2f\n", "Total Before Tax", totBeforeTax);
  132. System.out.printf ("%35s%10.2f\n", "GST", gst);
  133. System.out.printf ("%35s%10.2f\n", "Total After Tax", totAfterTax);
  134.  
  135.  
  136. System.out.println (" "); // creates space between printed lines for visual clarity
  137. // Cellnet usuage charges section
  138. System.out.println ("Cellnet Usage Charges");
  139. System.out.printf ("%35s%20s%9s\n", "Description", "Minutes", "Cost");
  140. System.out.printf ("%35s%20d%9.2f\n", "Regular Minutes Included", minInPlan, minInPlanCost);
  141. System.out.printf ("%35s%20d%9.2f\n", "Minutes over Plan", minsOver, minsOverCost);
  142. System.out.printf ("%35s%20d%9.2f\n", "Texts Recieved", txtIncounter,txtRecievedCost);
  143. System.out.printf ("%35s%20d%9.2f\n", "Texts sent - Included", txtInPlan, txtSentInPlanCost);
  144. System.out.printf ("%35s%20d%9.2f\n", "Texts Ssent - Over", txtOver, txtOverCost);
  145. System.out.println ("Cellnet usage summary ending " + date);
  146. }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement