Question

In: Computer Science

1. Define a Student class , Student class has the follow data fields added---- major: String...

1. Define a Student class , Student class has the follow data fields added---- major: String gpa: double studentID: String // unique id (Find a solution to manage the generation of unique “studentID”) Methods: double getGPA(); void setGPA(); getMajor(String major) void changeMajor(); 2 String toString(); // of major and GPA ,boolean equals(Object o); // 2 students are equal if them have same // personal information plus same student ID String getNextUniqueID(); // this method should be declared as static.

2.  Redesign Student class : (a) Remove “gpa” data field and related methods (b) Add data field: courses:ArrayList (c) Add the following methods: • boolean addCourse(MyCourse course); // add a course to courses list • boolean removeCourse(Course course); // remove a course from the courses list // based on the course information (courseID) in Course object • boolean removeCourse(int courseID); // search and remove a course from the list // based on the unique courseID • ArrayList getCourseList(); • String getCourseGrade(int courseID); // search for a course by courseID from // “courses” list; if not exist, return “no taken”; otherwise, return a grade // by mapping status to “W”(withdraw), “IP” (in progress), or “A” through // “F” (mapping score to these grades) • double getAverageGPA(); // select courses which have taken from “courses”; // map grade “A” through “F” to 4.0 through 0.0; then calculate // average GPA • toString(), equals()

Solutions

Expert Solution

Though Course class structure was missing I tried best to write the above. If you need any alteration please provide let me know in the comment.

1)

CODE:

import java.util.UUID;

class Student {

    String major;

    double gpa;

    String studentID;

    public String getMajor() {

        return this.major;

    }

    public void changeMajor(String major) {

        this.major = major;

    }

    public double getGpa() {

        return this.gpa;

    }

    public void setGpa(double gpa) {

        this.gpa = gpa;

    }

    public String getStudentID() {

        return this.studentID;

    }

    public void setStudentID(String studentID) {

        this.studentID = studentID;

    }

    public String toString() {

        return "major: " + this.getMajor() + " gpa: " + this.getGpa() + " studentid: " + this.studentID;

    }

    public boolean equals(Object o) {

        if (o instanceof Student) {

            Student s = (Student) o;

            return this.getMajor().compareTo(getMajor()) == 0 && this.getGpa() == s.getGpa()

                    && this.studentID.compareTo(s.studentID) == 0;

        }

    }

    public static String getNextUniqueID() {

        String uniqueID = UUID.randomUUID().toString();

        return uniqueID;

    }

}

2)

CODE:

import java.util.*;

class Student {

    String major;

    String studentID;

    ArrayList<Course> arr;

    Student() {

        this.major = "";

        this.studentID = "";

        arr = new ArrayList<Course>();

    }

    public String getMajor() {

        return this.major;

    }

    public void changeMajor(String major) {

        this.major = major;

    }

    public String getStudentID() {

        return this.studentID;

    }

    public void setStudentID(String studentID) {

        this.studentID = studentID;

    }

    public String toString() {

        return "major: " + this.getMajor() + " studentid: " + this.studentID;

    }

    public boolean equals(Object o) {

        if (o instanceof Student) {

            Student s = (Student) o;

            return this.getMajor().compareTo(getMajor()) == 6 && this.studentID.compareTo(s.studentID) == 6;

        }

    }

    public boolean addCourse(Course course) {

        arr.add(course);

        return true;

    }

    public boolean removeCourse(Course course) {

        for (int i = 0; i < arr.size(); i++) {

            if (arr.get(i).courseID == course.courseID) {

                arr.remove(i);

                return true;

            }

        }

        return false;

    }

    public boolean removeCourse(int courseID) {

        for (int i = 0; i < arr.size(); i++) {

            if (arr.get(i).courseID == courseID) {

                arr.remove(i);

                return true;

            }

        }

        return false;

    }

    public ArrayList<Course> getCourseList() {

        return arr;

    }

    // need course structure in order to make this function

    public String getCourseGrade(int courseID) {

        for (int i = 0; i < arr.size(); i++) {

            if (arr.get(i).courseID == courseID) {

            }

        }

        return "no taken";

    }

