Advertisement
Guest User

Untitled

a guest
Nov 20th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.39 KB | None | 0 0
  1. package javaca2;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class JavaCA2 {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner in = new Scanner(System.in);
  9.  
  10.         //Variable/Constant Declaration.
  11.         final double FEES = 3000;
  12.         String userName, password, passwordVerify, eol, studentName, studentNum;
  13.         int attemptsRemain, userChoice, resultTot, numStudents = 0, paid100 = 0, paid75 = 0, paid50 = 0, paid0 = 0;
  14.         double resultAvg, totAvg = 0, feeGiven, overallPaid = 0;
  15.  
  16.         //Username Checking
  17.         System.out.print("Please enter Username (Minimum 6 characters): ");
  18.         userName = in.nextLine();
  19.  
  20.         for (attemptsRemain = 3; attemptsRemain != 0; attemptsRemain--) {
  21.             if (userName.length() < 6) {        //Loops if the username is too short
  22.                 System.out.println("Invalid Username " + attemptsRemain + " attempt(s) remaining.");
  23.                 System.out.print("\nPlease enter Username (Minimum 6 characters): ");
  24.                 userName = in.nextLine();
  25.             } else if (userName.length() >= 6) {    //Breaks out of the loop if it's the right length
  26.                 System.out.println("Username entered successfully.\n");
  27.                 break;
  28.             }
  29.         }
  30.         //Checks if Username is wrong too many times
  31.         if (attemptsRemain < 0) {
  32.             System.err.println("Username Entered wrong too many times, please try again.");
  33.             System.exit(0);
  34.         }
  35.  
  36.         //Password Checking
  37.         System.out.print("Please Enter your password (Case-Sensitive): ");
  38.         password = in.nextLine();
  39.         System.out.print("Please Verify your password (Case-Sensitive): ");
  40.         passwordVerify = in.nextLine();
  41.  
  42.         for (attemptsRemain = 3; attemptsRemain != 0; attemptsRemain--) {
  43.             if (!password.equals(passwordVerify)) {     //Loops if they don't match
  44.                 System.out.println("\nPasswords do not match, please try again. " + attemptsRemain + " attempt(s) remaining");
  45.  
  46.                 System.out.print("\nPlease Enter your password (Case-Sensitive): ");
  47.                 password = in.nextLine();
  48.                 System.out.print("Please Verify your password (Case-Sensitive): ");
  49.                 passwordVerify = in.nextLine();         //Breaks out of loop if they match
  50.             } else if (password.equals(passwordVerify)) {
  51.                 System.out.println("Password entered successfully.\n");
  52.                 break;
  53.             }
  54.         }
  55.         //Checks if the passwords are wrong too many times
  56.         if (attemptsRemain < 0) {
  57.             System.err.println("Password Entered wrong too many times, please try again.");
  58.             System.exit(0);
  59.         }
  60.  
  61.         //Menu System
  62.         System.out.println("\n\tStudent Finance System");
  63.         System.out.println("1. Calculate Student Grant");
  64.         System.out.println("2. Current Overall Student Average");
  65.         System.out.println("3. Fee Data");
  66.         System.out.println("4. Grant Category Information");
  67.         System.out.println("5. Exit");
  68.         userChoice = in.nextInt();
  69.  
  70.         while (userChoice != 5) {
  71.             switch (userChoice) {
  72.                 case 1:
  73.                     eol = in.nextLine();
  74.                     System.out.print("Enter Name: ");
  75.                     studentName = in.nextLine();
  76.                     System.out.print("Enter Student Number (XNumber): ");
  77.                     studentNum = in.nextLine();
  78.  
  79.                     while (studentNum.charAt(0) != 'X') {
  80.                         System.out.print("Please re-enter stduent number (must start with 'X'): ");
  81.                         studentNum = in.nextLine();
  82.                     }
  83.  
  84.                     resultTot = 0;
  85.                     System.out.print("Enter Software Development Result: ");
  86.                     resultTot += in.nextInt();
  87.                     System.out.print("Enter Mathematics Result: ");
  88.                     resultTot += in.nextInt();
  89.                     System.out.print("Enter Learning to Learn Result: ");
  90.                     resultTot += in.nextInt();
  91.                     System.out.print("Enter Computer Architecture Result: ");
  92.                     resultTot += in.nextInt();
  93.  
  94.                     resultAvg = (resultTot / 4.0);
  95.                     System.out.println();
  96.                    
  97.                     System.out.println(studentName + " (" + studentNum + ") Average Result: "+ resultAvg);
  98.                    
  99.                     if (resultAvg >= 90 && resultAvg <= 100) {
  100.                         feeGiven = FEES;
  101.                         System.out.print("100% ");
  102.                     }
  103.                     else if (resultAvg >=70 && resultAvg <90) {
  104.                         feeGiven = (FEES * 0.75);
  105.                         System.out.print("75% ");
  106.                        
  107.                     }
  108.                     else if (resultAvg >=50 && resultAvg <70) {
  109.                         feeGiven = (FEES * 0.50);
  110.                         System.out.print("50% ");                      
  111.                     }
  112.                     else if (resultAvg <=50 && resultAvg >= 0) {
  113.                         feeGiven = 0;
  114.                         System.out.print("0% ");                        
  115.                     }
  116.                     else {
  117.                         System.out.println("Invalid Result Average, Please try again");
  118.                         break;
  119.                     }
  120.                     System.out.printf("(€%.2f) of the €%.0f fee is paid." , feeGiven, FEES);
  121.                    
  122.                     numStudents++;
  123.                     totAvg += resultAvg;
  124.                     overallPaid += feeGiven;
  125.                     break;
  126.                 case 2:
  127.                     System.out.println("The Overall Average is: " + (totAvg / numStudents));
  128.                 case 3:
  129.                 case 4:
  130.                 default:
  131.  
  132.                     //Reprint Menu and ask for choice
  133.                     System.out.println("\n\n\tStudent Finance System");
  134.                     System.out.println("1. Calculate Student Grant");
  135.                     System.out.println("2. Current Overall Student Average");
  136.                     System.out.println("3. Fee Data");
  137.                     System.out.println("4. Grant Category Information");
  138.                     System.out.println("5. Exit");
  139.                     userChoice = in.nextInt();
  140.             }
  141.         }
  142.     }
  143.  
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement