Given the following Person class, write a Boolean method called somethingsWrong() to determine if two instances of Person have different names, but the same SSN. The somethingsWrong () method should be true if the two people have the same social security number (SSN) but one or both of their names are not the same.
Given the following Person class, write a Boolean method called somethingsWrong() to determine if two instances of Person have different names, but the same SSN. The somethingsWrong () method should be true if the two people have the same social security number (SSN) but one or both of their names are not the same.
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question

Transcribed Image Text:Given the following Person class, write a Boolean method called somethingsWrong() to determine if two instances of
Person have different names, but the same SSN. The somethingsWrong () method should be true if the two people
have the same social security number (SSN) but one or both of their names are not the same.
public class Person {
private String firstName =
private String lastName = "";
private String ssn= "";
"";
Person (String firstName, String lastName, String ssn) {
this.firstName = firstName;
this.lastName = lastName;
this.ssn =
ssn;
}
public String getSSN() {
return ssn;
}
public String getFirstName () {
return firstName;
}
public String getLastName ()
{
return lastName;
}
<other methods are implemented here>
Expert Solution

Step 1: Solution
Question given:
A scratch code of a class and it's methods is given. Define a new method boolean somethingsWrong() within this class, that check if two different instances of this class have same ssn number but not have same names.
Programming language used: Java
Source code in Java:
(Note: all necessary comments are included in source code)
class Person {
private String firstName = "";
private String lastName = "";
private String ssn = "";
Person(String firstName, String lastName, String ssn){
this.firstName = firstName;
this.lastName = lastName;
this.ssn = ssn;
}
public String getSSN() {
return this.ssn;
}
public String getFirstName(){
return this.firstName;
}
public String getLastName(){
return this.lastName;
}
// other methods
public boolean somethingsWrong(Person p1, Person p2){
// get first person's full name
String p1_full = p1.getFirstName()+" "+p1.getLastName();
// get second person's full name
String p2_full = p2.getFirstName()+" "+p2.getLastName();
// check if both instances have same ssn number
if(p1.getSSN() == p2.getSSN()){
// check if both instances have not same name
if(p1_full != p2_full){
// if both conditions are true, then return boolean true
return true;
}
}
// if any condition is false then return boolean false
return false;
}
}
// create test class
public class PersonTest{
public static void main(String[] args) {
// create 2 instances of Person class
Person p1 = new Person("Daniel", "Jones", "123294");
Person p2 = new Person("Alex", "Hope", "123294");
// call somethingsWrong() method by any class's object and passed both instances as paramter
System.out.println("Result: "+ p1.somethingsWrong(p1, p2));
}
}
Step by step
Solved in 2 steps with 3 images

Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY