Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Empty Lab Exam 2 template
- // Program Id - Name - Description here
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.util.Scanner;
- public class NeilanDavidLabEx2{
- public static void main(String[] args) throws FileNotFoundException{
- // Constants
- final double UNIT_COST = 0.10;
- // File Objects/Variables
- Scanner usageFile = new Scanner(new FileReader("/home/david/IdeaProjects/2014NeilanDavidLabEx2/src/WaterUsage.dat"));
- // Record Layout
- int custId;
- char custStatus;
- String custFirstName;
- String custLastName;
- char custPlan;
- double custStandingCharge;
- int custFreeUnits;
- int customerUsage;
- // Other Variables
- String planName;
- double cost;
- int totalUsage, activeCustomers=0, inactiveCustomers=0, singleCustomers=0, pendingCustomers=0,
- doubleCustomers=0, concessionCustomers=0, famCustomers=0, bigFamCustomers=0, suspendedCustomers=0;
- // Screen/Report Header
- System.out.println(" Id Name Plan Stand Free Q1 Q2 Q3 Q4 Sum Avg Cost");
- System.out.println("================================================================================================");
- // Main while loop file Input until EOF
- while (usageFile.hasNext()){
- custId = usageFile.nextInt();
- custStatus= usageFile.next().charAt(0);
- custFirstName = usageFile.next();
- custLastName = usageFile.next();
- custPlan = usageFile.next().charAt(0);
- custStandingCharge = usageFile.nextDouble();
- custFreeUnits = usageFile.nextInt();
- totalUsage = 0;
- cost = custStandingCharge;
- if (Character.toUpperCase(custStatus) == 'A'){
- activeCustomers++;
- switch (Character.toLowerCase(custPlan)){
- case '1':
- planName = "Single";
- singleCustomers++;
- break;
- case '2':
- planName = "Double";
- doubleCustomers++;
- break;
- case 'c':
- planName = "Concession";
- concessionCustomers++;
- break;
- case 'f':
- planName = "Family";
- famCustomers++;
- break;
- case 'b':
- planName = "Big Family";
- bigFamCustomers++;
- break;
- default:
- planName = "Pending";
- pendingCustomers++;
- }
- System.out.printf("%-9d %-17s %-12s %5.2f %5d ", custId, (custLastName + ',' + custLastName), planName, custStandingCharge, custFreeUnits);
- for (int i=0;i<4;i++){
- customerUsage = usageFile.nextInt();
- totalUsage += customerUsage;
- System.out.printf("%4d ", customerUsage);
- }
- if (totalUsage > custFreeUnits){
- cost += (totalUsage-custFreeUnits)*UNIT_COST;
- }
- System.out.printf("%7d %7.2f %7.2f%n", totalUsage, totalUsage/4.0, cost);
- } else{
- usageFile.nextLine();
- switch (Character.toUpperCase(custStatus)){
- case 'X':
- inactiveCustomers++;
- break;
- case 'S':
- suspendedCustomers++;
- break;
- }
- }
- }
- // Output Footer details to Screen and Report
- System.out.println();
- System.out.printf("Customers:%4d ", activeCustomers+inactiveCustomers+suspendedCustomers);
- System.out.printf("Inactive:%4d " , inactiveCustomers);
- System.out.printf("Suspended:%4d " , suspendedCustomers);
- System.out.printf("Active:%4d%n" , activeCustomers);
- System.out.printf("Single:%4d " , singleCustomers);
- System.out.printf("Double:%4d " , doubleCustomers);
- System.out.printf("Concession:%4d%n" , concessionCustomers);
- System.out.printf("Family:%4d " , famCustomers);
- System.out.printf("Big Family:%4d ", bigFamCustomers);
- System.out.printf("Pending:%4d", pendingCustomers);
- // Close files
- } // main
- } // LastNameFirstNameLabEx2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement