Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 7 (Chapter 8) Override the toString() method and equals() method inside your class you created from Assignment 5. [2 points] Create a Copy Constructor

Assignment 7 (Chapter 8) Override the toString() method and equals() method inside your class you created from Assignment 5. [2 points] Create a Copy Constructor in your class from Assignment 5. [1 point] Create a static field in your class called counter. It should increment everytime an object is created. [1 point] Create a static method that displays the counter value. Also call this method at the end of your main method. [1 point] Use the "this" reference in all your setter (mutator) methods and also use the "this" reference in your default constructor to call the parameterized constructor. [1 point] Demonstrate that the copy Constructor, toString, and equals methods work in your main method [1 point]

package classes.and.objects;

public class Military

{

private String firstName;

private String lastName;

private int age;

private double asvabScore;

private boolean eligibility;

public Military()

{

firstName ="Unknown";

lastName="Unknown";

age=0;

asvabScore=0;

}

public Military(String f, String l, int a, double s)

{

firstName=f;

lastName=l;

age=a;

asvabScore=s;

}

public void setFirstName(String f)

{

firstName=f;

}

public void setLastName(String l)

{

lastName=l;

}

public void setAge(int a)

{

age=a;

}

public void setAsvabScore(double s)

{

asvabScore=s;

}

public String getFirstName()

{

return firstName;

}

public String getLastName()

{

return lastName;

}

public int getAge()

{

return age;

}

public double getAsvabScore()

{

return asvabScore;

}

public void display()

{

System.out.print(firstName+" ");

System.out.println(lastName);

System.out.print("Age: "+age);

System.out.println(", Test score: "+asvabScore);

}

public boolean testEligibility()

{

if(age>=18 && asvabScore>69)

{

eligibility=true;

}

return eligibility;

}

}

-------------------------------------------------------------------------------------------------------------------

package classes.and.objects;

import java.util.Scanner;

public class Demo {

public static void main(String[] args)

{

Military mark= new Military();

mark.setFirstName("Mark");

mark.setLastName("Cardenas");

mark.setAge(24);

mark.setAsvabScore(85);

mark.display();

System.out.println("Did he pass the initial requirement?: "+mark.testEligibility());

System.out.println("---------------------------------");

Military john= new Military("John", "Legend", 15, 75);

john.display();

System.out.println("Did he pass the initial requirement?: " +john.testEligibility());

System.out.println("---------------------------------");

@SuppressWarnings("resource")

Scanner keyboard= new Scanner(System.in);

System.out.println("Enter your first name: ");

String firstN=keyboard.nextLine();

System.out.println("Enter your last name: ");

String lastN=keyboard.nextLine();

System.out.println("Enter your age: ");

int age1=keyboard.nextInt();

System.out.println("Enter your asvab test score: ");

double asvab=keyboard.nextDouble();

Military mil =new Military(firstN, lastN, age1, asvab);

System.out.println("-----------------------------------");

System.out.print(mil.getFirstName());

System.out.println(" "+mil.getLastName());

System.out.print("Age: "+mil.getAge());

System.out.println(", Test score: "+mil.getAsvabScore());

System.out.println("Did he/she pass the initial requirement?: " +mil.testEligibility());

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2018 Dublin Ireland September 10 14 2018 Proceedings Part 1 Lnai 11051

Authors: Michele Berlingerio ,Francesco Bonchi ,Thomas Gartner ,Neil Hurley ,Georgiana Ifrim

1st Edition

3030109240, 978-3030109240

More Books

Students also viewed these Databases questions

Question

4. What decision would you make and why?

Answered: 1 week ago

Question

3. Review the evidence. Do you believe the testimony presented?

Answered: 1 week ago

Question

1. What are the marketing implications of this situation?

Answered: 1 week ago