Question

In: Computer Science

1.) According to the UML Class Diagram, these are the mutator and accessor methods that you...

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.

Solutions

Expert Solution

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.


Related Solutions

Convert the following UML diagram into the Java code. Write constructor, mutator and accessor methods for...
Convert the following UML diagram into the Java code. Write constructor, mutator and accessor methods for the given class. Create an instance of the class in a main method using a Practice class. Note: The structure of the class can be compiled and tested without having bodies for the methods. Just be sure to put in dummy return values for methods that have a return type other than void.      
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in...
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in Java. Circle Circle Radius: double Circle() Circle(newRadius: double) getArea(): double setRadius(newRadius: double): void getRadius(): double After creating the Circle class, you should test this class from the main() method by passing objects of this class to a method “ public static void printAreas(Circle c, int times)” You should display the area of the circle object 5 times with different radii.
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in...
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in Java. Circle Circle Radius: double Circle() Circle(newRadius: double) getArea(): double setRadius(newRadius: double): void getRadius(): double After creating the Circle class, you should test this class from the main() method by passing objects of this class to a method “ public static void printAreas(Circle c, int times)” You should display the area of the circle object 5 times with different radii.
draw a uml diagram for a class
draw a uml diagram for a class
Create a UML Class Diagram of a Food Supermarket. Show inheritance of common methods. Upload image.
Create a UML Class Diagram of a Food Supermarket. Show inheritance of common methods. Upload image.
create the UML Diagram to model a Movie/TV viewing site. Draw a complete UML class diagram...
create the UML Diagram to model a Movie/TV viewing site. Draw a complete UML class diagram which shows: Classes (Only the ones listed in bold below) Attributes in classes (remember to indicate privacy level, and type) No need to write methods Relationships between classes (has is, is a, ...) Use a program like Lucid Cart and then upload your diagram. Each movie has: name, description, length, list of actors, list of prequals and sequals Each TV Show has: name, description,...
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {...
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {       public int month;    public int day;    public int year;    public Date(int month, int day, int year) {    this.month = month;    this.day = day;    this.year = year;    }       public Date() {    this.month = 0;    this.day = 0;    this.year = 0;    } } //end of Date.java // Name.java public class Name...
2.2.1 cLL The class is described according to the simple UML diagram below: 2cLL<T> -head:item<T> *...
2.2.1 cLL The class is described according to the simple UML diagram below: 2cLL<T> -head:item<T> * -size:int ------------------------ +cLL() +~cLL() +isEmpty():bool +getSize():int +push(newItem: item<T>*):void +pop():item<T>* +removeAt(x:T):item<T> * +printList():void The class variables are as follows: • head: The head pointer for the linked list. • size: The current size of the circular linked list. It starts at 0 and grows as the list does. The class methods are as follows: • cLL: The constructor. It will set the size to 0...
A UML class diagram can be used to model UML by considering each graphical component of...
A UML class diagram can be used to model UML by considering each graphical component of the notation to be a class. For example, a class diagram contains a collection of classes. Your problem is to construct and draw one class diagram with the below UML elements. That is, there will be a class for each of the elements listed. You must also provide ALL of the relationships between each of these classes. The elements to model in the class...
C++ 1. Start with a UML diagram of the class definition for the following problem defining...
C++ 1. Start with a UML diagram of the class definition for the following problem defining a utility class named Month. 2. Write a class named Month. The class should have an integer field named monthNumber that holds the number of the month (January is 1, February is 2, etc.). Also provide the following functions: • A default constructor that sets the monthNumber field to 1. • A constructor that accepts the number of month as an argument and sets...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT