Design a class named Student. The class should have the following fields (User n
ID: 441030 • Letter: D
Question
Design a class named Student. The class should have the following fields (User needs to provide the information through keyboard) ? id (short) ? name (String) ? address (String) ? gpa (float) ? Notice, GPA will not be given directly. You need to define a method called ? calculateGPA( ) ? The method takes the grades of five courses from user input, computes GPA (the average of the five grades), and then return the GPA back to the main method. ? Note: your code should confirm if the grades (user input) are valid ([0..4]) ? Write a testing class which asks user to provide all information of the student (including grades of five courses), and then creates an instance of the student class and print out the studentExplanation / Answer
//somthing like this? Student.java package practiceStudent; import java.util.Scanner; public class Student { private short id; private String name; private String address; private float gpa;//Notice, GPA will not be given directly Student(short Id,String Name,String Address){ id=Id; name=Name; address=Address; } public void setId(short Id){id=Id;} public void setName(String Name){name=Name;} public void setAddress(String Address){address=Address;} public short getId(){return id;} public String getName(){return name;} public String getAddress(){return address;} public float calculatedGPA(float grade1,float grade2, float grade3, float grade4,float grade5){ float sum=grade1+grade2+grade3+grade4+grade5; gpa=sum/(float)5; return gpa; } } //------------------------------------------------------------------ Test.java public class Test{ public static void main(String[] args) { Scanner input=new Scanner(System.in); float[] grades=new float[5]; float number; Short Id; String Name,Address; System.out.print("Enter student id: "); Id=input.nextShort(); input.nextLine(); System.out.print("Enter student name: "); Name=input.nextLine(); System.out.print("Enter student address: "); Address=input.nextLine(); for(int i=0;i4||number4||numberRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.