Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * The purpose of this program is to read a clients file from a database regarding their cellphone usage
- * the month.
- * The program reads in the info and prints out in receipt form for the user who requests the
- * information and gives a basic overview of where charges are made.
- * The program is for users who are on a basic $15/month plan including access Fees and emergency
- * services costs
- * "T" Out oing text
- * "X" Incoming text (always free)
- * "I" Incoming call
- * "O" Outgoing call
- * @Authors Colin Smith & Edriane Moreno
- * v2.0
- */
- import java.util.Scanner;
- import java.io.*;
- public class Assignment3
- {
- public static void main (String [] args) throws IOException
- {
- // Prompt user to enter name of the datafile they are looking for
- String dataFile;
- Scanner in = new Scanner (System.in);
- System.out.print ("Enter the data filename: ");
- dataFile = in.nextLine();
- File file = new File ("c:/temp/" + dataFile + ".txt"); // user does not need to input ".txt"
- Scanner dfile = new Scanner (file);
- // Declare variables required for the program to run
- double cellUse, gst, totBeforeTax = 0, totAfterTax = 0, txtOutfee = 0, minsOverCost, txtOverCost;
- int cDay = 0, cLength = 0, txtIncounter = 0, txtOutcounter = 0, minCounter = 0, minsOver = 0,
- txtOver = 0;
- String name, acctNum, invNum, date, address, city, province, postCode, typeIn,
- cDate = " ", cHour = " ", cMin = " ";
- char type;
- //final values as they values do not change
- final double emerAccFee = 0.50, sysAccFee = 6.95, monFee = 15.00, minInPlanCost = 0,
- txtRecievedCost = 0, txtSentInPlanCost = 0;
- final int txtInPlan = 20, minInPlan = 50;
- //Reads in data from text file
- acctNum = dfile.nextLine();
- invNum = dfile.nextLine();
- date = dfile.nextLine();
- name = dfile.nextLine();
- address = dfile.nextLine();
- city = dfile.nextLine();
- province = dfile.nextLine();
- postCode = dfile.nextLine();
- //Print out name, acct number, and invoice number of client requesting information
- System.out.println (name);
- System.out.println ("Cellnet Account Summary: " + date);
- System.out.println ("Account Number: " + acctNum);
- System.out.println ("Invoice Number: " + invNum);
- while (dfile.hasNext())
- {
- typeIn = dfile.next();
- type = typeIn.toUpperCase().charAt(0);
- switch (type)
- {
- case 'T': //outgoing text
- cDate = dfile.next();
- cHour = dfile.next();
- cMin = dfile.next();
- txtOutcounter += 1;
- break;
- case 'X': //incoming text
- cDate = dfile.next();
- cHour = dfile.next();
- cMin = dfile.next();
- txtIncounter += 1;
- break;
- case 'I': //incoming calls
- cDate = dfile.next();
- cHour = dfile.next();
- cMin = dfile.next();
- cLength = dfile.nextInt();
- minCounter += cLength;
- break;
- case 'O': //outgoing calls
- cDate = dfile.next();
- cHour = dfile.next();
- cMin = dfile.next();
- cLength = dfile.nextInt();
- minCounter += cLength;
- break;
- //error check
- default:
- System.out.print ("Error: Invalid Type");
- break;
- }
- }
- //cellphone Usage calculations
- if (txtOutcounter > 20)
- {
- txtOver = txtOutcounter;
- txtOver -= txtInPlan;
- }
- if (minCounter > 50)
- {
- minsOver = minCounter;
- minsOver -= minInPlan;
- }
- minsOverCost = minsOver * 0.2;
- txtOverCost = txtOver * 0.1;
- cellUse = txtOverCost + minsOverCost;
- totBeforeTax = cellUse + monFee + sysAccFee + emerAccFee;
- gst = totBeforeTax * 0.05;
- totAfterTax = totBeforeTax + gst;
- System.out.println (" "); // creates space between printed lines for visual clarity
- System.out.println (name);
- System.out.println (address);
- System.out.println (city + ", " + province);
- System.out.println (postCode);
- // Regular charges section
- System.out.println ("Regular Charges");
- System.out.println (" "); // creates space between printed lines for visual clarity
- System.out.printf ("%35s%10s\n", "Description", "Cost");
- System.out.printf ("%35s%10.2f\n", "Cellnet usage (see below)", cellUse);
- System.out.printf ("%35s%10.2f\n", "Monthly Fee", monFee);
- System.out.printf ("%35s%10.2f\n", "System Access Fee", sysAccFee);
- System.out.printf ("%35s%10.2f\n", "9-1-1 Emergency Access Fee", emerAccFee);
- System.out.printf ("%35s%10.2f\n", "Total Before Tax", totBeforeTax);
- System.out.printf ("%35s%10.2f\n", "GST", gst);
- System.out.printf ("%35s%10.2f\n", "Total After Tax", totAfterTax);
- System.out.println (" "); // creates space between printed lines for visual clarity
- // Cellnet usuage charges section
- System.out.println ("Cellnet Usage Charges");
- System.out.printf ("%35s%20s%9s\n", "Description", "Minutes", "Cost");
- System.out.printf ("%35s%20d%9.2f\n", "Regular Minutes Included", minInPlan, minInPlanCost);
- System.out.printf ("%35s%20d%9.2f\n", "Minutes over Plan", minsOver, minsOverCost);
- System.out.printf ("%35s%20d%9.2f\n", "Texts Recieved", txtIncounter,txtRecievedCost);
- System.out.printf ("%35s%20d%9.2f\n", "Texts sent - Included", txtInPlan, txtSentInPlanCost);
- System.out.printf ("%35s%20d%9.2f\n", "Texts Ssent - Over", txtOver, txtOverCost);
- System.out.println ("Cellnet usage summary ending " + date);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement