Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package practise;
- import java.util.Scanner;
- public class CGPACalculator {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- // DATA 1 - CREDIT HOURS
- // DATA 2 - GRADE VALUE
- //
- // --------- Initialize all calculators --------- //
- double credit_hours1 = 0;
- double credit_hours2 = 0;
- double credit_hours3 = 0;
- double credit_hours4 = 0;
- double credit_hours5 = 0;
- double credit_hours6 = 0;
- double credit_hours7 = 0;
- double credit_hours8 = 0;
- double credit_hours9 = 0;
- System.out.println("Calculator has been initialized.");
- // ----------- Declare sub1 - sub9 ------------ //
- double sub1 ;
- double sub2 ;
- double sub3 ;
- double sub4 ;
- double sub5 ;
- double sub6 ;
- double sub7 ;
- double sub8 ;
- double sub9 ;
- // --------- Declare grade1 - grade 9 ---------- //
- int grade1 = 0;
- int grade2 = 0;
- int grade3 = 0;
- int grade4 = 0;
- int grade5 = 0;
- int grade6 = 0;
- int grade7 = 0;
- int grade8 = 0;
- int grade9 = 0;
- System.out.println("Grades have been declared within each subject.");
- // -------- Declare LCA --------- //
- char a; // A
- char b; // A-
- char c; // B+
- char d; // B
- char e; // B-
- char f; // C+
- char g; // C
- char h; // C-
- char i; // D+
- char j; // D
- char k; // F
- System.out.println("Grades have been declared.");
- //-------- Preset LCA to grades ---------- //
- a = 'A' ;
- b = 'B' ;
- c = 'C' ;
- d = 'D' ;
- e = 'E' ;
- f = 'F' ;
- g = 'G' ;
- h = 'H' ;
- i = 'I' ;
- j = 'J' ;
- k = 'K' ;
- System.out.println("LCA Grades have been preset.");
- // -------- Assign Grade to Value ---------- //
- final double A = 4.00 ;
- final double B = 3.67 ;
- final double C = 3.33 ;
- final double D = 3.00 ;
- final double E = 2.67 ;
- final double F = 2.33 ;
- final double G = 2.00 ;
- final double H = 1.67 ;
- final double I = 1.33 ;
- final double J = 1.00 ;
- final double K = 0.00 ;
- System.out.println("Grade value has been loaded.");
- // --------- Insertion of data for Credit Hours --------- //
- Scanner scanner = new Scanner(System.in);
- System.out.println("Enter credit hours for subject : Engineering Drawing ... ");
- credit_hours1 = scanner.nextDouble();
- System.out.println("Enter grade achieved");
- grade1 = scanner.next().charAt(0);
- System.out.println("Enter credit hours for subject : Engineering Science ... ");
- credit_hours2 = scanner.nextDouble();
- System.out.println("Enter grade achieved");
- grade2 = scanner.next().charAt(0);
- System.out.println("Enter credit hours for subject : Workshop Practices ... ");
- credit_hours3 = scanner.nextDouble();
- System.out.println("Enter grade achieved");
- grade3 = scanner.next().charAt(0);
- System.out.println("Enter credit hours for subject : Conventional Turning ... ");
- credit_hours4 = scanner.nextDouble();
- System.out.println("Enter grade achieved");
- grade4 = scanner.next().charAt(0);
- System.out.println("Enter credit hours for subject : Engineering Meteorology ... ");
- credit_hours5 = scanner.nextDouble();
- System.out.println("Enter grade achieved");
- grade5 = scanner.next().charAt(0);
- System.out.println("Enter credit hours for subject : English for Communication 1 ... ");
- credit_hours6 = scanner.nextDouble();
- System.out.println("Enter grade achieved");
- grade6 = scanner.next().charAt(0);
- System.out.println("Enter credit hours for subject : Engineering Mathematics 1 ... ");
- credit_hours7 = scanner.nextDouble();
- System.out.println("Enter grade achieved");
- grade7 = scanner.next().charAt(0);
- System.out.println("Enter credit hours for subject : Perspektif Islam ... ");
- credit_hours8 = scanner.nextDouble();
- System.out.println("Enter grade achieved");
- grade8 = scanner.next().charAt(0);
- System.out.println("Enter credit hours for subject : Co-Curriculum 1 ... ");
- credit_hours9 = scanner.nextDouble();
- System.out.println("Enter grade achieved");
- grade9 = scanner.next().charAt(0);
- sub1 = credit_hours1 * grade1;
- sub2 = credit_hours2 * grade2;
- sub3 = credit_hours3 * grade3;
- sub4 = credit_hours4 * grade4;
- sub5 = credit_hours5 * grade5;
- sub6 = credit_hours6 * grade6;
- sub7 = credit_hours7 * grade7;
- sub8 = credit_hours8 * grade8;
- sub9 = credit_hours9 * grade9;
- // ------- Declare grand total ------- //
- double subs;
- double totalch;
- double pointer;
- subs = sub1 + sub2 + sub3 + sub4 + sub5 + sub6 + sub7 + sub8 + sub9;
- totalch = credit_hours1 + credit_hours2 + credit_hours3 + credit_hours4 + credit_hours5 + credit_hours6 + credit_hours7 + credit_hours8 + credit_hours9;
- pointer = subs / totalch ;
- System.out.printf("Pointer is %.2f .", pointer);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement