Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaca2;
- import java.util.Scanner;
- public class JavaCA2 {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- //Variable/Constant Declaration.
- final double FEES = 3000;
- String userName, password, passwordVerify, eol, studentName, studentNum;
- int attemptsRemain, userChoice, resultTot, numStudents = 0, paid100 = 0, paid75 = 0, paid50 = 0, paid0 = 0;
- double resultAvg, totAvg = 0, feeGiven, overallPaid = 0;
- //Username Checking
- System.out.print("Please enter Username (Minimum 6 characters): ");
- userName = in.nextLine();
- for (attemptsRemain = 3; attemptsRemain != 0; attemptsRemain--) {
- if (userName.length() < 6) { //Loops if the username is too short
- System.out.println("Invalid Username " + attemptsRemain + " attempt(s) remaining.");
- System.out.print("\nPlease enter Username (Minimum 6 characters): ");
- userName = in.nextLine();
- } else if (userName.length() >= 6) { //Breaks out of the loop if it's the right length
- System.out.println("Username entered successfully.\n");
- break;
- }
- }
- //Checks if Username is wrong too many times
- if (attemptsRemain < 0) {
- System.err.println("Username Entered wrong too many times, please try again.");
- System.exit(0);
- }
- //Password Checking
- System.out.print("Please Enter your password (Case-Sensitive): ");
- password = in.nextLine();
- System.out.print("Please Verify your password (Case-Sensitive): ");
- passwordVerify = in.nextLine();
- for (attemptsRemain = 3; attemptsRemain != 0; attemptsRemain--) {
- if (!password.equals(passwordVerify)) { //Loops if they don't match
- System.out.println("\nPasswords do not match, please try again. " + attemptsRemain + " attempt(s) remaining");
- System.out.print("\nPlease Enter your password (Case-Sensitive): ");
- password = in.nextLine();
- System.out.print("Please Verify your password (Case-Sensitive): ");
- passwordVerify = in.nextLine(); //Breaks out of loop if they match
- } else if (password.equals(passwordVerify)) {
- System.out.println("Password entered successfully.\n");
- break;
- }
- }
- //Checks if the passwords are wrong too many times
- if (attemptsRemain < 0) {
- System.err.println("Password Entered wrong too many times, please try again.");
- System.exit(0);
- }
- //Menu System
- System.out.println("\n\tStudent Finance System");
- System.out.println("1. Calculate Student Grant");
- System.out.println("2. Current Overall Student Average");
- System.out.println("3. Fee Data");
- System.out.println("4. Grant Category Information");
- System.out.println("5. Exit");
- userChoice = in.nextInt();
- while (userChoice != 5) {
- switch (userChoice) {
- case 1:
- eol = in.nextLine();
- System.out.print("Enter Name: ");
- studentName = in.nextLine();
- System.out.print("Enter Student Number (XNumber): ");
- studentNum = in.nextLine();
- while (studentNum.charAt(0) != 'X') {
- System.out.print("Please re-enter stduent number (must start with 'X'): ");
- studentNum = in.nextLine();
- }
- resultTot = 0;
- System.out.print("Enter Software Development Result: ");
- resultTot += in.nextInt();
- System.out.print("Enter Mathematics Result: ");
- resultTot += in.nextInt();
- System.out.print("Enter Learning to Learn Result: ");
- resultTot += in.nextInt();
- System.out.print("Enter Computer Architecture Result: ");
- resultTot += in.nextInt();
- resultAvg = (resultTot / 4.0);
- System.out.println();
- System.out.println(studentName + " (" + studentNum + ") Average Result: "+ resultAvg);
- if (resultAvg >= 90 && resultAvg <= 100) {
- feeGiven = FEES;
- System.out.print("100% ");
- }
- else if (resultAvg >=70 && resultAvg <90) {
- feeGiven = (FEES * 0.75);
- System.out.print("75% ");
- }
- else if (resultAvg >=50 && resultAvg <70) {
- feeGiven = (FEES * 0.50);
- System.out.print("50% ");
- }
- else if (resultAvg <=50 && resultAvg >= 0) {
- feeGiven = 0;
- System.out.print("0% ");
- }
- else {
- System.out.println("Invalid Result Average, Please try again");
- break;
- }
- System.out.printf("(€%.2f) of the €%.0f fee is paid." , feeGiven, FEES);
- numStudents++;
- totAvg += resultAvg;
- overallPaid += feeGiven;
- break;
- case 2:
- System.out.println("The Overall Average is: " + (totAvg / numStudents));
- case 3:
- case 4:
- default:
- //Reprint Menu and ask for choice
- System.out.println("\n\n\tStudent Finance System");
- System.out.println("1. Calculate Student Grant");
- System.out.println("2. Current Overall Student Average");
- System.out.println("3. Fee Data");
- System.out.println("4. Grant Category Information");
- System.out.println("5. Exit");
- userChoice = in.nextInt();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement