Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java program to demonstrate using vectors, enumerations and instanceof. You will create a wallet that contains a random number of items from different

Write a Java program to demonstrate using vectors, enumerations and instanceof. You will create a wallet that contains a random number of items from different classes of content. Each class of content will be an enumeration.

#Please DON'T copy and past other's solution, I looked through them all. Thank you!

Recall that enumerations are special forms of classes and therefore are subclasses of the Object superclass. Using your knowledge of enumerations, create the following enumerations with the constants defined below:

public enum CreditCard {Visa, MasterCard, AmericanExpress, Lowes, BJs, HomeDepot, DinersClub, Debit}; public enum Photos {Spouse, Dog, Cat, Pet, Children, Friend, Parents, Grandparents}; public enum MiscCards {DriverLicense, MilitaryID, SSNCard, BloodDonor, Insurance, Library, RecordOfConviction, BarnesAndNoble, Borders}; public enum PaperCurrency {One, Five, Ten, Twenty, Fifty, Hundred}; 

Your wallet will be a Vector class of type Object. In this way you can add any type of item to the wallet. Your wallet will contain the following materials:

  • Between 2 and 5 credit cards, inclusive.
  • Between 0 and 10 photos, inclusive.
  • Between 3 and 6 miscellaneous cards, inclusive.
  • Between 0 and 20 pieces of paper currency, inclusive.

Each of the above is a random value within the specified range, but the catch is each item of a given category must be selected randomly. That is, if you are to add 3 credit cards to the wallet, each credit card type must be randomly selected. This is also true for all of the other categories. (Duplicates are allowed!)

Where this gets a little tricky is after the wallet is filled, you will shuffle the wallet using the Collections.shuffle() method. This will further randomize the contents.

At this point, someone has basically handed you your wallet with its contents stuffed into a paper bag. You now have to reorganize it. This is to be done by creating four methods to print the Vector contents for each class of item using the instanceof operator.

A sample template for these methods is show here:

public static void printCreditCards (Vector w) { // your code here }  

The following output is your guide on how to proceed:

Contents of wallet: [BJs, MasterCard, Spouse, Cat, Children, Parents, GrandParents, Insurance, Borders, BarnesAndNoble, BarnesAndNoble, One, Fifty, Ten, Ten, Five, Ten, One, Twenty, Ten, Hundred] Contents of wallet after shuffle: [Borders, BarnesAndNoble, Ten, Fifty, Parents, Five, Ten, Spouse, Children, MasterCard, Cat, GrandParents, One, One, Insurance, Hundred, Ten, BJs, BarnesAndNoble, Twenty, Ten] Credit Cards: MasterCard BJs Photos: Parents Spouse Children Cat GrandParents Miscellaneous Cards: Borders BarnesAndNoble Insurance BarnesAndNoble Paper Currency: Ten Fifty Five Ten One One Hundred Ten Twenty Ten Currency value: 217 dollars 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Pro PowerShell For Database Developers

Authors: Bryan P Cafferky

1st Edition

1484205413, 9781484205419

More Books

Students also viewed these Databases questions