Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the Student class that has name, address, major and GPA as its attributes

ID: 3645006 • Letter: W

Question

Write the Student class that has name, address, major and GPA as its attributes . All of its attributes are Strings except for the GPA, which is a double. In addition defining the class, implement accessorand mutatormethods for all of the instance variables. To calculate the GPA, generate a random float between .5 and 4.0. Also be sure to include a toString(). Write two constructors. The first takes a name, address, and major and calls computeGPA to set the GPA. The second constructor only takes a name and address and sets the major to

Explanation / Answer

import java.util.*; public class Student { private String name, address, major, minor; private double gpa; public void student(String name, String address, String major, String minor){ this.name = name; this.address = address; this.major = major; this.minor = minor; computeGPA(); } public double computeGPA(){ Random generator = new Random(); float gpa = (float) (generator.nextDouble() * 4.0 + 0.5); return gpa; } } public class Test{ public static void main(String[] args){ Student s = new Student("John","34 Fake Street","Science"); System.out.println(s.toString()); //to show the Student has been created } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote