Advertisement
thotfrnk

final project ver1.java

Jan 15th, 2023
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.85 KB | None | 0 0
  1. import java.util.Scanner; //importing scanner
  2. public class finalproject_v1 { //program begins
  3.     public static void main(String[] args) { //main method
  4.  
  5.         Scanner input = new Scanner(System.in); //scanner declaration
  6.  
  7.         //array declaration for String, int, char, and double
  8.         String[] name = new String[10];
  9.         int[] student_id = new int[10];
  10.         char[] student_type = new char[10];
  11.         double[] student_fees = new double[10];
  12.         //variable declaration
  13.         int local_count = 0, international_count = 0, classes;
  14.         double extra_fees, discount_amt, totalMonetaryDiscount = 0, totalFeesOwed = 0;
  15.         final double discount = 0.15;
  16.         char course_type, answer;
  17.  
  18.         //for loop to populate the arrays 'name', 'student_id', and 'student_type' as well as to process the 10 students for their course type and class amount
  19.         //and count the local and international students
  20.         for (int student = 0; student < name.length; student++) {
  21.  
  22.             //input statements that will read and place the student's last name, id, and type into their respective arrays
  23.             System.out.println("Please enter your Student ID: ");
  24.             student_id[student] = input.nextInt();
  25.  
  26.             System.out.println("Please enter your last name: ");
  27.             name[student] = input.next();
  28.  
  29.             System.out.println("Please enter your student type. L for local and I for international: ");
  30.             student_type[student] = input.next().charAt(0);
  31.  
  32.             //while loop to verify the correct char response, it displays an error message and will repeat until the
  33.             //user enters the correct response
  34.             while (student_type[student] != 'L' && student_type[student] != 'I') {
  35.                 System.out.println("Invalid type. Please enter again.");
  36.  
  37.                 System.out.println("Please enter your student type. L for local and I for international: ");
  38.                 student_type[student] = input.next().charAt(0);
  39.             } //while loop ends
  40.  
  41.             //if statements to count the amount of local and international students
  42.             if (student_type[student] == 'L') {
  43.                 local_count++;
  44.             }
  45.  
  46.             if (student_type[student] == 'I') {
  47.                 international_count++;
  48.             } //if statements end
  49.  
  50.             //input statement that will read and accept the course type the user enters
  51.             System.out.println("Please enter your course type. Your options are E, M, P, C: ");
  52.             course_type = input.next().charAt(0);
  53.  
  54.             //while loop that will display an error message if the user doesn't enter any of the valid course types and will repeat the course type question
  55.             while (course_type != 'E' && course_type != 'M' && course_type != 'P' && course_type != 'C') {
  56.                 System.out.println("Invalid course type. Enter Again.");
  57.  
  58.                 System.out.println("Please enter your course type. Your options are E, M, P, C: ");
  59.                 course_type = input.next().charAt(0);
  60.             } //while loop ends
  61.  
  62.             //input statement to read and accept the amount of classes taken within selected course type
  63.             System.out.println("Amount of classes taken with selected course type: ");
  64.             classes = input.nextInt();
  65.  
  66.             //method call for store the fee calculations done within method in the student_fees array
  67.             student_fees[student] = studentFees(course_type, classes);
  68.  
  69.             //input statement to read and accept a yes or no answer if student is taking classes from more than one course type
  70.             System.out.println("Do you take classes from other course types? Y or N: ");
  71.             answer = input.next().charAt(0);
  72.  
  73.             //if statements that will display appropriate responses if the user selects either yes or no
  74.             if (answer == 'N') {
  75.                 System.out.println("Your information has been recorded.");
  76.             }
  77.  
  78.             if (answer == 'Y') {
  79.                 System.out.println("Please enter the other course types and number of classes taken. Press N to exit.");
  80.  
  81.                 //while loop being used as a continuous loop, it will continue asking for course type and classes until the user enter N, the exit code.
  82.                 while (answer != 'N') {
  83.                     System.out.println("Please enter your course type. Your options are E, M, P, C: ");
  84.                     course_type = input.next().charAt(0);
  85.  
  86.                     //while loop that will display an error message if the user doesn't enter any of the valid course types and will repeat the course type question
  87.                     //until the correct course type options is entered
  88.                     while (course_type != 'E' && course_type != 'M' && course_type != 'P' && course_type != 'C') {
  89.                         System.out.println("Invalid course type. Enter Again.");
  90.  
  91.                         System.out.println("Please enter your course type. Your options are E, M, P, C: ");
  92.                         course_type = input.next().charAt(0);
  93.                     } //end of while loop
  94.  
  95.                     System.out.println("Amount of classes taken with selected course type: ");
  96.                     classes = input.nextInt();
  97.  
  98.                     //method call to store the fee calculations done in method in extra_fees
  99.                     extra_fees = studentFees(course_type, classes);
  100.  
  101.                     //calculating the fees to be paid by adding the extra_fees to the initial student_fees
  102.                     student_fees[student] = extra_fees + student_fees[student];
  103.  
  104.                     //to update the while loop
  105.                     System.out.println("Do you take classes from other course types? Y or N: ");
  106.                     answer = input.next().charAt(0);
  107.  
  108.                     System.out.println("Your information has been recorded.");
  109.                 } //while loop ends
  110.             } //if statement ends
  111.  
  112.             //if statement being used to calculate discount for local students
  113.             if(student_type[student] == 'L') {
  114.                 //finding the amount of money they are discounted
  115.                 discount_amt = student_fees[student] * discount;
  116.  
  117.                 //calculating the final fee that has to be paid by subtracting the discount from the amount that is stored in the student_fees array
  118.                 //for that particular student
  119.                 student_fees[student] = student_fees[student] - discount_amt;
  120.  
  121.                 //calculating the total monetary discount that the school has given
  122.                 totalMonetaryDiscount+=discount_amt;
  123.             } //if statement ends
  124.  
  125.             //calculating the total amount of fees owed to the school
  126.             totalFeesOwed+=student_fees[student];
  127.  
  128.         } //for loop ends
  129.  
  130.         //for loop being used to output the contents of the arrays for student id, name, type, and fees owed
  131.         for (int ss = 0; ss < name.length; ss++) {
  132.             System.out.println("---------------------------------");
  133.  
  134.             System.out.println("STUDENT ID: " + student_id[ss]);
  135.             System.out.println("STUDENT'S LAST NAME: " + name[ss]);
  136.             System.out.println("STUDENT TYPE: " + student_type[ss]);
  137.             System.out.println("FEES OWED: " +student_fees[ss]);
  138.  
  139.             System.out.println("---------------------------------");
  140.  
  141.         } //for loop ends
  142.  
  143.         //blank print statement to make the output look neater
  144.         System.out.println();
  145.  
  146.         //more output statements for total amount of local and international students, and total amount of discounts and fees
  147.         System.out.println("LOCAL STUDENTS: " + local_count);
  148.         System.out.println("INTERNATIONAL STUDENTS: " + international_count);
  149.         System.out.println("TOTAL MONETARY DISCOUNT: " +totalMonetaryDiscount);
  150.         System.out.println("TOTAL FEES OWED TO INSTITUTION: " +totalFeesOwed);
  151.  
  152.     } //main class ends
  153.  
  154.     //method called studentFees, it takes on the arguments courseType and class_amt. this method uses a switch to calculate the amount of money
  155.     //the students owe to the school and returns that value
  156.     public static double studentFees(char courseType, int class_amt) {
  157.         //variable declaration
  158.         double studentFees = 0;
  159.         final double feeE = 850.53, feeM = 895.25, feeP = 450.67, feeC = 921.14;
  160.  
  161.         //switch statement to go through the different course types and to calculate the fees accordingly
  162.         switch (courseType) {
  163.             case 'E' -> studentFees = class_amt * feeE;
  164.             case 'M' -> studentFees = class_amt * feeM;
  165.             case 'P' -> studentFees = class_amt * feeP;
  166.             case 'C' -> studentFees = class_amt * feeC;
  167.         } //switch ends
  168.  
  169.         //return statement
  170.         return studentFees;
  171.  
  172.     } //studentFees method ends
  173. }//program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement