Question 1 - CardTool
Question Prompt
Starter Code is available on Vocareum.
As an avid trading card enthusiast, you decide to attend a local card trading event to add to your collection. You decide to write a Java program to help you track your cards and their values.
The program will need to collect information about the cards collected and their values. Using that data, you will generate a receipt that documents the entire collection.
Specific processing instructions are included in the next section.
You must create and implement one class with a main method. The class should be named: CardTool.
Note: Do not use multiple Scanners or global Scanners during this question. You will not receive any credit for a solution that does so.
Implementation Guidelines
The program will accept input Strings with a user's trading card information and generates a report. Use the Starter Code for all output.
Input
The input will include all the relevant data for a user’s cards.
- The first line of input will always be the order initiation. If it is "Yes" or "yes", the program continues, otherwise, it prints the exit message and terminates.
- The second line of input will be the type of card being added.
- The third line of input will be the card's name.
- The fourth line of input will be the request to add another card.
- The fifth and subsequent lines of input will depend on the response to the fourth prompt. If another card is requested, return to the second input, otherwise, continue.
Here’s an example:
Welcome to the Trading Card Tool!
Would you like to add a card?
[Yes]
(1) Common
(2) Uncommon
(3) Super
(4) Rare
(5) Legendary
(6) Exit
Enter the card rarity you would like to place in the deck.
[1]
What is the name of the Common trading card?
[CS 18000]
Would you like to add another card?
[No]
The total cost for all the cards you collected today is 13.00.
After collecting the cards, here's your receipt: C:CS 18000
You collected 1 Common card(s).
You collected 0 Uncommon card(s).
You collected 0 Super card(s).
You collected 0 Rare card(s).
You collected 0 Legendary card(s).
Thank you for using the Trading Card Tool!
- The first input verifies the interest in adding a card: "Yes"
- The second input selects the type of card being added: 1.
- The third input indicates the name of the card being added: "CS 18000"
- The fourth input indicates if the user would like to process another card: "No".
Note: Brackets [] indicate input.
Note: The total cost is printed to two decimal places.
Processing
All processing examples use the sample input described in the previous section.
The user should be able to enter in as many cards as they like. You must track each card and add the information to the report.
General Input
- The user will enter "Yes" or "yes" in response to question prompts if they wish to proceed. All other inputs should be treated as "No".
- If the user enters an invalid integer for the menu options, print an error message ("You picked an invalid choice! Try again.") and reprint the menu until the input is valid.
Total Cost
The purchase cost associated with each card is listed below:
Card
|
Price
|
Common
|
13
|
Uncommon
|
54
|
Super
|
133
|
Rare
|
267
|
Legendary
|
599
|
Variables are included in the Starter Code with these values. Calculate the total cost based on the cards added.
Report Code
The Report code consists of a String generated by processing the results of the input.
Append each of the cards added to the report code as semicolon-separated values. Note: The last item should not be followed by a semicolon. For each card added, include the first letter of the card type, a colon, and the name.
For example, if the user adds two common cards, the first named "CS 18000" and the second named "CS 24000", the report would be as follows: "C:CS 18000;C:CS 24000".
Full Receipt
In addition to tracking the cost and details of each card, you'll need to track the number of each type of card as well. Include this information in the full receipt. Increment the count each time a user adds a specific card and use that number when printing the final result.
You collected 1 Common card(s).
You collected 0 Uncommon card(s).
You collected 0 Super card(s).
You collected 0 Rare card(s).
You collected 0 Legendary card(s).
Output
You are required to print the prompts sent to the user. The tests will check if you’ve printed the correct results, formatted properly.
The user will enter the inputs.
Print the following:
- Prompts for each of the inputs.
- Each of the specified outputs.
Note: Brackets [] indicate input.
Test Run 1
Welcome to the Trading Card Tool!
Would you like to add a card?
[Yes]
(1) Common
(2) Uncommon
(3) Super
(4) Rare
(5) Legendary
(6) Exit
Enter the card rarity you would like to place in the deck.
[1]
What is the name of the Common trading card?
[CS 18000]
Would you like to add another card?
[Yes]
(1) Common
(2) Uncommon
(3) Super
(4) Rare
(5) Legendary
(6) Exit
Enter the card rarity you would like to place in the deck.
[2]
What is the name of the Uncommon trading card?
[CS 24000]
Would you like to add another card?
[Yes]
(1) Common
(2) Uncommon
(3) Super
(4) Rare
(5) Legendary
(6) Exit
Enter the card rarity you would like to place in the deck.
[3]
What is the name of the Super trading card?
[CS 25000]
Would you like to add another card?
[Yes]
(1) Common
(2) Uncommon
(3) Super
(4) Rare
(5) Legendary
(6) Exit
Enter the card rarity you would like to place in the deck.
[4]
What is the name of the Rare trading card?
[CS 251000]
Would you like to add another card?
[Yes]
(1) Common
(2) Uncommon
(3) Super
(4) Rare
(5) Legendary
(6) Exit
Enter the card rarity you would like to place in the deck.
[5]
What is the name of the Legendary trading card?
[CS 25200]
Would you like to add another card?
[No]
The total cost for all the cards you collected today is 1066.00.
After collecting the cards, here's your receipt: C:CS 18000;U:CS 24000;
S:CS 25000;R:CS 251000;L:CS 25200
You collected 1 Common card(s).
You collected 1 Uncommon card(s).
You collected 1 Super card(s).
You collected 1 Rare card(s).
You collected 1 Legendary card(s).
Thank you for using the Trading Card Tool!
Test Run 2
Welcome to the Trading Card Tool!
Would you like to add a card?
[Yes]
(1) Common
(2) Uncommon
(3) Super
(4) Rare
(5) Legendary
(6) Exit
Enter the card rarity you would like to place in the deck.
[6]
Thank you for using the Trading Card Tool!
Test Run 3
Welcome to the Trading Card Tool!
Would you like to add a card?
[No]
Thank you for using the Trading Card Tool!
Test Run 4
Welcome to the Trading Card Tool!
Would you like to add a card?
[Yes]
(1) Common
(2) Uncommon
(3) Super
(4) Rare
(5) Legendary
(6) Exit
Enter the card rarity you would like to place in the deck.
[2]
What is the name of the Uncommon trading card?
[Programming in C]
Would you like to add another card?
[Yes]
(1) Common
(2) Uncommon
(3) Super
(4) Rare
(5) Legendary
(6) Exit
Enter the card rarity you would like to place in the deck.
[4]
What is the name of the Rare trading card?
[Data Structures and Algorithms]
Would you like to add another card?
[Yes]
(1) Common
(2) Uncommon
(3) Super
(4) Rare
(5) Legendary
(6) Exit
Enter the card rarity you would like to place in the deck.
[6]
The total cost for all the cards you collected today is 321.00.
After collecting the cards, here's your receipt: U:Programming in C;R:Data Structures and Algorithms
You collected 0 Common card(s).
You collected 1 Uncommon card(s).
You collected 0 Super card(s).
You collected 1 Rare card(s).
You collected 0 Legendary card(s).
Thank you for using the Trading Card Tool!
Test Run 5
Welcome to the Trading Card Tool!
Would you like to add a card?
[Yes]
(1) Common
(2) Uncommon
(3) Super
(4) Rare
(5) Legendary
(6) Exit
Enter the card rarity you would like to place in the deck.
[7]
You chose an invalid menu choice, try again!
(1) Common
(2) Uncommon
(3) Super
(4) Rare
(5) Legendary
(6) Exit
Enter the card rarity you would like to place in the deck.
[6]
Thank you for using the Trading Card Tool!
Assumptions
You can assume the following:
- Newlines will not be considered during grading.They are added to the sample output for readability.
Question 2 - CardCollection
Question Prompt
Continuing your efforts to document your card collection, you decide to write additional classes to store information about the cards.
This problem will involve two additional classes. The first,Card, will document the specific details associated with a given card in the collection. The second,CardCollection, will have a few useful calculations for the user.
You must create and implement the following classes:CardandCardCollection.
Note: There should not be a main method in either class. Implement functionality in the methods as they are described.
Card
Fields
Field name
|
Field Type
|
Access Modifier
|
Description
|
rarity
|
String
|
private
|
Therarityof thisCard.
|
name
|
String
|
private
|
Thenameof thisCard.
|
brand
|
String
|
private
|
Thebrandof thisCard.
|
isLimited
|
boolean
|
private
|
The limited availability statusof thisCard.
|
basePrice
|
double
|
private
|
ThebasePriceof thisCard.
|
Constructor
Access Modifier
|
Parameter List
|
Description
|
public
|
String rarity,
String name,
String brand,
boolean isLimited,
double basePrice
|
Constructs a newly allocatedCardobject and instantiates the fields to the specified parameters.
|
Methods
Method Name
|
Return Type
|
Parameters
|
Modifiers
|
getRarity
|
String
|
None
|
public
|
getName
|
String
|
None
|
public
|
getBrand
|
String
|
None
|
public
|
getLimited
|
boolean
|
None
|
public
|
getBasePrice
|
double
|
None
|
public
|
setRarity
|
void
|
String rarity
|
public
|
setName
|
void
|
String name
|
public
|
setBrand
|
void
|
String brand
|
public
|
setLimited
|
void
|
booleanisLimited
|
public
|
setBasePrice
|
void
|
double basePrice
|
public
|
calculateModifiedPrice
|
double
|
None
|
public
|
toString
|
String
|
None
|
public
|
Method Descriptions
Method
|
Description
|
getRarity
|
Returns therarityof thisCard.
|
getName
|
Returns thenameof thisCard.
|
getBrand
|
Returns thebrandof thisCard.
|
getLimited
|
Returns the limited availability status of thisCard.
|
getBasePrice
|
Returns thebasePriceof thisCard.
|
setRarity
|
Sets therarityof thisCard.
|
setName
|
Sets thenameof thisCard.
|
setBrand
|
Sets thebrandof thisCard.
|
setLimited
|
Sets the limited availability status of thisCard.
|
setBasePrice
|
Sets thebasePriceof thisCard.
|
calculateModifiedPrice
|
Returns the modified price. Multiply thebasePriceby the appropriate value for eachrarityand return the result.
- "Common" - 13
- "Uncommon" - 54
- "Super" - 133
- "Rare" - 267
- "Legendary" - 599
For example, a card with abasePriceof 4 and Uncommonraritywould return 216.00.
If therarityisn't one of the listed options, just return thebasePricewithout modification.
|
toString
|
Returns the String representation of thisCard.
For Example, given the following fields:
rarity= "Common"
name= "CS 18000"
brand= "Cards International"
isLimited= true
basePrice= 4.00
The result of callingtoString()would be:
Follow the example formatting exactly! Note that each comma is followed by exactly one blank. Format any double to two decimal places.
Note: The angle brackets <> are part of the expected String. It is not necessary to add a newline to the result at any point, though they may appear in the example for readability.
|
CardCollection
Fields
Field name
|
Field Type
|
Access Modifier
|
Description
|
numCommon
|
int
|
private
|
The number of common cards in thisCardCollection.
|
numUncommon
|
int
|
private
|
The number of uncommon cards in thisCardCollection.
|
numSuper
|
int
|
private
|
The number of super cards in thisCardCollection.
|
numRare
|
int
|
private
|
The number of rare cards in thisCardCollection.
|
numLegendary
|
int
|
private
|
The number of legendary cards in thisCardCollection.
|
Constructor
Access Modifier
|
Parameter List
|
Description
|
public
|
int numCommon,
int numUncommon,
int numSuper,
int numRare,
int numLegendary
|
Constructs a newly allocatedCardCollectionobject and instantiates the fields to the specified parameters.
|
Methods
Method Name
|
Return Type
|
Parameters
|
Modifiers
|
getNumCommon
|
int
|
None
|
public
|
getNumUncommon
|
int
|
None
|
public
|
getNumSuper
|
int
|
None
|
public
|
getNumRare
|
int
|
None
|
public
|
getNumLegendary
|
int
|
None
|
public
|
setNumCommon
|
void
|
int numCommon
|
public
|
setNumUncommon
|
void
|
int numUncommon
|
public
|
setNumSuper
|
void
|
int numSuper
|
public
|
setNumRare
|
void
|
int numRare
|
public
|
setNumLegendary
|
void
|
int numLegendary
|
public
|
calculatePercentageByRarity
|
double
|
String rarity
|
public
|
calculateTotalCollectionValue
|
double
|
None
|
public
|
toString
|
String
|
None
|
public
|
Method Descriptions
Method
|
Description
|
getNumCommon
|
Returns thenumCommonof thisCardCollection.
|
getNumUncommon
|
Returns thenumUncommonof thisCardCollection.
|
getNumSuper
|
Returns thenumSuperof thisCardCollection.
|
getNumRare
|
Returns thenumRareof thisCardCollection.
|
getNumLegendary
|
Returns thenumLegendaryof thisCardCollection.
|
setNumCommon
|
Sets thenumCommonof thisCardCollection.
|
setNumUncommon
|
Sets thenumUncommonof thisCardCollection.
|
setNumSuper
|
Sets thenumSuperof thisCardCollection.
|
setNumRare
|
Sets thenumRareof thisCardCollection.
|
setNumLegendary
|
Sets thenumLegendaryof thisCardCollection.
|
calculatePercentageByRarity
|
Given a rarity String, return the percentage of the total cards of that rarity currently present in the collection.
For example, given the following values:
- numCommon = 30
- numUncommon = 35
- numSuper = 5
- numRare = 15
- numLegendary = 15
If the rarity were "Super", the returned value would be the 0.05. If the rarity is not one of the options listed, return 0.
|
calculateTotalCollectionValue
|
Return the total cost of every card in the collection. Use the following values for the prices of each card by rarity:
- "Common" - 13
- "Uncommon" - 54
- "Super" - 133
- "Rare" - 267
- "Legendary" - 599
If there are 5 common cards, 3 super cards, and no other cards in the collection, the returned result would be 464.
Note: Do not consider thebasePriceas a factor in this calculation, only use the rarity cost and number of cards.
|
toString
|
Returns the String representation of thisCardCollection.
For Example, given the following fields:
numCommon= 15
numUncommon= 10
numSuper= 5
numRare= 3
numLegendary= 4
The result of callingtoString()would be:
Follow the example formatting exactly! Note that each comma is followed by exactly one blank.
Note: The angle brackets <> are part of the expected String. It is not necessary to add a newline to the result at any point, though they may appear in the example for readability.
|