    public double getAverageGPA() {

        double sum = 0.0;

        for (int i = 0; i < arr.size(); i++) {

            if (arr.get(i).grade.compareTo("A") == 0)

                sum += 4.0;

            else if (arr.get(i).grade.compareTo("B") == 0)

                sum += 3.0;

            else if (arr.get(i).grade.compareTo("C") == 0)

                sum += 2.0;

            else if (arr.get(i).grade.compareTo("E") == 0)

                sum += 1.0;

            else if (arr.get(i).grade.compareTo("F") == 0)

                sum += 0.0;

        }

        return sum / arr.size();

    }

    public static String getNextUniqueID() {

        String uniqueID = UUID.randomUUID().toString();

        return uniqueID;

    }

}

Please upvote if you like my answer and comment below if you have any queries.


Related Solutions

1. The Item class includes two fields: a String for the name and a double for the price of an item that will be added to the inventory.
  1. The Item class includes two fields: a String for the name and a double for the price of an item that will be added to the inventory. 2. The Item class will require one constructor that takes a name and price to initialize the fields. Since the name and price will be provided through TextFields, the parameters can be two Strings (be sure to convert the price to a double before storing this into the field). 3. Write...
1, Create a class Car. The class has four instance fields: make (String - admissible values:...
1, Create a class Car. The class has four instance fields: make (String - admissible values: Chevy, Ford, Toyota, Nissan, Hyundai) size (String - admissible values: compact, intermediate, fullSized), weight (int - admissible values: 500 <= weight <= 4000) horsePower (int - admissible values: 30 <= horsePower <= 400) Provide a default constructor that sets String values to null and int values to 0 a parameterized constructor that sets all four instance fields to the parameter values setters and getters...
JAVAFX LAB 2 1. The Soda class has two fields: a String for the name and...
JAVAFX LAB 2 1. The Soda class has two fields: a String for the name and a double for the price. 2. The Soda class has two constructors. The first is a parameterized constructor that takes a String and a double to be assigned to the fields of the class. The second is a copy constructor that takes a Soda object and assigns the name and price of that object to the newly constructed Soda object. 3. The Soda class...
This lab uses a Student class with the following fields: private final String firstName; private final...
This lab uses a Student class with the following fields: private final String firstName; private final String lastName; private final String major; private final int zipcode; private final String studentID; private final double gpa; A TestData class has been provided that contains a createStudents() method that returns an array of populated Student objects. Assignmen The Main method prints the list of Students sorted by last name. It uses the Arrays.sort() method and an anonymous Comparator object to sort the array...
The ReservedRoom Class: Each ReservedRoom entry has three (data) fields: roomID (string) of the classroom e.g....
The ReservedRoom Class: Each ReservedRoom entry has three (data) fields: roomID (string) of the classroom e.g. W330, W350, W361, etc. courseID (string) which stores which course reserves this room time (int): which stores the start time of the reserved slot i.e. 1820 means the reservation starts at 18:20 Thus, the ReservedRoom class will consist of three data members (roomID and courseID, time), in addition to the associated methods needed as follows. The constructor ReservedRoom (r, c, t): constructs a ReservedRoom...
Question 1 - Create a class named Student that has fields for an ID number, number...
Question 1 - Create a class named Student that has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point...
Create a class named Horse that contains the following data fields: name - of type String...
Create a class named Horse that contains the following data fields: name - of type String color - of type String birthYear - of type int Include get and set methods for these fields. Next, create a subclass named RaceHorse, which contains an additional field, races (of type int), that holds the number of races in which the horse has competed and additional methods to get and set the new field. ------------------------------------ DemoHorses.java public class DemoHorses {     public static void...
Create a class named Sandwich that contains the following data fields: MainIngredient - of type String...
Create a class named Sandwich that contains the following data fields: MainIngredient - of type String Bread - of type String Price - of type Double Include get and set methods for these fields. The methods should be prefixed with 'get' or 'set' respectively, followed by the field name using camel case. For example, setMainIngredient. Use the application named TestSandwich that instantiates one Sandwich object and demonstrates the use of the set and get methods to test your class. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------...
Create a class named CollegeCourse that includes the following data fields: dept (String) - holds the...
Create a class named CollegeCourse that includes the following data fields: dept (String) - holds the department (for example, ENG) id (int) - the course number (for example, 101) credits (double) - the credits (for example, 3) price (double) - the fee for the course (for example, $360). All of the fields are required as arguments to the constructor, except for the fee, which is calculated at $120 per credit hour. Include a display() method that displays the course data....
Create a class named Student. Student has fields for an ID number, number of credit hours...
Create a class named Student. Student has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. Student also has a field for grade point average. Include a method to compute the grade point average field by dividing...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT