Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java program to demonstrate using vectors, enumerations and instanceof.

ID: 3631083 • Letter: W

Question

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.

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:
CreditCard = {Visa, MasterCard, AmericanExpress, Lowes, BJs, HomeDepot, DinersClub, Debit}
Photos = {Spouse, Dog, Cat, Pet, Children, Friend, Parents, Grandparents}
MiscCards = {DriverLicense, MilitaryID, SSNCard, BloodDonor, Insurance, Library,
RecordOfConviction, BarnesAndNoble, Borders}
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.

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

Explanation / Answer

import java.util.Collections; import java.util.Random; import java.util.Vector; enum CreditCard {Visa, MasterCard, AmericanExpress, Lowes, BJs, HomeDepot, DinersClub, Debit}; enum Photos {Spouse, Dog, Cat, Pet, Children, Friend, Parents, Grandparents}; enum MiscCards {DriverLicense, MilitaryID, SSNCard, BloodDonor, Insurance, Library, RecordOfConviction, BarnesAndNoble, Borders}; enum PaperCurrency {One, Five, Ten, Twenty, Fifty, Hundred}; public class VectorEnum { static Vector wallet= new Vector(); static Random rnd=null; public static void main(String[] args) { rnd = new Random(); //Adding Credit Cards to Wallet int numCreditCardstoAdd = genRandomNumWithinRange(2,5,rnd); for(int i=0;i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote