SHARE
TWEET

Untitled

a guest May 24th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. import java.util.ArrayList;
  8. import java.util.Scanner;
  9.  
  10. class Data {
  11.     public static ArrayList<AssociativeGrade> Grades = new ArrayList<AssociativeGrade>();
  12.     public static ArrayList<AssociativeStudent> Students = new ArrayList<AssociativeStudent>();
  13. }
  14.  
  15. class AssociativeStudent {
  16.    
  17.     private String name;
  18.     private String mark1;
  19.     private String mark2;
  20.     private String mark3;
  21.     private String average;
  22.     private String grade;
  23.    
  24.     public void setName(String name) {
  25.         this.name = name;
  26.     }
  27.    
  28.     public String getName() {
  29.         return this.name;
  30.     }
  31.     public void setMark1(String mark1) {
  32.         this.mark1 = mark1;
  33.     }
  34.     public String getMark1() {
  35.         return this.mark1;
  36.     }
  37.     public void setMark2(String mark2) {
  38.         this.mark2 = mark2;
  39.     }
  40.     public String getMark2() {
  41.         return this.mark2;
  42.     }
  43.     public void setMark3(String mark3) {
  44.         this.mark3 = mark3;
  45.     }
  46.    
  47.     public String getMark3() {
  48.         return this.mark3;
  49.     }
  50.    
  51.     public void setGrade(String grade) {
  52.         this.grade = grade;
  53.     }
  54.     public String getGrade() {
  55.         return this.grade;
  56.     }
  57.     public void setAverage(String average) {
  58.         this.average = average;
  59.     }
  60.     public String getAverage() {
  61.         return this.average;
  62.     }
  63.    
  64. }
  65.  
  66. class AssociativeGrade {
  67.    
  68.     private String from;
  69.     private String to;
  70.     private String grade;
  71.    
  72.     public void setFrom(String from) {
  73.         this.from = from;
  74.     }
  75.     public String getFrom() {
  76.         return this.from;
  77.     }
  78.     public void setTo(String to) {
  79.         this.to = to;
  80.     }
  81.     public String getTo() {
  82.         return this.to;
  83.     }
  84.     public void setGrade(String grade) {
  85.         this.grade = grade;
  86.     }
  87.     public String getGrade() {
  88.         return this.grade;
  89.     }
  90. }
  91.        
  92. class Grade {
  93.    
  94.     public AssociativeGrade ag;
  95.    
  96.     public Grade() {
  97.         this.ag = new AssociativeGrade();
  98.         this.ag.setFrom("90");
  99.         this.ag.setTo("100");
  100.         this.ag.setGrade("A");
  101.        
  102.         Data.Grades.add(this.ag);
  103.        
  104.         this.ag = new AssociativeGrade();
  105.         this.ag.setFrom("90");
  106.         this.ag.setTo("80");
  107.         this.ag.setGrade("B");
  108.        
  109.         Data.Grades.add(this.ag);
  110.        
  111.         this.ag = new AssociativeGrade();
  112.         this.ag.setFrom("70");
  113.         this.ag.setTo("79");
  114.         this.ag.setGrade("C");
  115.        
  116.         Data.Grades.add(this.ag);
  117.        
  118.         this.ag = new AssociativeGrade();
  119.         this.ag.setFrom("60");
  120.         this.ag.setTo("69");
  121.         this.ag.setGrade("D");
  122.        
  123.         Data.Grades.add(this.ag);
  124.        
  125.         this.ag = new AssociativeGrade();
  126.         this.ag.setFrom("0");
  127.         this.ag.setTo("59");
  128.         this.ag.setGrade("E");
  129.        
  130.         Data.Grades.add(this.ag);
  131.        
  132.     }
  133.    
  134.     public ArrayList<AssociativeGrade> getDataGrades() {
  135.         return Data.Grades;
  136.     }
  137. }
  138.  
  139. class Student {
  140.    
  141.     public AssociativeStudent as;
  142.    
  143.     public void insert(String name, String mark1, String mark2, String mark3, String average, String grade) {
  144.         this.as = new AssociativeStudent();
  145.         this.as.setName(name);
  146.         this.as.setMark1(mark1);
  147.         this.as.setMark2(mark2);
  148.         this.as.setMark3(mark3);
  149.         this.as.setAverage(average);
  150.         this.as.setGrade(grade);
  151.        
  152.         Data.Students.add(this.as);
  153.     }
  154.    
  155.     public ArrayList<AssociativeStudent> getStudents() {
  156.         return Data.Students;
  157.     }
  158.    
  159.     public void showTable() {
  160.         for(int i=0; i< this.getStudents().size(); i++) {
  161.             System.out.print("Nama");
  162.             System.out.print("\tMark");
  163.             System.out.print("\tMark 2");
  164.             System.out.print("\tMark 3");
  165.             System.out.print("\tAverage");
  166.             System.out.print("\tGrade");
  167.             System.out.println();
  168.             System.out.print("" + this.getStudents().get(i).getName());
  169.             System.out.print("\t" + this.getStudents().get(i).getMark1());
  170.             System.out.print("\t" + this.getStudents().get(i).getMark2());
  171.             System.out.print("\t" + this.getStudents().get(i).getMark3());
  172.             System.out.print("\t" + this.getStudents().get(i).getAverage());
  173.             System.out.print("\t" + this.getStudents().get(i).getGrade());
  174.             System.out.println();
  175.         }
  176.     }
  177. }
  178.  
  179. class Rumus {
  180.     public static String getCalculateAverage(String mark1, String mark2, String mark3) {
  181.         double results = (Integer.parseInt(mark1) + Integer.parseInt(mark2) + Integer.parseInt(mark3));
  182.         double result = results / 3;
  183.         return String.valueOf(result);
  184.     }
  185.     public static String getCalculateGrade(String average) {
  186.         String gr = "Unknown";
  187.         double av = Double.parseDouble(average);
  188.        
  189.         for(int i=0; i < Data.Grades.size(); i++) {
  190.             int from = Integer.parseInt(Data.Grades.get(i).getFrom());
  191.             int to =  Integer.parseInt(Data.Grades.get(i).getTo());
  192.            
  193.             if(av >= from && av <= to) {
  194.                 // GRADE A-E
  195.                 gr = Data.Grades.get(i).getGrade();
  196.             }
  197.         }
  198.        
  199.         return gr;
  200.     }
  201. }
  202. public class Task3_10 {
  203.  
  204.     /**
  205.      * @param args the command line arguments
  206.      */
  207.     public static void main(String[] args) {
  208.         // TODO code application logic here
  209.        
  210.         Grade grade = new Grade();
  211.         Student student = new Student();
  212.        
  213.         Scanner sc = new Scanner(System.in);
  214.        
  215.         System.out.print("Enter number of students? ");
  216.        
  217.         int numberOfStudents = sc.nextInt();
  218.        
  219.         for(int i=1; i  <= numberOfStudents; i++) {
  220.             System.out.println("Enter name and 3 marks for student " + i + "?");
  221.            
  222.             System.out.print("Name :");
  223.             String name = sc.next();
  224.            
  225.             System.out.print("Mark 1 :");
  226.             String mark1 = sc.next();
  227.            
  228.             System.out.print("Mark 2 :");
  229.             String mark2 = sc.next();
  230.            
  231.             System.out.print("Mark 3 :");
  232.             String mark3 = sc.next();
  233.            
  234.             String _average = Rumus.getCalculateAverage(mark1, mark2, mark3);
  235.             String _grade = Rumus.getCalculateGrade(_average);
  236.            
  237.             student.insert(
  238.                     name, mark1, mark2, mark3, _average,_grade
  239.             );
  240.         }
  241.        
  242.         int choice;
  243.         do {
  244.            
  245.             System.out.println();      
  246.             System.out.println("1: Print the entire list");
  247.             System.out.println("2: Sort and print the list alphabetically");
  248.             System.out.println("3: Sort and print the list in descending order based on the average");
  249.             System.out.println("4: Ask the user to enter an average and search for the student who has that average");
  250.             System.out.println("5: Find the student who has the minimum average");
  251.             System.out.println("6: Print the grade distribution");
  252.             System.out.println("0: Exit");
  253.             System.out.println();      
  254.             System.out.print("Enter your choice?");
  255.             choice = sc.nextInt();
  256.             System.out.println();
  257.            
  258.             switch(choice) {
  259.                 case 1:
  260.                     student.showTable();
  261.                 break;
  262.                 case 2:
  263.                  
  264.                 break;
  265.             }
  266.         }while(choice != 0);
  267.        
  268.         System.out.println("Terima kasih ! ^_^");
  269.        
  270.     }
  271. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top