SlideShare a Scribd company logo
1 of 28
Download to read offline
Repeat Programming Project 2 in Chapter 5. This time, add the following four constructor
methods: one for each instance variable, one with two parameters for the two instance variables,
and a default constructor. Be sure that each constructor sets all the instance variables. write a
driver program to test each of the methods, including each of the four constructors and at least
one true or false case for each of the test method.
this is the code that i have to add four constructor methods to
import java.util.*;
public class PersonImproved// Counter is the name of the class and i saved it in a file named
PersonImproved.
{
//Data members
private String name;
private int age;
public void readInput()
{
Scanner keyboard = new Scanner(System.in);
System.out.println("What is the person's name?");// This gets the program ready for
keyboard input by telling us that there is a new scanner called keyboard, that is accepting user
input.
name = keyboard.nextLine();
System.out.println("What is the person's age?");
age = keyboard.nextInt();
while (age < 0)
{
System.out.println("Age cannot be negative.");
System.out.println("Reenter age:");
age = keyboard.nextInt();
}
}
public void writeOutput()
{
System.out.println("Name = " + name);
System.out.println("Age = " + age);
}
//method to set non negative age
public void set(String newName, int newAge)
{
name = newName;
if (newAge >= 0)
age = newAge;
else
{
System.out.println("ERROR: Used a negative age.");
System.exit(0);
}
}
//method to setting name
public void setName(String newName)
{
name = newName;
}
//method to set age
public void setAge(int newAge)
{
if (newAge >= 0)
age = newAge;
else
{
System.out.println("ERROR: Used a negative age.");
System.exit(0);
}
} //to get name
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
/*Boolean tests for if two persons are equal (same name and age), if two persons
have the same name, if two persons have the same age, if one person is older
than another, and if one person is younger than another.*/
public boolean equals(PersonImproved another)
{
return(this.name.equalsIgnoreCase(another.name)
&& this.getAge() == another.getAge());
}
public boolean isSameName(PersonImproved another)
{
return(this.name.equalsIgnoreCase(another.name));
}
public boolean isSameAge(PersonImproved another)
{
return(this.getAge() == another.getAge());
}
public boolean isOlderThan(PersonImproved another)
{
return(this.getAge() > another.getAge());
}
public boolean isYoungerThan(PersonImproved
another)
{
return(this.getAge() < another.getAge());
}
}
and this is the test file
public class PersonCh6Test
{
public static void main(String[] args)
{
System.out.println();
System.out.println("Test case 1: default constructor and");
System.out.println("writeOutput() method.");
System.out.println();
PersonCh6 secretAgent1 = new PersonCh6();
System.out.println("Results of default constructor:");
System.out.println("Should be name = "No name" and");
System.out.println("age = 0.");
System.out.println();
secretAgent1.writeOutput();
System.out.println();
System.out.println("====================================");
System.out.println("Test case 2: readInput() method.");
secretAgent1.readInput();
System.out.println();
System.out.println("Verify name and age.");
System.out.println("Should be whatever you just entered.");
System.out.println();
secretAgent1.writeOutput();
System.out.println();
System.out.println("====================================");
System.out.println("Test case 3: constructor with just name.");
PersonCh6 secretAgent2 = new PersonCh6("Boris");
System.out.println();
System.out.println("Verify name = Boris and age = 0.");
System.out.println();
secretAgent2.writeOutput();
System.out.println();
System.out.println("====================================");
System.out.println("Test case 4: constructor with just age.");
System.out.println();
System.out.println("Verify name is "No name" and age = 40.");
System.out.println();
PersonCh6 secretAgent3 = new PersonCh6(40);
secretAgent3.writeOutput();
System.out.println();
System.out.println("====================================");
System.out.println("Test case 5: constructor with both name & age.");
System.out.println();
System.out.println("Verify name = Natasha & age 39.");
System.out.println();
PersonCh6 secretAgent4 = new PersonCh6("Natasha", 39);
secretAgent4.writeOutput();
System.out.println();
System.out.println("====================================");
System.out.println();
System.out.println("Test case 6:");
System.out.println("getName: should be Natasha.");
System.out.println();
System.out.println("Verify results: "+ secretAgent4.getName());
System.out.println("====================================");
System.out.println();
System.out.println("Test case 7:");
System.out.println("getAge: should be 39");
System.out.println();
System.out.println("Verify results: "
+ secretAgent4.getAge());
System.out.println("====================================");
System.out.println();
System.out.println("Test case 8:");
System.out.println("setName to Rocky");
secretAgent4.setName("Rocky");
System.out.println();
System.out.println("Verify results with getName(): "
+ secretAgent4.getName());
System.out.println("====================================");
System.out.println();
System.out.println("Test case 9:");
System.out.println("setAge to 99");
secretAgent4.setAge(99);
System.out.println();
System.out.println("Verify results: "
+ secretAgent4.getAge());
System.out.println("====================================");
System.out.println();
System.out.println("Test case 10: set method (both name & age)");
System.out.println("and equals (both name and age)");
System.out.println("Making two persons"
+ " with same name and age:");
secretAgent1.set("Bullwinkle", 10);
secretAgent2.set("Bullwinkle", 10);
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be true.");
System.out.println(secretAgent1.equals(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 11:");
System.out.println("equals (both name and age)");
System.out.println("with different names, same ages.");
secretAgent2.setName("Boris");
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be false.");
System.out.println(secretAgent1.equals(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 12:");
System.out.println("equals (both name and age)");
System.out.println("with different ages, same names.");
secretAgent2.setName("Bullwinkle");
secretAgent2.setAge(98);
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be false.");
System.out.println(secretAgent1.equals(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 13:");
System.out.println("equals (both name and age)");
System.out.println("with different names and ages.");
secretAgent2.setName("Boris");
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be false.");
System.out.println(secretAgent1.equals(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 14:");
System.out.println("isSameName");
System.out.println("with same names and ages.");
secretAgent2.set("Bullwinkle", 10);
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be true.");
System.out.println(secretAgent1.isSameName(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 15:");
System.out.println("isSameName");
System.out.println("with same names, different ages.");
secretAgent2.setAge(98);
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be true.");
System.out.println(secretAgent1.isSameName(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 16:");
System.out.println("isSameName");
System.out.println("with different names, same ages.");
secretAgent2.set("Boris", 10);
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be false.");
System.out.println(secretAgent1.isSameName(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 17:");
System.out.println("isSameName");
System.out.println("with different names, different ages.");
secretAgent2.set("Boris", 5);
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be false.");
System.out.println(secretAgent1.isSameName(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 18:");
System.out.println("isOlderThan");
System.out.println("with 1st person older than the other.");
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be true.");
System.out.println(secretAgent1.isOlderThan(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 19:");
System.out.println("isOlderThan");
System.out.println("with same ages.");
secretAgent2.setAge(10);
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be false.");
System.out.println(secretAgent1.isOlderThan(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 20:");
System.out.println("isOlderThan");
System.out.println("with 1st person younger than the other.");
secretAgent2.setAge(100);
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be false.");
System.out.println(secretAgent1.isOlderThan(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 21:");
System.out.println("isYoungerThan");
System.out.println("with 1st person younger than the other.");
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be true.");
System.out.println(secretAgent1.isYoungerThan(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 22:");
System.out.println("isYoungerThan");
System.out.println("with same ages.");
secretAgent2.setAge(10);
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be false.");
System.out.println(secretAgent1.isYoungerThan(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 20:");
System.out.println("isYoungerThan");
System.out.println("with 1st person older than the other.");
secretAgent2.setAge(9);
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be false.");
System.out.println(secretAgent1.isYoungerThan(secretAgent2));
}
}
the output should look similar to this
Solution
import java.util.Scanner;
public class PersonImproved {
// Data members
private String name;
private int age;
/**
* Default constructor
*/
public PersonImproved() {
this.name = "No name";
this.age = 0;
}
/**
* Parameterized constructor with name
* @param name
*/
public PersonImproved(String name) {
this.name = name;
this.age = 0;
}
/**
* Parameterized constructor with age
* @param age
*/
public PersonImproved(int age) {
this.name = "No name";
this.age = age;
}
/**
* Parameterized constructor with name and age
* @param name
* @param age
*/
public PersonImproved(String name, int age) {
this.name = name;
this.age = age;
}
/**
* Gets the name and age from the user
*/
public void readInput() {
Scanner keyboard = new Scanner(System.in);
System.out.println("What is the person's name?");// This gets the
// program ready for
// keyboard input by
// telling us that
// there is a new
// scanner called
// keyboard, that is
// accepting user
// input.
name = keyboard.nextLine();
System.out.println("What is the person's age?");
age = keyboard.nextInt();
while (age < 0) {
System.out.println("Age cannot be negative.");
System.out.println("Reenter age:");
age = keyboard.nextInt();
}
//Close scanner
keyboard.close();
}
/**
* Displays the name and age
*/
public void writeOutput() {
System.out.println("Name = " + name);
System.out.println("Age = " + age);
}
/**
* method to set non negative age
* @param newName
* @param newAge
*/
public void set(String newName, int newAge) {
name = newName;
if (newAge >= 0)
age = newAge;
else {
System.out.println("ERROR: Used a negative age.");
System.exit(0);
}
}
/**
* method to setting name
* @param newName
*/
public void setName(String newName) {
name = newName;
}
/**
* method to set age
* @param newAge
*/
public void setAge(int newAge) {
if (newAge >= 0)
age = newAge;
else {
System.out.println("ERROR: Used a negative age.");
System.exit(0);
}
}
/**
* Gets the name
* @return
*/
public String getName() {
return name;
}
/**
* Gets the age
* @return
*/
public int getAge() {
return age;
}
/*
* Boolean tests for if two persons are equal (same name and age), if two
* persons have the same name, if two persons have the same age, if one
* person is older than another, and if one person is younger than another.
*/
public boolean equals(PersonImproved another) {
return (this.name.equalsIgnoreCase(another.name) && this.getAge() == another.getAge());
}
public boolean isSameName(PersonImproved another) {
return (this.name.equalsIgnoreCase(another.name));
}
public boolean isSameAge(PersonImproved another) {
return (this.getAge() == another.getAge());
}
public boolean isOlderThan(PersonImproved another) {
return (this.getAge() > another.getAge());
}
public boolean isYoungerThan(PersonImproved another) {
return (this.getAge() < another.getAge());
}
}
public class PersonCh6Test {
public static void main(String[] args) {
System.out.println();
System.out.println("Test case 1: default constructor and");
System.out.println("writeOutput() method.");
System.out.println();
PersonImproved secretAgent1 = new PersonImproved();
System.out.println("Results of default constructor:");
System.out.println("Should be name = "No name" and");
System.out.println("age = 0.");
System.out.println();
secretAgent1.writeOutput();
System.out.println();
System.out.println("====================================");
System.out.println("Test case 2: readInput() method.");
secretAgent1.readInput();
System.out.println();
System.out.println("Verify name and age.");
System.out.println("Should be whatever you just entered.");
System.out.println();
secretAgent1.writeOutput();
System.out.println();
System.out.println("====================================");
System.out.println("Test case 3: constructor with just name.");
PersonImproved secretAgent2 = new PersonImproved("Boris");
System.out.println();
System.out.println("Verify name = Boris and age = 0.");
System.out.println();
secretAgent2.writeOutput();
System.out.println();
System.out.println("====================================");
System.out.println("Test case 4: constructor with just age.");
System.out.println();
System.out.println("Verify name is "No name" and age = 40.");
System.out.println();
PersonImproved secretAgent3 = new PersonImproved(40);
secretAgent3.writeOutput();
System.out.println();
System.out.println("====================================");
System.out.println("Test case 5: constructor with both name & age.");
System.out.println();
System.out.println("Verify name = Natasha & age 39.");
System.out.println();
PersonImproved secretAgent4 = new PersonImproved("Natasha", 39);
secretAgent4.writeOutput();
System.out.println();
System.out.println("====================================");
System.out.println();
System.out.println("Test case 6:");
System.out.println("getName: should be Natasha.");
System.out.println();
System.out.println("Verify results: " + secretAgent4.getName());
System.out.println("====================================");
System.out.println();
System.out.println("Test case 7:");
System.out.println("getAge: should be 39");
System.out.println();
System.out.println("Verify results: " + secretAgent4.getAge());
System.out.println("====================================");
System.out.println();
System.out.println("Test case 8:");
System.out.println("setName to Rocky");
secretAgent4.setName("Rocky");
System.out.println();
System.out.println("Verify results with getName(): " + secretAgent4.getName());
System.out.println("====================================");
System.out.println();
System.out.println("Test case 9:");
System.out.println("setAge to 99");
secretAgent4.setAge(99);
System.out.println();
System.out.println("Verify results: " + secretAgent4.getAge());
System.out.println("====================================");
System.out.println();
System.out.println("Test case 10: set method (both name & age)");
System.out.println("and equals (both name and age)");
System.out.println("Making two persons" + " with same name and age:");
secretAgent1.set("Bullwinkle", 10);
secretAgent2.set("Bullwinkle", 10);
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be true.");
System.out.println(secretAgent1.equals(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 11:");
System.out.println("equals (both name and age)");
System.out.println("with different names, same ages.");
secretAgent2.setName("Boris");
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be false.");
System.out.println(secretAgent1.equals(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 12:");
System.out.println("equals (both name and age)");
System.out.println("with different ages, same names.");
secretAgent2.setName("Bullwinkle");
secretAgent2.setAge(98);
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be false.");
System.out.println(secretAgent1.equals(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 13:");
System.out.println("equals (both name and age)");
System.out.println("with different names and ages.");
secretAgent2.setName("Boris");
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be false.");
System.out.println(secretAgent1.equals(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 14:");
System.out.println("isSameName");
System.out.println("with same names and ages.");
secretAgent2.set("Bullwinkle", 10);
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be true.");
System.out.println(secretAgent1.isSameName(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 15:");
System.out.println("isSameName");
System.out.println("with same names, different ages.");
secretAgent2.setAge(98);
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be true.");
System.out.println(secretAgent1.isSameName(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 16:");
System.out.println("isSameName");
System.out.println("with different names, same ages.");
secretAgent2.set("Boris", 10);
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be false.");
System.out.println(secretAgent1.isSameName(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 17:");
System.out.println("isSameName");
System.out.println("with different names, different ages.");
secretAgent2.set("Boris", 5);
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be false.");
System.out.println(secretAgent1.isSameName(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 18:");
System.out.println("isOlderThan");
System.out.println("with 1st person older than the other.");
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be true.");
System.out.println(secretAgent1.isOlderThan(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 19:");
System.out.println("isOlderThan");
System.out.println("with same ages.");
secretAgent2.setAge(10);
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be false.");
System.out.println(secretAgent1.isOlderThan(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 20:");
System.out.println("isOlderThan");
System.out.println("with 1st person younger than the other.");
secretAgent2.setAge(100);
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be false.");
System.out.println(secretAgent1.isOlderThan(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 21:");
System.out.println("isYoungerThan");
System.out.println("with 1st person younger than the other.");
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be true.");
System.out.println(secretAgent1.isYoungerThan(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 22:");
System.out.println("isYoungerThan");
System.out.println("with same ages.");
secretAgent2.setAge(10);
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be false.");
System.out.println(secretAgent1.isYoungerThan(secretAgent2));
System.out.println("====================================");
System.out.println();
System.out.println("Test case 20:");
System.out.println("isYoungerThan");
System.out.println("with 1st person older than the other.");
secretAgent2.setAge(9);
System.out.println("First person: ");
secretAgent1.writeOutput();
System.out.println("Second person: ");
secretAgent2.writeOutput();
System.out.println();
System.out.println("Verify results: should be false.");
System.out.println(secretAgent1.isYoungerThan(secretAgent2));
}
}
OUTPUT:
Test case 1: default constructor and
writeOutput() method.
Results of default constructor:
Should be name = "No name" and
age = 0.
Name = No name
Age = 0
====================================
Test case 2: readInput() method.
What is the person's name?
John
What is the person's age?
10
Verify name and age.
Should be whatever you just entered.
Name = John
Age = 10
====================================
Test case 3: constructor with just name.
Verify name = Boris and age = 0.
Name = Boris
Age = 0
====================================
Test case 4: constructor with just age.
Verify name is "No name" and age = 40.
Name = No name
Age = 40
====================================
Test case 5: constructor with both name & age.
Verify name = Natasha & age 39.
Name = Natasha
Age = 39
====================================
Test case 6:
getName: should be Natasha.
Verify results: Natasha
====================================
Test case 7:
getAge: should be 39
Verify results: 39
====================================
Test case 8:
setName to Rocky
Verify results with getName(): Rocky
====================================
Test case 9:
setAge to 99
Verify results: 99
====================================
Test case 10: set method (both name & age)
and equals (both name and age)
Making two persons with same name and age:
First person:
Name = Bullwinkle
Age = 10
Second person:
Name = Bullwinkle
Age = 10
Verify results: should be true.
true
====================================
Test case 11:
equals (both name and age)
with different names, same ages.
First person:
Name = Bullwinkle
Age = 10
Second person:
Name = Boris
Age = 10
Verify results: should be false.
false
====================================
Test case 12:
equals (both name and age)
with different ages, same names.
First person:
Name = Bullwinkle
Age = 10
Second person:
Name = Bullwinkle
Age = 98
Verify results: should be false.
false
====================================
Test case 13:
equals (both name and age)
with different names and ages.
First person:
Name = Bullwinkle
Age = 10
Second person:
Name = Boris
Age = 98
Verify results: should be false.
false
====================================
Test case 14:
isSameName
with same names and ages.
First person:
Name = Bullwinkle
Age = 10
Second person:
Name = Bullwinkle
Age = 10
Verify results: should be true.
true
====================================
Test case 15:
isSameName
with same names, different ages.
First person:
Name = Bullwinkle
Age = 10
Second person:
Name = Bullwinkle
Age = 98
Verify results: should be true.
true
====================================
Test case 16:
isSameName
with different names, same ages.
First person:
Name = Bullwinkle
Age = 10
Second person:
Name = Boris
Age = 10
Verify results: should be false.
false
====================================
Test case 17:
isSameName
with different names, different ages.
First person:
Name = Bullwinkle
Age = 10
Second person:
Name = Boris
Age = 5
Verify results: should be false.
false
====================================
Test case 18:
isOlderThan
with 1st person older than the other.
First person:
Name = Bullwinkle
Age = 10
Second person:
Name = Boris
Age = 5
Verify results: should be true.
true
====================================
Test case 19:
isOlderThan
with same ages.
First person:
Name = Bullwinkle
Age = 10
Second person:
Name = Boris
Age = 10
Verify results: should be false.
false
====================================
Test case 20:
isOlderThan
with 1st person younger than the other.
First person:
Name = Bullwinkle
Age = 10
Second person:
Name = Boris
Age = 100
Verify results: should be false.
false
====================================
Test case 21:
isYoungerThan
with 1st person younger than the other.
First person:
Name = Bullwinkle
Age = 10
Second person:
Name = Boris
Age = 100
Verify results: should be true.
true
====================================
Test case 22:
isYoungerThan
with same ages.
First person:
Name = Bullwinkle
Age = 10
Second person:
Name = Boris
Age = 10
Verify results: should be false.
false
====================================
Test case 20:
isYoungerThan
with 1st person older than the other.
First person:
Name = Bullwinkle
Age = 10
Second person:
Name = Boris
Age = 9
Verify results: should be false.
false

More Related Content

Similar to Repeat Programming Project 2 in Chapter 5. This time, add the follow.pdf

LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdfLECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdfShashikantSathe3
 
You will need to develop a system that can track employee informatio.pdf
You will need to develop a system that can track employee informatio.pdfYou will need to develop a system that can track employee informatio.pdf
You will need to develop a system that can track employee informatio.pdfjeetumordhani
 
Create a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdfCreate a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdffeelingspaldi
 
I need help making these adjustments to my class Persons_Informati.pdf
I need help making these adjustments to my class Persons_Informati.pdfI need help making these adjustments to my class Persons_Informati.pdf
I need help making these adjustments to my class Persons_Informati.pdfomarionmatzmcwill497
 
Java questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfJava questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfforwardcom41
 
2. Create a Java class called EmployeeMain within the same project Pr.docx
 2. Create a Java class called EmployeeMain within the same project Pr.docx 2. Create a Java class called EmployeeMain within the same project Pr.docx
2. Create a Java class called EmployeeMain within the same project Pr.docxajoy21
 
Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdffashioncollection2
 
can do this in java please thanks in advance The code that y.pdf
can do this in java please thanks in advance The code that y.pdfcan do this in java please thanks in advance The code that y.pdf
can do this in java please thanks in advance The code that y.pdfakshpatil4
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodecamp Romania
 
WAP to implement inheritance and overloading methods in java
WAP to implement inheritance and overloading methods in javaWAP to implement inheritance and overloading methods in java
WAP to implement inheritance and overloading methods in javaOne97 Communications Limited
 
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdfBasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdfankitmobileshop235
 
node.js Module Development
node.js Module Developmentnode.js Module Development
node.js Module DevelopmentJay Harris
 
Listing.javaimport java.util.Scanner;public class Listing {   .pdf
Listing.javaimport java.util.Scanner;public class Listing {   .pdfListing.javaimport java.util.Scanner;public class Listing {   .pdf
Listing.javaimport java.util.Scanner;public class Listing {   .pdfAnkitchhabra28
 

Similar to Repeat Programming Project 2 in Chapter 5. This time, add the follow.pdf (20)

LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdfLECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
 
You will need to develop a system that can track employee informatio.pdf
You will need to develop a system that can track employee informatio.pdfYou will need to develop a system that can track employee informatio.pdf
You will need to develop a system that can track employee informatio.pdf
 
Create a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdfCreate a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdf
 
I need help making these adjustments to my class Persons_Informati.pdf
I need help making these adjustments to my class Persons_Informati.pdfI need help making these adjustments to my class Persons_Informati.pdf
I need help making these adjustments to my class Persons_Informati.pdf
 
Java practical
Java practicalJava practical
Java practical
 
Java questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfJava questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdf
 
2. Create a Java class called EmployeeMain within the same project Pr.docx
 2. Create a Java class called EmployeeMain within the same project Pr.docx 2. Create a Java class called EmployeeMain within the same project Pr.docx
2. Create a Java class called EmployeeMain within the same project Pr.docx
 
Java 8 Examples
Java 8 ExamplesJava 8 Examples
Java 8 Examples
 
Manual tecnic sergi_subirats
Manual tecnic sergi_subiratsManual tecnic sergi_subirats
Manual tecnic sergi_subirats
 
Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdf
 
can do this in java please thanks in advance The code that y.pdf
can do this in java please thanks in advance The code that y.pdfcan do this in java please thanks in advance The code that y.pdf
can do this in java please thanks in advance The code that y.pdf
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
 
WAP to implement inheritance and overloading methods in java
WAP to implement inheritance and overloading methods in javaWAP to implement inheritance and overloading methods in java
WAP to implement inheritance and overloading methods in java
 
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdfBasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
 
node.js Module Development
node.js Module Developmentnode.js Module Development
node.js Module Development
 
Java programs
Java programsJava programs
Java programs
 
Listing.javaimport java.util.Scanner;public class Listing {   .pdf
Listing.javaimport java.util.Scanner;public class Listing {   .pdfListing.javaimport java.util.Scanner;public class Listing {   .pdf
Listing.javaimport java.util.Scanner;public class Listing {   .pdf
 
Boot strap.groovy
Boot strap.groovyBoot strap.groovy
Boot strap.groovy
 
Bootstrap
BootstrapBootstrap
Bootstrap
 
java
javajava
java
 

More from arracollection

On April 18, 1906, an earthquake killed over 3,000 people when it hi.pdf
On April 18, 1906, an earthquake killed over 3,000 people when it hi.pdfOn April 18, 1906, an earthquake killed over 3,000 people when it hi.pdf
On April 18, 1906, an earthquake killed over 3,000 people when it hi.pdfarracollection
 
On the planet of Caracas, in the Stellar Solorais Ka Chunk Galaxy, th.pdf
On the planet of Caracas, in the Stellar Solorais Ka Chunk Galaxy, th.pdfOn the planet of Caracas, in the Stellar Solorais Ka Chunk Galaxy, th.pdf
On the planet of Caracas, in the Stellar Solorais Ka Chunk Galaxy, th.pdfarracollection
 
Muv is homozygous You have a C. elegans worm with the following geno.pdf
Muv is homozygous You have a C. elegans worm with the following geno.pdfMuv is homozygous You have a C. elegans worm with the following geno.pdf
Muv is homozygous You have a C. elegans worm with the following geno.pdfarracollection
 
Material Science (Solidification)What is the solute atoms concent.pdf
Material Science (Solidification)What is the solute atoms concent.pdfMaterial Science (Solidification)What is the solute atoms concent.pdf
Material Science (Solidification)What is the solute atoms concent.pdfarracollection
 
Let P[x] denote the vector space of all polynomials. Let E be the set.pdf
Let P[x] denote the vector space of all polynomials. Let E be the set.pdfLet P[x] denote the vector space of all polynomials. Let E be the set.pdf
Let P[x] denote the vector space of all polynomials. Let E be the set.pdfarracollection
 
Investment in Note ReceivableSuppliesPrepaid RentBuildingsAc.pdf
Investment in Note ReceivableSuppliesPrepaid RentBuildingsAc.pdfInvestment in Note ReceivableSuppliesPrepaid RentBuildingsAc.pdf
Investment in Note ReceivableSuppliesPrepaid RentBuildingsAc.pdfarracollection
 
In a tube containing 1 ml of a 15 dilution of A, and 4 ml of a 110.pdf
In a tube containing 1 ml of a 15 dilution of A, and 4 ml of a 110.pdfIn a tube containing 1 ml of a 15 dilution of A, and 4 ml of a 110.pdf
In a tube containing 1 ml of a 15 dilution of A, and 4 ml of a 110.pdfarracollection
 
Implement a function called getElements() that takes in two lists. T.pdf
Implement a function called getElements() that takes in two lists. T.pdfImplement a function called getElements() that takes in two lists. T.pdf
Implement a function called getElements() that takes in two lists. T.pdfarracollection
 
gnmenttakeAssignmentMaindoinvoker assignmentstakeAssignmernt Dr. L. .pdf
gnmenttakeAssignmentMaindoinvoker assignmentstakeAssignmernt Dr. L. .pdfgnmenttakeAssignmentMaindoinvoker assignmentstakeAssignmernt Dr. L. .pdf
gnmenttakeAssignmentMaindoinvoker assignmentstakeAssignmernt Dr. L. .pdfarracollection
 
Every cell in our bodies expresses the same genes. True or False.pdf
Every cell in our bodies expresses the same genes. True or False.pdfEvery cell in our bodies expresses the same genes. True or False.pdf
Every cell in our bodies expresses the same genes. True or False.pdfarracollection
 
Describe the partition of Z resulting from the equivalence relati.pdf
Describe the partition of Z resulting from the equivalence relati.pdfDescribe the partition of Z resulting from the equivalence relati.pdf
Describe the partition of Z resulting from the equivalence relati.pdfarracollection
 
describe what is meant by Rh factor when typing blood.Solution.pdf
describe what is meant by Rh factor when typing blood.Solution.pdfdescribe what is meant by Rh factor when typing blood.Solution.pdf
describe what is meant by Rh factor when typing blood.Solution.pdfarracollection
 
Describe the causes, symptoms, and treatment of conjunctivitisSo.pdf
Describe the causes, symptoms, and treatment of conjunctivitisSo.pdfDescribe the causes, symptoms, and treatment of conjunctivitisSo.pdf
Describe the causes, symptoms, and treatment of conjunctivitisSo.pdfarracollection
 
Discuss the relationship between gap rule gene mutations, pair-rule .pdf
Discuss the relationship between gap rule gene mutations, pair-rule .pdfDiscuss the relationship between gap rule gene mutations, pair-rule .pdf
Discuss the relationship between gap rule gene mutations, pair-rule .pdfarracollection
 
Create a directory your virtual machine. Within that directory creat.pdf
Create a directory your virtual machine. Within that directory creat.pdfCreate a directory your virtual machine. Within that directory creat.pdf
Create a directory your virtual machine. Within that directory creat.pdfarracollection
 
Compare between the two light microscope SolutionFeature1. .pdf
Compare between the two light microscope  SolutionFeature1. .pdfCompare between the two light microscope  SolutionFeature1. .pdf
Compare between the two light microscope SolutionFeature1. .pdfarracollection
 
Chordin, Tolloid and Sizzled all play important roles in BMP signal r.pdf
Chordin, Tolloid and Sizzled all play important roles in BMP signal r.pdfChordin, Tolloid and Sizzled all play important roles in BMP signal r.pdf
Chordin, Tolloid and Sizzled all play important roles in BMP signal r.pdfarracollection
 
Chills are used in casting where the part is likely to form a cavity.pdf
Chills are used in casting where the part is likely to form a cavity.pdfChills are used in casting where the part is likely to form a cavity.pdf
Chills are used in casting where the part is likely to form a cavity.pdfarracollection
 
A drug that disrupts tubulin polymerzation is applied to some cell.pdf
A drug that disrupts tubulin polymerzation is applied to some cell.pdfA drug that disrupts tubulin polymerzation is applied to some cell.pdf
A drug that disrupts tubulin polymerzation is applied to some cell.pdfarracollection
 
At the second metaphase of meiosis Chromosomes have single chromatid.pdf
At the second metaphase of meiosis  Chromosomes have single chromatid.pdfAt the second metaphase of meiosis  Chromosomes have single chromatid.pdf
At the second metaphase of meiosis Chromosomes have single chromatid.pdfarracollection
 

More from arracollection (20)

On April 18, 1906, an earthquake killed over 3,000 people when it hi.pdf
On April 18, 1906, an earthquake killed over 3,000 people when it hi.pdfOn April 18, 1906, an earthquake killed over 3,000 people when it hi.pdf
On April 18, 1906, an earthquake killed over 3,000 people when it hi.pdf
 
On the planet of Caracas, in the Stellar Solorais Ka Chunk Galaxy, th.pdf
On the planet of Caracas, in the Stellar Solorais Ka Chunk Galaxy, th.pdfOn the planet of Caracas, in the Stellar Solorais Ka Chunk Galaxy, th.pdf
On the planet of Caracas, in the Stellar Solorais Ka Chunk Galaxy, th.pdf
 
Muv is homozygous You have a C. elegans worm with the following geno.pdf
Muv is homozygous You have a C. elegans worm with the following geno.pdfMuv is homozygous You have a C. elegans worm with the following geno.pdf
Muv is homozygous You have a C. elegans worm with the following geno.pdf
 
Material Science (Solidification)What is the solute atoms concent.pdf
Material Science (Solidification)What is the solute atoms concent.pdfMaterial Science (Solidification)What is the solute atoms concent.pdf
Material Science (Solidification)What is the solute atoms concent.pdf
 
Let P[x] denote the vector space of all polynomials. Let E be the set.pdf
Let P[x] denote the vector space of all polynomials. Let E be the set.pdfLet P[x] denote the vector space of all polynomials. Let E be the set.pdf
Let P[x] denote the vector space of all polynomials. Let E be the set.pdf
 
Investment in Note ReceivableSuppliesPrepaid RentBuildingsAc.pdf
Investment in Note ReceivableSuppliesPrepaid RentBuildingsAc.pdfInvestment in Note ReceivableSuppliesPrepaid RentBuildingsAc.pdf
Investment in Note ReceivableSuppliesPrepaid RentBuildingsAc.pdf
 
In a tube containing 1 ml of a 15 dilution of A, and 4 ml of a 110.pdf
In a tube containing 1 ml of a 15 dilution of A, and 4 ml of a 110.pdfIn a tube containing 1 ml of a 15 dilution of A, and 4 ml of a 110.pdf
In a tube containing 1 ml of a 15 dilution of A, and 4 ml of a 110.pdf
 
Implement a function called getElements() that takes in two lists. T.pdf
Implement a function called getElements() that takes in two lists. T.pdfImplement a function called getElements() that takes in two lists. T.pdf
Implement a function called getElements() that takes in two lists. T.pdf
 
gnmenttakeAssignmentMaindoinvoker assignmentstakeAssignmernt Dr. L. .pdf
gnmenttakeAssignmentMaindoinvoker assignmentstakeAssignmernt Dr. L. .pdfgnmenttakeAssignmentMaindoinvoker assignmentstakeAssignmernt Dr. L. .pdf
gnmenttakeAssignmentMaindoinvoker assignmentstakeAssignmernt Dr. L. .pdf
 
Every cell in our bodies expresses the same genes. True or False.pdf
Every cell in our bodies expresses the same genes. True or False.pdfEvery cell in our bodies expresses the same genes. True or False.pdf
Every cell in our bodies expresses the same genes. True or False.pdf
 
Describe the partition of Z resulting from the equivalence relati.pdf
Describe the partition of Z resulting from the equivalence relati.pdfDescribe the partition of Z resulting from the equivalence relati.pdf
Describe the partition of Z resulting from the equivalence relati.pdf
 
describe what is meant by Rh factor when typing blood.Solution.pdf
describe what is meant by Rh factor when typing blood.Solution.pdfdescribe what is meant by Rh factor when typing blood.Solution.pdf
describe what is meant by Rh factor when typing blood.Solution.pdf
 
Describe the causes, symptoms, and treatment of conjunctivitisSo.pdf
Describe the causes, symptoms, and treatment of conjunctivitisSo.pdfDescribe the causes, symptoms, and treatment of conjunctivitisSo.pdf
Describe the causes, symptoms, and treatment of conjunctivitisSo.pdf
 
Discuss the relationship between gap rule gene mutations, pair-rule .pdf
Discuss the relationship between gap rule gene mutations, pair-rule .pdfDiscuss the relationship between gap rule gene mutations, pair-rule .pdf
Discuss the relationship between gap rule gene mutations, pair-rule .pdf
 
Create a directory your virtual machine. Within that directory creat.pdf
Create a directory your virtual machine. Within that directory creat.pdfCreate a directory your virtual machine. Within that directory creat.pdf
Create a directory your virtual machine. Within that directory creat.pdf
 
Compare between the two light microscope SolutionFeature1. .pdf
Compare between the two light microscope  SolutionFeature1. .pdfCompare between the two light microscope  SolutionFeature1. .pdf
Compare between the two light microscope SolutionFeature1. .pdf
 
Chordin, Tolloid and Sizzled all play important roles in BMP signal r.pdf
Chordin, Tolloid and Sizzled all play important roles in BMP signal r.pdfChordin, Tolloid and Sizzled all play important roles in BMP signal r.pdf
Chordin, Tolloid and Sizzled all play important roles in BMP signal r.pdf
 
Chills are used in casting where the part is likely to form a cavity.pdf
Chills are used in casting where the part is likely to form a cavity.pdfChills are used in casting where the part is likely to form a cavity.pdf
Chills are used in casting where the part is likely to form a cavity.pdf
 
A drug that disrupts tubulin polymerzation is applied to some cell.pdf
A drug that disrupts tubulin polymerzation is applied to some cell.pdfA drug that disrupts tubulin polymerzation is applied to some cell.pdf
A drug that disrupts tubulin polymerzation is applied to some cell.pdf
 
At the second metaphase of meiosis Chromosomes have single chromatid.pdf
At the second metaphase of meiosis  Chromosomes have single chromatid.pdfAt the second metaphase of meiosis  Chromosomes have single chromatid.pdf
At the second metaphase of meiosis Chromosomes have single chromatid.pdf
 

Recently uploaded

Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 

Recently uploaded (20)

Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 

Repeat Programming Project 2 in Chapter 5. This time, add the follow.pdf

  • 1. Repeat Programming Project 2 in Chapter 5. This time, add the following four constructor methods: one for each instance variable, one with two parameters for the two instance variables, and a default constructor. Be sure that each constructor sets all the instance variables. write a driver program to test each of the methods, including each of the four constructors and at least one true or false case for each of the test method. this is the code that i have to add four constructor methods to import java.util.*; public class PersonImproved// Counter is the name of the class and i saved it in a file named PersonImproved. { //Data members private String name; private int age; public void readInput() { Scanner keyboard = new Scanner(System.in); System.out.println("What is the person's name?");// This gets the program ready for keyboard input by telling us that there is a new scanner called keyboard, that is accepting user input. name = keyboard.nextLine(); System.out.println("What is the person's age?"); age = keyboard.nextInt(); while (age < 0) { System.out.println("Age cannot be negative."); System.out.println("Reenter age:"); age = keyboard.nextInt(); } } public void writeOutput() { System.out.println("Name = " + name); System.out.println("Age = " + age); } //method to set non negative age
  • 2. public void set(String newName, int newAge) { name = newName; if (newAge >= 0) age = newAge; else { System.out.println("ERROR: Used a negative age."); System.exit(0); } } //method to setting name public void setName(String newName) { name = newName; } //method to set age public void setAge(int newAge) { if (newAge >= 0) age = newAge; else { System.out.println("ERROR: Used a negative age."); System.exit(0); } } //to get name public String getName() { return name; } public int getAge() { return age; }
  • 3. /*Boolean tests for if two persons are equal (same name and age), if two persons have the same name, if two persons have the same age, if one person is older than another, and if one person is younger than another.*/ public boolean equals(PersonImproved another) { return(this.name.equalsIgnoreCase(another.name) && this.getAge() == another.getAge()); } public boolean isSameName(PersonImproved another) { return(this.name.equalsIgnoreCase(another.name)); } public boolean isSameAge(PersonImproved another) { return(this.getAge() == another.getAge()); } public boolean isOlderThan(PersonImproved another) { return(this.getAge() > another.getAge()); } public boolean isYoungerThan(PersonImproved another) { return(this.getAge() < another.getAge()); } } and this is the test file public class PersonCh6Test { public static void main(String[] args) { System.out.println(); System.out.println("Test case 1: default constructor and"); System.out.println("writeOutput() method.");
  • 4. System.out.println(); PersonCh6 secretAgent1 = new PersonCh6(); System.out.println("Results of default constructor:"); System.out.println("Should be name = "No name" and"); System.out.println("age = 0."); System.out.println(); secretAgent1.writeOutput(); System.out.println(); System.out.println("===================================="); System.out.println("Test case 2: readInput() method."); secretAgent1.readInput(); System.out.println(); System.out.println("Verify name and age."); System.out.println("Should be whatever you just entered."); System.out.println(); secretAgent1.writeOutput(); System.out.println(); System.out.println("===================================="); System.out.println("Test case 3: constructor with just name."); PersonCh6 secretAgent2 = new PersonCh6("Boris"); System.out.println(); System.out.println("Verify name = Boris and age = 0."); System.out.println(); secretAgent2.writeOutput(); System.out.println(); System.out.println("===================================="); System.out.println("Test case 4: constructor with just age."); System.out.println(); System.out.println("Verify name is "No name" and age = 40."); System.out.println(); PersonCh6 secretAgent3 = new PersonCh6(40); secretAgent3.writeOutput(); System.out.println();
  • 5. System.out.println("===================================="); System.out.println("Test case 5: constructor with both name & age."); System.out.println(); System.out.println("Verify name = Natasha & age 39."); System.out.println(); PersonCh6 secretAgent4 = new PersonCh6("Natasha", 39); secretAgent4.writeOutput(); System.out.println(); System.out.println("===================================="); System.out.println(); System.out.println("Test case 6:"); System.out.println("getName: should be Natasha."); System.out.println(); System.out.println("Verify results: "+ secretAgent4.getName()); System.out.println("===================================="); System.out.println(); System.out.println("Test case 7:"); System.out.println("getAge: should be 39"); System.out.println(); System.out.println("Verify results: " + secretAgent4.getAge()); System.out.println("===================================="); System.out.println(); System.out.println("Test case 8:"); System.out.println("setName to Rocky"); secretAgent4.setName("Rocky"); System.out.println(); System.out.println("Verify results with getName(): " + secretAgent4.getName()); System.out.println("===================================="); System.out.println();
  • 6. System.out.println("Test case 9:"); System.out.println("setAge to 99"); secretAgent4.setAge(99); System.out.println(); System.out.println("Verify results: " + secretAgent4.getAge()); System.out.println("===================================="); System.out.println(); System.out.println("Test case 10: set method (both name & age)"); System.out.println("and equals (both name and age)"); System.out.println("Making two persons" + " with same name and age:"); secretAgent1.set("Bullwinkle", 10); secretAgent2.set("Bullwinkle", 10); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be true."); System.out.println(secretAgent1.equals(secretAgent2)); System.out.println("===================================="); System.out.println(); System.out.println("Test case 11:"); System.out.println("equals (both name and age)"); System.out.println("with different names, same ages."); secretAgent2.setName("Boris"); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be false."); System.out.println(secretAgent1.equals(secretAgent2));
  • 7. System.out.println("===================================="); System.out.println(); System.out.println("Test case 12:"); System.out.println("equals (both name and age)"); System.out.println("with different ages, same names."); secretAgent2.setName("Bullwinkle"); secretAgent2.setAge(98); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be false."); System.out.println(secretAgent1.equals(secretAgent2)); System.out.println("===================================="); System.out.println(); System.out.println("Test case 13:"); System.out.println("equals (both name and age)"); System.out.println("with different names and ages."); secretAgent2.setName("Boris"); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be false."); System.out.println(secretAgent1.equals(secretAgent2)); System.out.println("===================================="); System.out.println(); System.out.println("Test case 14:"); System.out.println("isSameName"); System.out.println("with same names and ages."); secretAgent2.set("Bullwinkle", 10);
  • 8. System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be true."); System.out.println(secretAgent1.isSameName(secretAgent2)); System.out.println("===================================="); System.out.println(); System.out.println("Test case 15:"); System.out.println("isSameName"); System.out.println("with same names, different ages."); secretAgent2.setAge(98); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be true."); System.out.println(secretAgent1.isSameName(secretAgent2)); System.out.println("===================================="); System.out.println(); System.out.println("Test case 16:"); System.out.println("isSameName"); System.out.println("with different names, same ages."); secretAgent2.set("Boris", 10); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be false."); System.out.println(secretAgent1.isSameName(secretAgent2)); System.out.println("====================================");
  • 9. System.out.println(); System.out.println("Test case 17:"); System.out.println("isSameName"); System.out.println("with different names, different ages."); secretAgent2.set("Boris", 5); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be false."); System.out.println(secretAgent1.isSameName(secretAgent2)); System.out.println("===================================="); System.out.println(); System.out.println("Test case 18:"); System.out.println("isOlderThan"); System.out.println("with 1st person older than the other."); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be true."); System.out.println(secretAgent1.isOlderThan(secretAgent2)); System.out.println("===================================="); System.out.println(); System.out.println("Test case 19:"); System.out.println("isOlderThan"); System.out.println("with same ages."); secretAgent2.setAge(10); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: ");
  • 10. secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be false."); System.out.println(secretAgent1.isOlderThan(secretAgent2)); System.out.println("===================================="); System.out.println(); System.out.println("Test case 20:"); System.out.println("isOlderThan"); System.out.println("with 1st person younger than the other."); secretAgent2.setAge(100); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be false."); System.out.println(secretAgent1.isOlderThan(secretAgent2)); System.out.println("===================================="); System.out.println(); System.out.println("Test case 21:"); System.out.println("isYoungerThan"); System.out.println("with 1st person younger than the other."); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be true."); System.out.println(secretAgent1.isYoungerThan(secretAgent2)); System.out.println("===================================="); System.out.println(); System.out.println("Test case 22:"); System.out.println("isYoungerThan");
  • 11. System.out.println("with same ages."); secretAgent2.setAge(10); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be false."); System.out.println(secretAgent1.isYoungerThan(secretAgent2)); System.out.println("===================================="); System.out.println(); System.out.println("Test case 20:"); System.out.println("isYoungerThan"); System.out.println("with 1st person older than the other."); secretAgent2.setAge(9); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be false."); System.out.println(secretAgent1.isYoungerThan(secretAgent2)); } } the output should look similar to this Solution import java.util.Scanner; public class PersonImproved { // Data members private String name; private int age; /** * Default constructor
  • 12. */ public PersonImproved() { this.name = "No name"; this.age = 0; } /** * Parameterized constructor with name * @param name */ public PersonImproved(String name) { this.name = name; this.age = 0; } /** * Parameterized constructor with age * @param age */ public PersonImproved(int age) { this.name = "No name"; this.age = age; } /** * Parameterized constructor with name and age * @param name * @param age */ public PersonImproved(String name, int age) { this.name = name; this.age = age; } /** * Gets the name and age from the user */
  • 13. public void readInput() { Scanner keyboard = new Scanner(System.in); System.out.println("What is the person's name?");// This gets the // program ready for // keyboard input by // telling us that // there is a new // scanner called // keyboard, that is // accepting user // input. name = keyboard.nextLine(); System.out.println("What is the person's age?"); age = keyboard.nextInt(); while (age < 0) { System.out.println("Age cannot be negative."); System.out.println("Reenter age:"); age = keyboard.nextInt(); } //Close scanner keyboard.close(); } /** * Displays the name and age */ public void writeOutput() { System.out.println("Name = " + name); System.out.println("Age = " + age); } /** * method to set non negative age * @param newName * @param newAge */ public void set(String newName, int newAge) {
  • 14. name = newName; if (newAge >= 0) age = newAge; else { System.out.println("ERROR: Used a negative age."); System.exit(0); } } /** * method to setting name * @param newName */ public void setName(String newName) { name = newName; } /** * method to set age * @param newAge */ public void setAge(int newAge) { if (newAge >= 0) age = newAge; else { System.out.println("ERROR: Used a negative age."); System.exit(0); } } /** * Gets the name * @return */ public String getName() { return name; } /** * Gets the age
  • 15. * @return */ public int getAge() { return age; } /* * Boolean tests for if two persons are equal (same name and age), if two * persons have the same name, if two persons have the same age, if one * person is older than another, and if one person is younger than another. */ public boolean equals(PersonImproved another) { return (this.name.equalsIgnoreCase(another.name) && this.getAge() == another.getAge()); } public boolean isSameName(PersonImproved another) { return (this.name.equalsIgnoreCase(another.name)); } public boolean isSameAge(PersonImproved another) { return (this.getAge() == another.getAge()); } public boolean isOlderThan(PersonImproved another) { return (this.getAge() > another.getAge()); } public boolean isYoungerThan(PersonImproved another) { return (this.getAge() < another.getAge()); } } public class PersonCh6Test { public static void main(String[] args) { System.out.println(); System.out.println("Test case 1: default constructor and"); System.out.println("writeOutput() method."); System.out.println(); PersonImproved secretAgent1 = new PersonImproved(); System.out.println("Results of default constructor:"); System.out.println("Should be name = "No name" and"); System.out.println("age = 0.");
  • 16. System.out.println(); secretAgent1.writeOutput(); System.out.println(); System.out.println("===================================="); System.out.println("Test case 2: readInput() method."); secretAgent1.readInput(); System.out.println(); System.out.println("Verify name and age."); System.out.println("Should be whatever you just entered."); System.out.println(); secretAgent1.writeOutput(); System.out.println(); System.out.println("===================================="); System.out.println("Test case 3: constructor with just name."); PersonImproved secretAgent2 = new PersonImproved("Boris"); System.out.println(); System.out.println("Verify name = Boris and age = 0."); System.out.println(); secretAgent2.writeOutput(); System.out.println(); System.out.println("===================================="); System.out.println("Test case 4: constructor with just age."); System.out.println(); System.out.println("Verify name is "No name" and age = 40."); System.out.println(); PersonImproved secretAgent3 = new PersonImproved(40); secretAgent3.writeOutput(); System.out.println(); System.out.println("===================================="); System.out.println("Test case 5: constructor with both name & age."); System.out.println(); System.out.println("Verify name = Natasha & age 39."); System.out.println(); PersonImproved secretAgent4 = new PersonImproved("Natasha", 39); secretAgent4.writeOutput(); System.out.println();
  • 17. System.out.println("===================================="); System.out.println(); System.out.println("Test case 6:"); System.out.println("getName: should be Natasha."); System.out.println(); System.out.println("Verify results: " + secretAgent4.getName()); System.out.println("===================================="); System.out.println(); System.out.println("Test case 7:"); System.out.println("getAge: should be 39"); System.out.println(); System.out.println("Verify results: " + secretAgent4.getAge()); System.out.println("===================================="); System.out.println(); System.out.println("Test case 8:"); System.out.println("setName to Rocky"); secretAgent4.setName("Rocky"); System.out.println(); System.out.println("Verify results with getName(): " + secretAgent4.getName()); System.out.println("===================================="); System.out.println(); System.out.println("Test case 9:"); System.out.println("setAge to 99"); secretAgent4.setAge(99); System.out.println(); System.out.println("Verify results: " + secretAgent4.getAge()); System.out.println("===================================="); System.out.println(); System.out.println("Test case 10: set method (both name & age)"); System.out.println("and equals (both name and age)"); System.out.println("Making two persons" + " with same name and age:"); secretAgent1.set("Bullwinkle", 10); secretAgent2.set("Bullwinkle", 10); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: ");
  • 18. secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be true."); System.out.println(secretAgent1.equals(secretAgent2)); System.out.println("===================================="); System.out.println(); System.out.println("Test case 11:"); System.out.println("equals (both name and age)"); System.out.println("with different names, same ages."); secretAgent2.setName("Boris"); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be false."); System.out.println(secretAgent1.equals(secretAgent2)); System.out.println("===================================="); System.out.println(); System.out.println("Test case 12:"); System.out.println("equals (both name and age)"); System.out.println("with different ages, same names."); secretAgent2.setName("Bullwinkle"); secretAgent2.setAge(98); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be false."); System.out.println(secretAgent1.equals(secretAgent2)); System.out.println("===================================="); System.out.println(); System.out.println("Test case 13:"); System.out.println("equals (both name and age)"); System.out.println("with different names and ages.");
  • 19. secretAgent2.setName("Boris"); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be false."); System.out.println(secretAgent1.equals(secretAgent2)); System.out.println("===================================="); System.out.println(); System.out.println("Test case 14:"); System.out.println("isSameName"); System.out.println("with same names and ages."); secretAgent2.set("Bullwinkle", 10); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be true."); System.out.println(secretAgent1.isSameName(secretAgent2)); System.out.println("===================================="); System.out.println(); System.out.println("Test case 15:"); System.out.println("isSameName"); System.out.println("with same names, different ages."); secretAgent2.setAge(98); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be true."); System.out.println(secretAgent1.isSameName(secretAgent2)); System.out.println("===================================="); System.out.println();
  • 20. System.out.println("Test case 16:"); System.out.println("isSameName"); System.out.println("with different names, same ages."); secretAgent2.set("Boris", 10); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be false."); System.out.println(secretAgent1.isSameName(secretAgent2)); System.out.println("===================================="); System.out.println(); System.out.println("Test case 17:"); System.out.println("isSameName"); System.out.println("with different names, different ages."); secretAgent2.set("Boris", 5); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be false."); System.out.println(secretAgent1.isSameName(secretAgent2)); System.out.println("===================================="); System.out.println(); System.out.println("Test case 18:"); System.out.println("isOlderThan"); System.out.println("with 1st person older than the other."); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be true."); System.out.println(secretAgent1.isOlderThan(secretAgent2));
  • 21. System.out.println("===================================="); System.out.println(); System.out.println("Test case 19:"); System.out.println("isOlderThan"); System.out.println("with same ages."); secretAgent2.setAge(10); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be false."); System.out.println(secretAgent1.isOlderThan(secretAgent2)); System.out.println("===================================="); System.out.println(); System.out.println("Test case 20:"); System.out.println("isOlderThan"); System.out.println("with 1st person younger than the other."); secretAgent2.setAge(100); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be false."); System.out.println(secretAgent1.isOlderThan(secretAgent2)); System.out.println("===================================="); System.out.println(); System.out.println("Test case 21:"); System.out.println("isYoungerThan"); System.out.println("with 1st person younger than the other."); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println();
  • 22. System.out.println("Verify results: should be true."); System.out.println(secretAgent1.isYoungerThan(secretAgent2)); System.out.println("===================================="); System.out.println(); System.out.println("Test case 22:"); System.out.println("isYoungerThan"); System.out.println("with same ages."); secretAgent2.setAge(10); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be false."); System.out.println(secretAgent1.isYoungerThan(secretAgent2)); System.out.println("===================================="); System.out.println(); System.out.println("Test case 20:"); System.out.println("isYoungerThan"); System.out.println("with 1st person older than the other."); secretAgent2.setAge(9); System.out.println("First person: "); secretAgent1.writeOutput(); System.out.println("Second person: "); secretAgent2.writeOutput(); System.out.println(); System.out.println("Verify results: should be false."); System.out.println(secretAgent1.isYoungerThan(secretAgent2)); } } OUTPUT: Test case 1: default constructor and writeOutput() method. Results of default constructor: Should be name = "No name" and
  • 23. age = 0. Name = No name Age = 0 ==================================== Test case 2: readInput() method. What is the person's name? John What is the person's age? 10 Verify name and age. Should be whatever you just entered. Name = John Age = 10 ==================================== Test case 3: constructor with just name. Verify name = Boris and age = 0. Name = Boris Age = 0 ==================================== Test case 4: constructor with just age. Verify name is "No name" and age = 40. Name = No name Age = 40 ==================================== Test case 5: constructor with both name & age. Verify name = Natasha & age 39. Name = Natasha Age = 39 ==================================== Test case 6: getName: should be Natasha. Verify results: Natasha ==================================== Test case 7: getAge: should be 39 Verify results: 39
  • 24. ==================================== Test case 8: setName to Rocky Verify results with getName(): Rocky ==================================== Test case 9: setAge to 99 Verify results: 99 ==================================== Test case 10: set method (both name & age) and equals (both name and age) Making two persons with same name and age: First person: Name = Bullwinkle Age = 10 Second person: Name = Bullwinkle Age = 10 Verify results: should be true. true ==================================== Test case 11: equals (both name and age) with different names, same ages. First person: Name = Bullwinkle Age = 10 Second person: Name = Boris Age = 10 Verify results: should be false. false ==================================== Test case 12: equals (both name and age) with different ages, same names.
  • 25. First person: Name = Bullwinkle Age = 10 Second person: Name = Bullwinkle Age = 98 Verify results: should be false. false ==================================== Test case 13: equals (both name and age) with different names and ages. First person: Name = Bullwinkle Age = 10 Second person: Name = Boris Age = 98 Verify results: should be false. false ==================================== Test case 14: isSameName with same names and ages. First person: Name = Bullwinkle Age = 10 Second person: Name = Bullwinkle Age = 10 Verify results: should be true. true ==================================== Test case 15: isSameName with same names, different ages.
  • 26. First person: Name = Bullwinkle Age = 10 Second person: Name = Bullwinkle Age = 98 Verify results: should be true. true ==================================== Test case 16: isSameName with different names, same ages. First person: Name = Bullwinkle Age = 10 Second person: Name = Boris Age = 10 Verify results: should be false. false ==================================== Test case 17: isSameName with different names, different ages. First person: Name = Bullwinkle Age = 10 Second person: Name = Boris Age = 5 Verify results: should be false. false ==================================== Test case 18: isOlderThan with 1st person older than the other.
  • 27. First person: Name = Bullwinkle Age = 10 Second person: Name = Boris Age = 5 Verify results: should be true. true ==================================== Test case 19: isOlderThan with same ages. First person: Name = Bullwinkle Age = 10 Second person: Name = Boris Age = 10 Verify results: should be false. false ==================================== Test case 20: isOlderThan with 1st person younger than the other. First person: Name = Bullwinkle Age = 10 Second person: Name = Boris Age = 100 Verify results: should be false. false ==================================== Test case 21: isYoungerThan with 1st person younger than the other.
  • 28. First person: Name = Bullwinkle Age = 10 Second person: Name = Boris Age = 100 Verify results: should be true. true ==================================== Test case 22: isYoungerThan with same ages. First person: Name = Bullwinkle Age = 10 Second person: Name = Boris Age = 10 Verify results: should be false. false ==================================== Test case 20: isYoungerThan with 1st person older than the other. First person: Name = Bullwinkle Age = 10 Second person: Name = Boris Age = 9 Verify results: should be false. false