Write the code from UML diagrams for these 2 questions
1)
2)
Expert Answer
The code BEGINS from here:
/*
* Class Name
*/
public class Name {
private String first;
private String last;
// Constructor
public Name(String fName, String lName){
first = fName;
last = lName;
}
// toString Method
public String toString(){
return (first + ” ” + last);
}
}
/*
* Student Class
*/
public class Student {
public Name name;
private double gpa;
// Constructor
public Student(String fName, String lName, double gp){
name = new Name(fName, lName);
gpa = gp;
}
// updateGPA Method
public void updateGPA(double gp){
// Your code to change the gpa here
}
// toString Method
public String toString(){
return (name.toString() + “: ” + gpa);
}
}
**************** DemoClass.java*********************
public class DemoClass {
public static void main(String[] args) {
Student stu = new Student(“Shadow”, “Blade”, 9.5);
System.out.println(stu.toString());
}
}
Note: The main class is just for a demo.
ScreenShot:
Hope this code meets all your requirements…