1

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

Question

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 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.   

Answers

Lab10.java


public class Lab10
{
//Constants
private final static String NAME = "John Terry"; // 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.
System.out.println("\nName: Trine Thunder" );
System.out.println("Id Number: 000000001");
System.out.println("GPA : 4.00");
Student stu2 = new Student("Trine Thunder",000000001, 4.00 );
// [Add code here]
  
// Print out this student similar to above.
// You do not need to reset the gpa of this student.
System.out.println(stu2 + "\n");

// [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.
System.out.println("Using ==");
   if(stu1 == stu2){
       System.out.println("Both are same");
   }
   else{
       System.out.println("Both are different");
   }
   stu1.equals(stu2);
// [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
   name = namePar;
// [Add code here]
   idNum = idNumPar;
// Save idNumPar to class variable idNum
   gpa = gpaPar ;
// [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
   return name;
// [Add code here]
}

// Accessor: returns GPA of student
public double getGPA()
{
// Return the gpa of the student
   return gpa;
// [Add code here]
}

// Accessor: returns idNum of student
public int getIdNum()
{
// Return the idnum of the Student
   return idNum;
// [Add code here]
}


// Mutator: Changes the GPA of the student
public void setGPA(double g)
{
// Set the class variable gpa equal to g
   gpa = 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.
   String s ="";
   s = s + "Student Name: "+name+"\n";
   s =s + "Student Id num: "+idNum+"\n";
   s =s + "Student GPA: "+gpa+"\n";
   return s;
// [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]
   System.out.println("Using .equals() method");
   if(this.equals(s.idNum == this.idNum)){
       System.out.println("Both are same");
       return true;
   }
   else{
       System.out.println("Both are different");
       return false;
   }
     
     
}
} // end of class Student

Output:


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: 000000001
GPA : 4.00
Student Name: Trine Thunder
Student Id num: 1
Student GPA: 4.0


Using ==
Both are different
Using .equals() method
Both are different


Similar Solved Questions

1 answers
Explain the importance of maintaining seperate medical and billing records in worker's compensation cases. Research WC...
explain the importance of maintaining seperate medical and billing records in worker's compensation cases. Research WC regulations in your state and give a brief summary of what you found....
1 answers
Probiem &.8-Enhanced- with MacBook Air 2 5 7 9
Probiem &.8-Enhanced- with MacBook Air 2 5 7 9...
1 answers
1) Use the following descriptive statistics. The descriptive statistics are based on daily stock price returns...
1) Use the following descriptive statistics. The descriptive statistics are based on daily stock price returns over the last year for two companies: eBay and Disney. a) Does Disney appear to be more or less risky than eBay? b) Which company's stock performed better in the past year? Describe whi...
1 answers
You want to test which candy gets you the best ratings on student evaluations (0-10). The...
You want to test which candy gets you the best ratings on student evaluations (0-10). The first set of students gets no candy, the second gets black licorice, and the third gets skittles. You test n = 4 people in each group No Black Candy Licorice Skittles 4 زرا 8 N = 12 ز...
1 answers
Dx (8-5)(x+7
dx (8-5)(x+7...
1 answers
A particle is moving in a potential V ) given by the figure below. (b)Λ. Sketch...
A particle is moving in a potential V ) given by the figure below. (b)Λ. Sketch approximately the phase portrait 0 <q < 10. Label regions where (a) the particle has enough energy to make it over both local maxima. (b) the particle is confined to the left of both maxima. (c) the particle...
1 answers
Problem 8.1. We experience the pull of gravity as constant and not dependent on position. How...
Problem 8.1. We experience the pull of gravity as constant and not dependent on position. How does it come to be inter- preted as exerting a spring force that is linearly propor- tional to position? (Hint: Think about the equation of motion in which the relevant term appears.) Identify the fundament...
1 answers
How do bones grow?
How do bones grow?...
1 answers
The consulting company is under contract to carry out seven projects, all with deadlines measured...
The consulting company is under contract to carry out seven projects, all with deadlines measured in days. The consultants are small group and must work together on each project, so that the project will be started and completed sequentially. Under the terms of the contract, the consultants will rec...
1 answers
Find the UBRR for the following baud rate is XTAL = 16 MHz and U2X =...
Find the UBRR for the following baud rate is XTAL = 16 MHz and U2X = 1. Write the answer rounding to the nearest integer. 9,600 bps => UBRR = Answer 19,200 bps => UBRR = Answer 38,400 bps => UBRR = Answer 57,600 bps => UBRR = Answer...
1 answers
Chapter 12 series B exercises PLEASE andise on account from Sillas avice No 12,53,100, terms 1/10,...
chapter 12 series B exercises PLEASE andise on account from Sillas avice No 12,53,100, terms 1/10, a Company 5 Returned merchandive purchased from Tang's Toys, receiving a credit wmemo on the amount owed, $500 s Parchased merchandise on account from Daisy's Dolls, Invoice No. 139, ...
1 answers
In Goa, India, the multiplier effect of iron ore exports is calculated to be 1.62 (Ta, 2003). Calculate the impact of an...
In Goa, India, the multiplier effect of iron ore exports is calculated to be 1.62 (Ta, 2003). Calculate the impact of an additional 1,000 rupees of iron ore exports on the economy of Goa....
1 answers
8. Let X.(i-12) be independent N(0,1) random variables. a. Find the value of c such that...
8. Let X.(i-12) be independent N(0,1) random variables. a. Find the value of c such that P ( (X1 + X2尸/( X2-X)2 < c ) =.90 b. Find P(2 X1 -3 X21.5) c. Find 95th percentile of the distribution of Y-2X -3X2...
1 answers
The dimensions of the service environment include layout of furnishings, arrangement of signs and tangible cues...
The dimensions of the service environment include layout of furnishings, arrangement of signs and tangible cues fixed, process-focused products all of the above none of the above answer...

-- 0.060420--