1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Scorpion4ik [409]
3 years ago
6

Java

Computers and Technology
1 answer:
ladessa [460]3 years ago
4 0

Answer:

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

Explanation:

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

You might be interested in
Why must the image be reduced when the field of view is widened to take in more of the scene?
fiasKO [112]
The lighting in the shot
8 0
2 years ago
Read 2 more answers
Critics are concerned about how easy it is to upload and download music on the Internet because:
evablogger [386]
C. people have to buy entire albums, which can get expensive.
6 0
3 years ago
Read 2 more answers
Which options can you choose to determine the width and height of data or cells in a spreadsheet? You can choose the or rulers t
Tju [1.3M]

Answer :

Double click on boarder width an height will automatically adjust.

Manual procedure are following:

1.Open desire file of spreadsheet

2. Click on home tab in cell group and then click format.

3. Under cell size click on default width.

4. In standered column width box type new measurements and then click OK.

4 0
3 years ago
How to make google my default search engine on mac?
Paladinen [302]
Click safari , then go to preferences . open the general tab and you should be able to see 'Default search engine' , change that to google . (Often has Google , Yahoo! and Bing)
5 0
3 years ago
Lol im new to this. can anyone explain how i get points?
anygoal [31]
Answer people’s questions and log in daily
4 0
3 years ago
Other questions:
  • What variation of a dictionary attack involves a dictionary attack combined with a brute force attack, and will slightly alter d
    9·1 answer
  • BITS wants to store information about the supervisors, including their supervisor number and the relationship to consultants. Su
    15·1 answer
  • Which command can be used to manually add a package to the driver store?
    13·1 answer
  • Identify at least three body language messages that project a positive attitude?
    15·1 answer
  • Bushman and bonacci (2004) found that prejudiced participants were ____ likely to return a lost e-mail that had been addressed t
    5·1 answer
  • 1- How should an operating system support communication between applications? explain your reasoning?
    10·1 answer
  • You have been using the same computer for several years. To extend its service life, you decide to upgrade the processor. You ch
    13·1 answer
  • How does Google work, why does it work that way?
    11·2 answers
  • Project 15A - Math Application
    10·1 answer
  • A while loop uses a(n) ___________ at the top of every iteration to test whether to continue or not.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!