Advertisement
Kulas_Code20

Student Grade

Sep 20th, 2021
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.45 KB | None | 0 0
  1. package others.com;
  2.  
  3. import java.util.Scanner;
  4. import javax.swing.JOptionPane;
  5.  
  6. public class JavaApp {
  7.  
  8.     public static void main(String[] args) {
  9.         //Instance of StudentGrade class
  10.         StudentGarde studentMaria = new StudentGarde();
  11.         Scanner in = new Scanner(System.in);
  12.         int idNum, sumScore=0, ctr=0;
  13.         int[] score = new int[10];
  14.         String studFName, studLName;
  15.        
  16.         idNum = Integer.parseInt(JOptionPane.showInputDialog("Enter ID#: "));
  17.         studFName = JOptionPane.showInputDialog("Enter firstname: ");
  18.         studLName = JOptionPane.showInputDialog("Enter lastname: ");
  19.         System.out.println("Enter 5 score: ");
  20.         for(int i=0; i<5; i++) {
  21.             System.out.println("Enter score["+(i+1)+"]: ");
  22.             score[i] = in.nextInt();
  23.             ctr++;//to count the number of time it loop
  24.             if(score[i] < 70 || score[i] > 100) {
  25.                 System.out.println("Input should be 70-100");
  26.                 System.out.println("Enter score["+ctr+"]: ");
  27.                 score[i] = in.nextInt();
  28.             }
  29.             sumScore+=score[i];
  30.         }
  31.         //pass to the setters
  32.         studentMaria.setIdNumber(idNum);
  33.         studentMaria.setFirstName(studFName);
  34.         studentMaria.setLastName(studLName);
  35.         studentMaria.setScore(sumScore);
  36.        
  37.         //getting value from other class
  38.         int id = studentMaria.getIdNumber();
  39.         String fname = studentMaria.getFirstName();
  40.         String lname = studentMaria.getLastName();
  41.         double gradetotal = studentMaria.computeGrade();
  42.        
  43.         //Display outputs
  44.         System.out.println("\nId No: "+id);
  45.         System.out.println("FirstName: "+fname);
  46.         System.out.println("LastName: "+lname);
  47.         System.out.println("Grade: "+gradetotal);
  48.     }
  49.  
  50. }
  51. class StudentGarde {
  52.     //Declaration
  53.     private int idNumber, score;
  54.     private String firstName, lastName;
  55.     private double grade;
  56.    
  57.     //Constructor
  58.     public StudentGarde() {
  59.        
  60.     }
  61.  
  62.     public int getIdNumber() {
  63.         return idNumber;
  64.     }
  65.  
  66.     public void setIdNumber(int idNumber) {
  67.         this.idNumber = idNumber;
  68.     }
  69.  
  70.     public int getScore() {
  71.         return score;
  72.     }
  73.  
  74.     public void setScore(int score) {
  75.         this.score = score;
  76.     }
  77.  
  78.     public String getFirstName() {
  79.         return firstName;
  80.     }
  81.  
  82.     public void setFirstName(String firstName) {
  83.         this.firstName = firstName;
  84.     }
  85.  
  86.     public String getLastName() {
  87.         return lastName;
  88.     }
  89.  
  90.     public void setLastName(String lastName) {
  91.         this.lastName = lastName;
  92.     }
  93.  
  94.     public double getGrade() {
  95.         return grade;
  96.     }
  97.  
  98.     public void setGrade(double grade) {
  99.         this.grade = grade;
  100.     }
  101.    
  102.     public double computeGrade() {
  103.         grade = score/5;
  104.        
  105.         return grade;
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement