Question

// Client application class and service class Create a NetBeans project named StudentClient following the instructions...

// Client application class and service class Create a NetBeans project named StudentClient following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. Add a class named Student to the StudentClient project following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. After you have created your NetBeans Project your application class StudentC lient should contain the following executable code: package studentclient; public class StudentClient { public static void main(String[] args) { } } Your service class should contain the following executable code: package studentclient; publi c class Student { } In the StudentClient application class main method code the instructions to perform the tasks indicated in the remarks : package studentclient; public class StudentClient{ public static void main( String [] args ){ /* Declare two object references of type Student s1 and s2 and instantiate two Student objects passing three arguments to the constructor for the class . Use different values for each class object */ // Your code here /* Output the name, social security number and GPA of the student from object reference s1 using the appropriate accessor methods to obtain the data */ // Your code here /* Output the name, social security number and GPA of the student from object reference s2 using the toString method to return the data */ // Your code here /* Using the equals method and a selection control structure (if statement), compare objects s1 and s2 and output an appropriate message indicating if the objects are equal */ // Your code here /* U sing the appropriate mutator methods on student object s2, change the name, social security number and GPA to the same values as in object s1. Use the set methods. */ // Your code here /* Again, using the equals method and a selection control structure (if statement), compare objects s1 and s2 and output an appropriate message indicating if the objects are equal */ // Your code here } } In the Student service class code the instructions to define your Student service class struc ture with the appropriate constructors, mutator methods, accessor methods as well as a toString and an equals method : package studentclient; public class Student { /* Declare three instance variables to represent the student name, social security num ber and GPA */ // Your code here /* Overloaded constructor method : Allows client to set beginning values for name, ssn, and gpa . This constructor takes three parameters and c alls mutator methods to validate new values */ public Student ( String newName, String newSsn, double newGpa ) { // Your code here } /* getName accessor method */ public String getName( ) { // Your code here } /* setName mutator method */ public void setName( String newName ) { // Your code here } /* getSsn accessor method */ public String getSsn( ) { // Your code here } / * setSSN mutator method */ public void setSsn( String newSsn ) { // Your code here } /* getGpa accessor method */ public double getGpa( ) { // Your code here } /* setGpa mutator method: Allows client to set value of gpa and p rints an error message if new value is either less than 0 or greater than 4.0 . setGpa does not change the valu e of gpa if newGpa is negative or greater than 4. 0 */ public void setGpa( double newGpa ) { // Your code here } /* toString method returns student name, social security number and GPA */ public String toString( ) { // Your code here } /* equals method returns boolean Compares two Student objects for the same field values return s a boolean, true if this object has the same field value as the parameter object */ public boolean equals( Object o ) { // Your code here } } When your application has been successfully compiled and executed , Zip the StudentClient project folder. After the StudentClient project folder has been successfully compressed, upload the zipped folder to your Blackboard ac count for Programming Exercise 3 .

0 0
Add a comment Improve this question Transcribed image text
Answer #1

package studentclient;

import java.util.Scanner;

public class StudentClient {

public static void main(String[] args) {

String n;
String Sn;
double g;
System.out.println("Enter Student 1 details");
System.out.println("Name:");
Scanner sc=new Scanner(System.in);
n=sc.next();
System.out.println("Social Security number");
Sn=sc.next();
System.out.println("GPA");
g=sc.nextDouble();
Student s1=new Student(n,Sn,g);
System.out.println("Enter Student 2 details");
System.out.println("Name:");
n=sc.next();
System.out.println("Social Security number");
Sn=sc.next();
System.out.println("GPA");
g=sc.nextDouble();
Student s2=new Student(n,Sn,g);
/* Output the name, social security number and GPA of the student from object reference s1
using the appropriate accessor methods to obtain the data */

// Your code here
System.out.println("Student 1 details");
System.out.println("name:"+s1.getName());
System.out.println("Social Security Number:"+s1.getSsn());
System.out.println("GPA:"+s1.getGpa());
/* Output the name, social security number and GPA of the student from object reference s2
using the toString method to return the data */

// Your code here
System.out.println("Student 2 details");
System.out.println("name:"+s2.getName());
System.out.println("Social Security Number:"+s2.getSsn());
System.out.println("GPA:"+s2.getGpa());

  
/* Using the equals method and a selection control structure (if statement), compare objects
s1 and s2 and output an appropriate message indicating if the objects are equal */

// Your code here
if(s1.equals(s2))
System.out.println("Student details are Equal");
else
System.out.println("Student details are not Equal");

/* Using the appropriate mutator methods on student object s2, change the name, social security
number and GPA to the same values as in object s1. Use the set methods. */
// Your code here
System.out.println("Enter new details for Student 2");
System.out.println("Name:");
n=sc.next();
s2.setName(n);
System.out.println("Social Security number");
Sn=sc.next();
s2.setSsn(Sn);
System.out.println("GPA");
g=sc.nextDouble();
  
s2.setGpa(g);
  
/* Again, using the equals method and a selection control structure (if statement),
compare objects s1 and s2 and output an appropriate message indicating if the objects are equal */

// Your code here
if(s1.equals(s2))
System.out.println("Student details are Equal");
else
System.out.println("Student details are not Equal");
}
}

