Question: Module: Core Java Lab7: java.lang and java.util packages Create a class called Name as: Name - lastName: String - firstName: String +Name(String lastName, String firstName)

Module: Core Java
Lab7: java.lang and java.util packages

Create a class called Name as:

Name
- lastName: String
- firstName: String
+Name(String lastName, String firstName)
+ getLastName(): String
+ setLastName(String lastName): void
+ getFirstName(): String
+ setFirstName(String firstName): void

Write a program with the following requirements:
Creates 10 Name objects with:
? FirstName, LastName are produced randomly from [Oscar, Grouch, John, Lennon, Groucho, Marx, Karl, Marx].
? Ensure that there is no duplicate Name object.
Displays all full name (Name.LastName + Name.FirstName) in ascending order of lastName ( if equals lastName then sort by firstName).

Hint:
• class Name implements Comparable to ordering 2 Name objects.
• override equals(..) method to compare 2 Name objects.
• override toString() method to return full name.
• use Set to ensure no duplicate.
• use Random class to create random value.
• use support class Collections to sort all Name objects.

Step by Step Solution

3.39 Rating (149 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Create class called Name a as public class Name implements Comparable lastName ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!