Question
Java Problem, Problem 1] Create a class named Employee. The class has the following instance variables, constructor, and methods. A private String instance variable named
Java Problem,
Problem 1] Create a class named Employee. The class has the following instance variables, constructor, and methods.
A private String instance variable named name.
A private String instance variable named ssn.
A private integer instance variable named seniority. A public getter and setter method for each instance variable.
A public constructor that takes three arguments and sets the values of the instance variables accordingly.
A public instance method named displayEmployee() that takes no argument and returns no value. The method displays the information of the employee in a format of your design.
Create the class TestEmployee to test the functionality of the class Employee.
Problem 2] Create a class named Country. The class Country includes the following instance variables, constructor, and methods.
A private String instance variable named name. A private double instance variable named population (in Million).
A private double instance variable named area (in thousand square mile).
An empty no-arg constructor.
A public constructor that takes three arguments and sets the instance variables accordingly.
A setter and getter method for each of the instance variables.
A public instance method named printCountry that takes no argument and returns no value. The method displays the information of the country (the data fields of the invoking object).
Create a class named TestCountry to test the functionality of the class Country.
Optional: [Extension to the class Country]
A public instance method named countryInfo that takes no argument and returns no value. The method displays the country information if the country has a name, has a population larger than 0 and an area larger than 0. Otherwise, the method should display No sufficient information to be displayed.
A public instance method named copyCountry that does not take any argument and returns a variable of type Country. The method returns a copy of this object. To do that:
o Create a new object of type Country inside the method copyCountry
o Copy the instance variables of this object to the corresponding instance variables of the object created in the first step
o Return the new object that was created in the method copyCountry
A public static method named mergeCountries that takes three arguments; two arguments of type Country (reference variables to objects of type Country) and an argument of type String. The method returns an object of type Country. The returned object includes the information of the result of merger/unification of the two countries whose information are stored in the two Country objects provided as the first two arguments. The population/area of the new country is the sum of the population/area of the two merged countries. The name of the new country is given as the third argument of the method. The following is an example of using this method to merge two objects.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started