In: Computer Science
1.) According to the UML Class Diagram, these are the mutator and accessor methods that you need to define:
1a.) +setName(value:String):void
1b.) +setGPA(value:double):void
1c.) +setID(value: String):void
1d.) +getName(): String
1e.) +getLastName():String
2.) Working with constructors
2a.) +Student() : This is the default constuctor. For the Strings properties, initialize them to null. The order is String ID, String name, String lastName, and double GPA.
2b.) +Student(value:String) - This constructor receives just the ID.
2c.) +Student(value:String, var: String) - This constructor receives the ID and name in that order.
2d.) +Student(value:String, var: String, change: String) - This constructor receives the ID, name, and last name in that order.
implementation:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication23;
import java.util.Random;
import java.util.Scanner;
/**
*
* @author haptop laptop
*/
class Student{
String name;
String id;
String lastName;
double GPA;
Student()//2.a solution//default constructor
{
id=null;
name=null;
lastName=null;
GPA=0.0;
}
Student(String value)//2.b solution//parametrized constructor
{
id=value;
}
Student(String value,String var)//2.c solution//parametrized constructor
{
id=value;
name=var;
}
Student(String value,String var,String change)//2.d solution//parametrized constructor
{
id=value;
name=var;
lastName=change;
}
void setName(String value )//sol 1.a//mutator method
{
name=value;
}
void setGPA(double value)//sol 1.b//mutator method
{
GPA=value;
}
void setId(String value)//sol 1.c//mutator method
{
id=value;
}
String getName()//sol 1.d//accessor method
{
return name;
}
String getLastName()//sol 1.e//accessor method
{
return lastName;
}
double getGPA()//accessor method
{ return GPA;
}
}
public class JavaApplication23 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Student s1=new Student();//object
Student s2=new Student("shreya");//object
Student s3=new Student("sristy","1234");
Student s4=new Student("1232","shresth","sharma");
System.out.println("name of student "+s4.getName()+" last name is "+s4.getLastName());
s1.setName("john");
s1.setGPA(4.5);
System.out.println("name of student "+s1.getName()+" gpa is "+s1.getGPA());
// TODO Auto-generated method stub
}
}
//hope it is cleared i have mentioned details in the comment of program.