class Student
{
String name;
String social_security_number;
double GPA;
public Student( String newName, String newSsn, double newGpa )
{
this.name=newName;
this.social_security_number=newSsn;
this.GPA=newGpa;
}
public String getName( )
{
return this.name;

}
/* setName mutator method */
public void setName( String newName )
{
// Your code here
this.name=newName;
}
/* getSsn accessor method */

public String getSsn( )
{
// Your code here
return this.social_security_number;
}

/* setSSN mutator method */
public void setSsn( String newSsn )
{
// Your code here
this.social_security_number=newSsn;
}

/* getGpa accessor method */

public double getGpa( )
{
// Your code here
return this.GPA;
}

/* setGpa mutator method: Allows client to set value of gpa and prints an error message
if new value is either less than 0 or greater than 4.0. setGpa does not change the value
of gpa if newGpa is negative or greater than 4.0 */

public void setGpa( double newGpa )
{
// Your code here
if(newGpa<0 || newGpa>4)
System.out.println("Error! Gpa value should be in the range(0 to 4 ) only.");
else
this.GPA=newGpa;
}

/* toString method returns student name, social security number and GPA */
@Override
public String toString( )
{   
// Your code here
return ("name:"+this.name+" Social Security number:"+this.social_security_number+ " GPA:"+this.GPA);   
}

/* equals method returns boolean
Compares two Student objects for the same field values returns a boolean, true if this object has
the same field value as the parameter object */
public boolean equals( Student S )
{
// Your code here
boolean ans=false;
if(this.name.equals(S.name) && this.social_security_number.equals(S.social_security_number)
&&this.GPA==S.GPA)
{
ans=true;
}
return ans;
}

}

//Output:

run:
Enter Student 1 details
Name:
Bala
Social Security number
1234
GPA
2.3
Enter Student 2 details
Name:
David
Social Security number
3456
GPA
2.3
Student 1 details
name:Bala
Social Security Number:1234
GPA:2.3
Student 2 details
name:David
Social Security Number:3456
GPA:2.3
Student details are not Equal
Enter new details for Student 2
Name:
Bala
Social Security number
1234
GPA
5
Error! Gpa value should be in the range(0 to 4 ) only.
Student details are Equal

Add a comment
Know the answer?
Add Answer to:
// Client application class and service class Create a NetBeans project named StudentClient following the instructions...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {   ...

    import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {        Student s1 = new Student();         Student s2 = new Student("Smith", "123-45-6789", 3.2);         Student s3 = new Student("Jones", "987-65-4321", 3.7);         System.out.println("The name of student #1 is ");         System.out.println("The social security number of student #1 is " + s1.toString());         System.out.println("Student #2 is " + s2);         System.out.println("the name of student #3 is " + s3.getName());         System.out.println("The social security number...

  • java This lab is intended to give you practice creating a class with a constructor method,...

    java This lab is intended to give you practice creating a class with a constructor method, accessor methods, mutator methods, equals method , toString method and a equals method. In this lab you need to create two separate classes, one Student class and other Lab10 class. You need to define your instance variables, accessor methods, mutator methods, constructor, toString method and equals method in Student class. You need to create objects in Lab10 class which will have your main method...

  • Start a new project in NetBeans that defines a class Person with the following: Instance variables...

    Start a new project in NetBeans that defines a class Person with the following: Instance variables firstName (type String), middleInitial (type char) and lastName (type String) (1) A no-parameter constructor with a call to the this constructor; and (2) a constructor with String, char, String parameters (assign the parameters directly to the instance variables in this constructor--see info regarding the elimination of set methods below) Accessor (get) methods for all three instance variables (no set methods are required which makes...

  • Build a java program that has Student class, use arrays of objects {name, age, gpa} to...

    Build a java program that has Student class, use arrays of objects {name, age, gpa} to saves 3 students records. Use printable interface with abstract print method. Student class inherits from an abstract Person class that has name, age as attributes. It also has the following 2 methods: abstract setAge and concrete setGPA. Below is the hierarchy and a sample run (using netbeans): Hierarchy: Printable Interface print(Object ( ) ): object ] Abstract Person Class Name: String Age: int Abstract...

  • I need help for part B and C 1) Create a new project in NetBeans called...

    I need help for part B and C 1) Create a new project in NetBeans called Lab6Inheritance. Add a new Java class to the project called Person. 2) The UML class diagram for Person is as follows: Person - name: String - id: int + Person( String name, int id) + getName(): String + getido: int + display(): void 3) Add fields to Person class. 4) Add the constructor and the getters to person class. 5) Add the display() method,...

  • I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student...

    I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student {    private String name;    private double gpa;    private int idNumber;    public Student() {        this.name = "";        this.gpa = 0;        this.idNumber = 0;    }    public Student(String name, double gpa, int idNumber) {        this.name = name;        this.gpa = gpa;        this.idNumber = idNumber;    }    public Student(Student s)...

  • Description: This project focuses on creating a Java class, Date.java, along with a client class, DateCleint.java,...

    Description: This project focuses on creating a Java class, Date.java, along with a client class, DateCleint.java, which will contain code that utilizes your Date.java class. You will submit both files (each with appropriate commenting). A very similar project is described in the Programming Projects section at the end of chapter 8, which you may find helpful as reference. Use (your own) Java class file Date.java, and a companion DateClient.java file to perform the following:  Ask user to enter Today’s...

  • JAVA Create a Java project to implement a simple Name class. This class will have the...

    JAVA Create a Java project to implement a simple Name class. This class will have the following class variable: First Name, Middle Name, Last Name, and Full Name Create the accessor/getter and mutator/setter methods. In addition to these methods, create a toString() method, which overrides the object class toString() method. This override method prints the current value of any of this class object. Create a main() method to test your project.

  • Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram)

    Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram) Author -name:String -email:String -gender:char +Author(name:String, email:String, gender:char) +getName():String +getEmail):String +setEmail (email:String):void +getGender():char +tostring ):String . Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f'): One constructor to initialize the name, email and gender with the given values . Getters and setters: get Name (), getEmail() and getGender (). There are no setters for name and...

  • Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the...

    Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT