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
Step: 1
Create class called Name a as public class Name implements Comparable lastName ...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