Trouble with Java, I can\'t figure out how to get started on this problem. How s
ID: 3857372 • Letter: T
Question
Trouble with Java, I can't figure out how to get started on this problem. How should I go about solving this?
Design a class called Student. This class is used to represent a student with student id, name and total number of units completed in college. Include standard methods (overloaded constructors, gets, sets, toString) and also include a method that determines the student's class standing based on number of units completed, a student's standing is a freshman if completed 30 units or under, a sophomore if completed 31 to 60 units, a junior if completed 61-90 units or a senior (90 units or above) Write out an UML diagram for the Student class. (See a sample in Fig 3.12 on Page 87) Then write Student.java to implement the class design. Write StudentTest.java to create a student object with id as 1234567, name as John Smith, number of units completed as 55.0. Print out the student information including the standing. Then ask user to enter the units completed in current semester, the print the updated information. Sample output: Student information: Student ID: 1234567 Student Name: John Smith Total Number of Units Completed: 55.0 Class Standing: Sophomore Enter Current Semester Units: 12.5 Updated Student information: Student Name: John Smith Total Number of Units Completed: 67.5 Class Standing: JuniorExplanation / Answer
public class Student {
private int studentID;
private String name;
private double totalNumOfUnitsCompleted;
/**
* @param studentID
* @param name
* @param totalNumOfUnitsCompleted
*/
public Student(int studentID, String name, double totalNumOfUnitsCompleted) {
this.studentID = studentID;
this.name = name;
this.totalNumOfUnitsCompleted = totalNumOfUnitsCompleted;
}
/**
* @return the studentID
*/
public int getStudentID() {
return studentID;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @return the totalNumOfUnitsCompleted
*/
public double getTotalNumOfUnitsCompleted() {
return totalNumOfUnitsCompleted;
}
/**
* @param studentID
* the studentID to set
*/
public void setStudentID(int studentID) {
this.studentID = studentID;
}
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @param totalNumOfUnitsCompleted
* the totalNumOfUnitsCompleted to set
*/
public void setTotalNumOfUnitsCompleted(double totalNumOfUnitsCompleted) {
this.totalNumOfUnitsCompleted = totalNumOfUnitsCompleted;
}
public String classStanding() {
if (totalNumOfUnitsCompleted <= 30)
return "Freshman";
else if (totalNumOfUnitsCompleted <= 60)
return "Sophomore";
else if (totalNumOfUnitsCompleted < 90)
return "Junior";
else
return "Senior";
}
@Override
public String toString() {
// TODO Auto-generated method stub
return "Student Information: Student ID: " + getStudentID()
+ " Student Name: " + getName()
+ " Total Number of Units Completed:"
+ getTotalNumOfUnitsCompleted() + " Class Standing: "
+ classStanding();
}
}
import java.util.Scanner;
public class StudentTest {
public static void main(String[] args) {
Scanner scanner = null;
try {
scanner = new Scanner(System.in);
Student student = new Student(1234567, "John Smith", 55.0);
System.out.println(student);
System.out.print("Enter Current Semester Units:");
double currSemUnits = scanner.nextDouble();
student.setTotalNumOfUnitsCompleted(student
.getTotalNumOfUnitsCompleted() + currSemUnits);
System.out.println(" Total Number of Units Completed:"
+ student.getTotalNumOfUnitsCompleted()
+ " Class Standing: " + student.classStanding());
} catch (Exception e) {
// TODO: handle exception
}
}
}
OUTPUT:
Student Information:
Student ID: 1234567
Student Name: John Smith
Total Number of Units Completed:55.0 Class Standing: Sophomore
Enter Current Semester Units:12.5
Total Number of Units Completed:67.5 Class Standing: Junior
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.