subject

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 and need to add various
functionalities so that you can get the output as shown in sample output.

// Name:
// Section:

// Lab 10
// CS1113
// Fall 2016
// Class Lab10

public class Lab10
{
//Constants
private final static String NAME = "YOUR NAME"; // replace YOUR NAME with your name
private final static int STUID = 123456789;
private final static double GPA1 = 4.00;
private final static double GPA2 = 2.34;

//main method
public static void main (String[] args)
{
Student stu1;

stu1 = new Student(NAME, STUID, GPA1);

System. out. println("\nName: " + stu1.getName());
System. out. println("Id Number: " + stu1.getIdNum());
System. out. println("GPA : " + stu1.getGPA());
stu1.setGPA(GPA2);
System. out. println(stu1 + "\n");

// Create a second student object
// With a name of Trine Thunder, a
// gpa of 4.00, and a student Id of
// 000000001
// You do not need to declare these at final constants,
// but you can if you want to.

// [Add code here]

// Print out this student similar to above.
// You do not need to reset the gpa of this student.

// [Add code here]

// Check if both objects are same using == and .equals() methods.
// Print the message in both cases, whether same or not as shown in sample output.

// [Add code here]

} // end of main
} // end of class Lab10

// Name:
// Section:

// Lab 10
// CS1113
// Fall 2016
// Class : Student. java

public class Student
{
//class variables
private String name;
private int idNum;
private double gpa;

// Constructor
public Student(String namePar, int idNumPar, double gpaPar)
{
// Save namePar to class variable name

// [Add code here]

// Save idNumPar to class variable idNum

// [Add code here]

// Save gpaPar to class variable gpa

// [Add code here]

}

// Accessor: returns name of student
public String getName()
{
// Return the name of the student

// [Add code here]
}

// Accessor: returns GPA of student
public double getGPA()
{
// Return the gpa of the student

// [Add code here]
}

// Accessor: returns idNum of student
public int getIdNum()
{
// Return the idnum of the Student

// [Add code here]
}

// Mutator: Changes the GPA of the student
public void setGPA(double g)
{
// Set the class variable gpa equal to g

// [Add code here]
}

// toString method: Returns a formatted string
// of student information.
// As shown in sample output.
public String toString()
{
// declare a String variable to store the string value
// then return the formatted String.

// [Add code here]
}

// implement .equals() method which returns a boolean value
// of student information. When you call this method,
// it should print message as shown in sample output.
public boolean equals(Student s)
{
//[Add code here]
}
} // end of class Student

1) Fill in the needed code in the file (class)
Student. java (Student) and Lab10.java.
The program will not compile until you do so.
You will have 2 files, one named Lab10.java
and one named Student. java.

Compile the subsidiary class, Student. java,
first, using

javac Student. java

Once you have eliminated any and all syntax errors
in the student class. Then compile

javac Lab10.java

and eliminate any syntax errors from that class.
Then you can run the program using

java Lab10

2) Run the program and redirect the output to Lab10_out. txt

A Sample output is below:

Name: John Terry
Id Number: 123456789
GPA : 4.0
Student Name: John Terry
Student Id num:123456789
Student GPA: 2.34

Name: Trine Thunder
Id Number: 1
GPA : 4.0
Student Name: Trine Thunder
Student Id num:1
Student GPA: 4.0

Using ==
Both are different.

Using .equals() method
Both are different.

3) Now change your code so that you pass same values for both stu1 and stu2.
Compile and run your program.
Your output should look like:

Name: John Terry
Id Number: 123456789
GPA : 4.0
Student Name: John Terry
Student Id num:123456789
Student GPA: 2.34

Name: Trine Thunder
Id Number: 1
GPA : 4.0
Student Name: Trine Thunder
Student Id num:1
Student GPA: 4.0

Using ==
Both are different.

Using .equals() method
Both are different.

Explain why the result is not as expected?

Revert back to your previous version of your java code.

4) Turn in a printed copy of both Student. java and Lab10.java. Also
turn in a printed copy of your output file created in step 2.

ansver
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 15:30, 1232444553
Which of the following examples has four beats in each measure?
Answers: 2
image
Computers and Technology, 23.06.2019 09:30, ranmmm
The place where the extended axis of the earth would touch the celestial sphere is called the celestial
Answers: 1
image
Computers and Technology, 24.06.2019 14:00, maddi0132
In the microsoft® access® and microsoft excel® programs, the ribbon contains tabs that are divided into with like tools in them. parts groups containers bunches
Answers: 1
image
Computers and Technology, 25.06.2019 00:00, ddatsman1730
One difference of input method between most desktop computers and most tablets is the memory the touch screen the speech recognition
Answers: 1
You know the right answer?
Java

This lab is intended to give you practice creating a class with
a construct...

Questions in other subjects:

Konu
Mathematics, 17.02.2021 22:10
Konu
Mathematics, 17.02.2021 22:10
Konu
Mathematics, 17.02.2021 22:10