Question
Restrictions: you cannot use any methods from the Java Array(s) class to copy an array, check for equality, or otherwise manipulate an array. You must
Restrictions: you cannot use any methods from the Java Array(s) class to copy an array, check for equality, or otherwise manipulate an array. You must write the Java code to perform these functions.
Step 1:
Create a class named LuckyNumber that has the following instance variables:
- String name
- int luckyNumber
This class should only have a single overload constructor that:
- takes a single parameter, name
- automatically assigns luckyNumber a random number between 0 and 9 (inclusive of both) to the instance being created
This class must have the following methods:
- getName
- get luckyNumber
- toString
- make sure your toString returns the class name
- the class name will be useful if you become lost in your data structure
- equals
This class should not have the following methods:
- set name
- you are who you are
- set luckyNumber
- you cant change your luck
Step 2:
Create a class named LuckyNumberList that will contain a LinkedPositionalList of LuckyNumber objects.
This class should contain a constructor and methods similar to the Alphabet class in the IteratorExample1 project.
- Unlike the Alphabet class your constructor should just create an empty LinkedPositionalList
- You will need to add a addLuckyNumber method to this class
- This method has a single parameter of type LuckyNumber.
- this method should add the new entry at the end of the list.
- It will be the job of the client class the add entries into the list.
You will be adding two custom iterators:
- an iterator that iterates over the positions in the list that have an even LuckyNumber
- an iterator that iterates over the positions in the list that have a prime LuckyNumber
- Note, if you use the Alphabet class as a guide you will remove the VowelPositionIterator. Actually, you may find it helpful to modify the VowelPositionIterator into one of the above required iterators.
Step 3:
Create a client class named Client that does the following:
- Creates an instance of your LuckyNumberList class.
- Fills the list with at least ten (10) names.
- You can hardwire the fills into your code by using ten calls to addLuckyNumber that pass new instances of LuckyNumber objects.
- Names can be hardwired into your code.
- Prints out the resulting contents of your instance of the LuckyNumberList class using:
- The default iterator that displays all entries in the list
- The Prime iterator that displays only the entries in the list that have prime luckyNumbers
- The Even iterator that display only the entries in the list that have even luckyNumbers.
- You output should be similar to the output listed below:
- Correct use of the printf method makes printing this output easy
- Your output should be nicely formatted but it does not have to dynamically adjust to minimum field width size
- You do not need to create an ASCII table
You may need to run your program several times in order to get a good mix of even/odd and prime/not prime entries.
Lucky Number List Contents (printed with default iterator)
Joe 0 Even Not Prime
Tina 8 Even Not Prime
George 2 Even Prime
Bobbie 5 Odd Prime
Fred 1 Odd Not Prime
Karen 9 Odd Not Prime
Linda 0 Even Not Prime
Gale 3 Odd Prime
Rick 0 Even Not Prime
Sharon 6 Even Not Prime
Frankie 5 Odd Prime
Vance 2 Even Prime
Lori 0 Even Not Prime
Lucky Number List Contents (printed with Prime iterator)
George 2 Even Prime
Bobbie 5 Odd Prime
Gale 3 Odd Prime
Frankie 5 Odd Prime
Vance 2 Even Prime
Lucky Number List Contents (printed with even iterator)
Joe 0 Even Not Prime
Tina 8 Even Not Prime
George 2 Even Prime
Linda 0 Even Not Prime
Rick 0 Even Not Prime
Sharon 6 Even Not Prime
Vance 2 Even Prime
Lori 0 Even Not Prime
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