Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package others.com;
- import java.util.Scanner;
- import javax.swing.JOptionPane;
- public class JavaApp {
- public static void main(String[] args) {
- //Instance of StudentGrade class
- StudentGarde studentMaria = new StudentGarde();
- Scanner in = new Scanner(System.in);
- int idNum, sumScore=0, ctr=0;
- int[] score = new int[10];
- String studFName, studLName;
- idNum = Integer.parseInt(JOptionPane.showInputDialog("Enter ID#: "));
- studFName = JOptionPane.showInputDialog("Enter firstname: ");
- studLName = JOptionPane.showInputDialog("Enter lastname: ");
- System.out.println("Enter 5 score: ");
- for(int i=0; i<5; i++) {
- System.out.println("Enter score["+(i+1)+"]: ");
- score[i] = in.nextInt();
- ctr++;//to count the number of time it loop
- if(score[i] < 70 || score[i] > 100) {
- System.out.println("Input should be 70-100");
- System.out.println("Enter score["+ctr+"]: ");
- score[i] = in.nextInt();
- }
- sumScore+=score[i];
- }
- //pass to the setters
- studentMaria.setIdNumber(idNum);
- studentMaria.setFirstName(studFName);
- studentMaria.setLastName(studLName);
- studentMaria.setScore(sumScore);
- //getting value from other class
- int id = studentMaria.getIdNumber();
- String fname = studentMaria.getFirstName();
- String lname = studentMaria.getLastName();
- double gradetotal = studentMaria.computeGrade();
- //Display outputs
- System.out.println("\nId No: "+id);
- System.out.println("FirstName: "+fname);
- System.out.println("LastName: "+lname);
- System.out.println("Grade: "+gradetotal);
- }
- }
- class StudentGarde {
- //Declaration
- private int idNumber, score;
- private String firstName, lastName;
- private double grade;
- //Constructor
- public StudentGarde() {
- }
- public int getIdNumber() {
- return idNumber;
- }
- public void setIdNumber(int idNumber) {
- this.idNumber = idNumber;
- }
- public int getScore() {
- return score;
- }
- public void setScore(int score) {
- this.score = score;
- }
- public String getFirstName() {
- return firstName;
- }
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
- public String getLastName() {
- return lastName;
- }
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
- public double getGrade() {
- return grade;
- }
- public void setGrade(double grade) {
- this.grade = grade;
- }
- public double computeGrade() {
- grade = score/5;
- return grade;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement