Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 ... 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

Survey of Accounting

Authors: Edmonds, old, Mcnair, Tsay

2nd edition

9780077392659, 978-0-07-73417, 77392655, 0-07-734177-5, 73379557, 978-0073379555

Students also viewed these Accounting questions

Question

A function contains the statements that make up the function.

Answered: 1 week ago