View the step-by-step solution to:

To Do: GAME AND GAMEDRIVER In this exercise and the next, you run a business that sells different types of games wholesale to different stores in...

12. To Do: GAME AND GAMEDRIVER
In this exercise and the next, you run a business that sells different types of games wholesale to different stores in the area. There is sample output at the bottom of these directions. Write the Game class. A Game instance is described by three instance variables: gameName (a String), numSold (an integer that represents the number of that type of game sold), and priceEach (a double that is the price of each of that type of Game). I only want three instance variables!! The class should have the following methods:
a. A constructor that has two parameter – a String containing the name of the Game and a double containing its price. The constructor should set the other instance variable to zero.
b. An empty constructor
c. All getters and setters
d. A method updateSales() that takes a single integer parameter representing the number of additional games of that type sold. The method should add this number to the numSold instance variable and return nothing. I will help with this one since it often causes a problem
public void updateSales(int addGame)
{
numSold = numSold + addGame;
}
e. A method totalValue() that takes no parameters and returns the total value of that game item. This is calculated by multiplying the priceEach times the numSold.
f. A toString() method that returns a string containing the name of the game, the number sold, the price each, and the total value

Write a GameDriver program that uses Game objects to track the sales of games sold at a variety of stores.
a. Ask the user for how many different types of games are being sold and read in the answer.
b. Ask the user for how many stores and read in the answer
c. Use loops. You will need nested loops. The outside one will read in each game and the inside one is for each sale for that game.
d. Read in the names and prices of the first game. Create an instance of the class.
e. Loop through reading in sales for each of the stores. Call the updateSales() method after each store.
f. Call your toString() method to print that game.
g. Repeat steps d-f for each of the other games.
h. here is an outline for you

public static void main(String[] args)
{
// ask for the number of games and read it into numGames
// ask for the number of stores and read it into numStores


// beginning of loop for number of games
for(int i = 0; i < howGames; i++)
{
//ask for the name and price and read these into variables
// create a Game instance using the data obtained above

for(int j = 0; j < howStores; j++) // loop through the stores {
// ask for the sales for the current store and read it in
// call updateSales with this number

}

//print out this game info
} //end of inner for loop
} //end of outer for loop
} //end of main

13. To Do: QUOTE AND QUOTEDRIVER. NOTE: There is a start file for this.
Write a class named Quote with a single instance variable named quote that is a String. Write the no-argument and full constructor and the getter and setter. The class should also have methods returns the following:
• The number of characters in the quote
• The quote in all uppercase letters
• The quote in all lowercase letters
• The first character in the quote
• the number of vowels in the string
• the number of consonants in the string.
• A method that asks the user to enter a character. The program should count and return the number of times that the specified character appears in the string.
Here is a UML document for the Quote class. Very cool! Shows the fields and methods. Make certain your methods have the signature seen below.



Demonstrate the class in a program named QuoteDriver that performs the following:

a) The user is asked to enter a string.
b) The program displays a menu giving the user a choice of the methods above. The user should also have a choice of either entering another String or of exiting.
c) The program performs the operation selected by the user and repeats until the user selects to exit the program.
SEE BOTTOM OF DOCUMENT FOR MORE INFORMATION ON THE QUOTE/QUOTEDRIVER APPLICATION

14. Associations are when an instance of a class is a field in another class. Let’s look at a more complete example that uses associations. We will be looking at a class for Sales that has a field that represents the Customer that made the purchase and another that has the Inventory item purchased. Study the code in itp120mod4.Ex4.sales.
15. We have three classes and a driver. The three classes are connected by associations (has-a relationships). A UML diagram is very useful for seeing this relationship. Study and understand the Sales application code.




16. To do: CARPET CALCULATOR
The Westfield Carpet Company has asked you to write an application that calculates the price of carpeting for rectangular rooms. To calculate the price, you multiply the area of the floor (width times length) by the price per square foot of carpet. For example, the area of floor that is 12 feet long and 10 wide is 120 square feet. To cover that floor with carpet that costs $8 per square foot would cost $960. (12 X 10 X 8 = 960.)

First, you should create a class named RoomDimension that has two fields: one for the length of the room and one for the width. The RoomDimension class should have two constructors, a toString() method, getters and setters, and a method that returns the area of the room. (The area of the room is the room’s length multiplied by the room’s width.)

Next you should create a RoomCarpet class that has a RoomDimension object as a field. It should also have a field for the cost of the carpet per square foot. The RoomCarpet class should have two constructors, a toString() method, getters and setters, and a method that returns the total cost of the carpet.

Once you have written these classes, use them in an application named CarpetCalculator that asks the user to enter the dimensions of a room and the price per square foot of the desired carpeting. The driver should create a RoomDimension instance calling the full constructor and use that and the cost per square foot to create a RoomCarpet instance. The application should display the total cost of the carpet.

Add a loop that asks for more calculations (end it by whatever means you wish). Add an accumulator that keeps track of the total price for the estimate.

Write the programs listed above. When you are finished you should have the following programs included in a package named dwolffmod4 (except your name) submitted in a jar file named dwolffmod4.jar. In the lab module, write your comments in the text box (see the syllabus for information). Attach your jar file back in the Assignment and submit it back through the portal.


Step 9. Widget and WidgetDriver
Step 11. Stock and StockDriver
Step 12. Game and GameDriver
Step 13. Quote and QuoteDriver
Step 16. RoomDimension, RoomCarpet, and CarpetCalculator

PLEASE Only include a single package with eleven programs in it.


Typical output expected for Games.

How many games?
3
How many stores?
2
Game Name:
Chutes and Ladders
Price Each:
18.00
STORE 1 Sales
How many Chutes and Ladders were sold?
22
STORE 2 Sales
How many Chutes and Ladders were sold?
21
There are 43 of the game Chutes and Ladders sold. Each costs $18.00 for a total value of $774.00
Game Name:
Monopoly
Price Each:
23.00
STORE 1 Sales
How many Monopoly were sold?
20
STORE 2 Sales
How many Monopoly were sold?
12
There are 32 of the game Monopoly sold. Each costs $23.00 for a total value of $736.00
Game Name:
Bopit
Price Each:
12.50
STORE 1 Sales
How many Bopit were sold?
9
STORE 2 Sales
How many Bopit were sold?
14
There are 23 of the game Bopit sold. Each costs $12.50 for a total value of $287.50

StockDriver sample Output
Customer id: 1234
Name of stock: IBM
Number of shares: 200
Price paid per share: 60.00
Current value per share: 65.00
1234 owns 200 shares of IBM worth $65.00 per share. You paid $60.00 per share.
The total cost of the stock is $12,000.00 and the current value is $13,000.00
More stocks to calculate? (true or false)
true
Customer id: 3434
Name of stock: GOOG
Number of shares: 120
Price paid per share: 45.00
Current value per share: 120.00
3434 owns 120 shares of GOOG worth $120.00 per share. You paid $45.00 per share.
The total cost of the stock is $5,400.00 and the current value is $14,400.00
More stocks to calculate? (true or false)
false

Quote/QuoteDriver



Sample Output
Give me a quote to analyze
I love baseball!! Go Rangers!

Which of the following would you like:
1. The number of characters in the quote
2. The quote in all uppercase letters
3. The quote in all lowercase letters
4. The first character in the quote
5. The number of vowels in the string
6. The number of consonants in the string
7. To count the number of occurrences of a specific character in the string
8. Enter an new string
999. Quit the program
CHOICE:
1
The number of characters in the quote is 29

Which of the following would you like:
1. The number of characters in the quote
2. The quote in all uppercase letters
3. The quote in all lowercase letters
4. The first character in the quote
5. The number of vowels in the string
6. The number of consonants in the string
7. To count the number of occurrences of a specific character in the string
8. Enter an new string
999. Quit the program
CHOICE:
2
The quote in all upper case is I LOVE BASEBALL!! GO RANGERS!

Which of the following would you like:
1. The number of characters in the quote
2. The quote in all uppercase letters
3. The quote in all lowercase letters
4. The first character in the quote
5. The number of vowels in the string
6. The number of consonants in the string
7. To count the number of occurrences of a specific character in the string
8. Enter an new string
999. Quit the program
CHOICE:
3
The quote in all lower case is i love baseball!! go rangers!

Which of the following would you like:
1. The number of characters in the quote
2. The quote in all uppercase letters
3. The quote in all lowercase letters
4. The first character in the quote
5. The number of vowels in the string
6. The number of consonants in the string
7. To count the number of occurrences of a specific character in the string
8. Enter an new string
999. Quit the program
CHOICE:
4
The first character of the quote is I

Which of the following would you like:
1. The number of characters in the quote
2. The quote in all uppercase letters
3. The quote in all lowercase letters
4. The first character in the quote
5. The number of vowels in the string
6. The number of consonants in the string
7. To count the number of occurrences of a specific character in the string
8. Enter an new string
999. Quit the program
CHOICE:
5
The number of vowels in the quote is 9

Which of the following would you like:
1. The number of characters in the quote
2. The quote in all uppercase letters
3. The quote in all lowercase letters
4. The first character in the quote
5. The number of vowels in the string
6. The number of consonants in the string
7. To count the number of occurrences of a specific character in the string
8. Enter an new string
999. Quit the program
CHOICE:
6
The number of consanants in the quote is 13

Which of the following would you like:
1. The number of characters in the quote
2. The quote in all uppercase letters
3. The quote in all lowercase letters
4. The first character in the quote
5. The number of vowels in the string
6. The number of consonants in the string
7. To count the number of occurrences of a specific character in the string
8. Enter an new string
999. Quit the program
CHOICE:
7
What character are you looking for?
b
The number of times the character 'b' occurs in the quote is 2

Which of the following would you like:
1. The number of characters in the quote
2. The quote in all uppercase letters
3. The quote in all lowercase letters
4. The first character in the quote
5. The number of vowels in the string
6. The number of consonants in the string
7. To count the number of occurrences of a specific character in the string
8. Enter an new string
999. Quit the program
CHOICE:
7
What character are you looking for?
R
The number of times the character 'R' occurs in the quote is 1

Which of the following would you like:
1. The number of characters in the quote
2. The quote in all uppercase letters
3. The quote in all lowercase letters
4. The first character in the quote
5. The number of vowels in the string
6. The number of consonants in the string
7. To count the number of occurrences of a specific character in the string
8. Enter an new string
999. Quit the program
CHOICE:
7
What character are you looking for?
r
The number of times the character 'r' occurs in the quote is 1

Which of the following would you like:
1. The number of characters in the quote
2. The quote in all uppercase letters
3. The quote in all lowercase letters
4. The first character in the quote
5. The number of vowels in the string
6. The number of consonants in the string
7. To count the number of occurrences of a specific character in the string
8. Enter an new string
999. Quit the program
CHOICE:
8
Give me a new quote to analyze
I am having fun.... are you??

Which of the following would you like:
1. The number of characters in the quote
2. The quote in all uppercase letters
3. The quote in all lowercase letters
4. The first character in the quote
5. The number of vowels in the string
6. The number of consonants in the string
7. To count the number of occurrences of a specific character in the string
8. Enter an new string
999. Quit the program
CHOICE:
1
The number of characters in the quote is 29

Which of the following would you like:
1. The number of characters in the quote
2. The quote in all uppercase letters
3. The quote in all lowercase letters
4. The first character in the quote
5. The number of vowels in the string
6. The number of consonants in the string
7. To count the number of occurrences of a specific character in the string
8. Enter an new string
999. Quit the program
CHOICE:
2
The quote in all upper case is I AM HAVING FUN.... ARE YOU??

Which of the following would you like:
1. The number of characters in the quote
2. The quote in all uppercase letters
3. The quote in all lowercase letters
4. The first character in the quote
5. The number of vowels in the string
6. The number of consonants in the string
7. To count the number of occurrences of a specific character in the string
8. Enter an new string
999. Quit the program
CHOICE:
3
The quote in all lower case is i am having fun.... are you??

Which of the following would you like:
1. The number of characters in the quote
2. The quote in all uppercase letters
3. The quote in all lowercase letters
4. The first character in the quote
5. The number of vowels in the string
6. The number of consonants in the string
7. To count the number of occurrences of a specific character in the string
8. Enter an new string
999. Quit the program
CHOICE:
4
The first character of the quote is I

Which of the following would you like:
1. The number of characters in the quote
2. The quote in all uppercase letters
3. The quote in all lowercase letters
4. The first character in the quote
5. The number of vowels in the string
6. The number of consonants in the string
7. To count the number of occurrences of a specific character in the string
8. Enter an new string
999. Quit the program
CHOICE:
5
The number of vowels in the quote is 10

Which of the following would you like:
1. The number of characters in the quote
2. The quote in all uppercase letters
3. The quote in all lowercase letters
4. The first character in the quote
5. The number of vowels in the string
6. The number of consonants in the string
7. To count the number of occurrences of a specific character in the string
8. Enter an new string
999. Quit the program
CHOICE:
6
The number of consanants in the quote is 8

Which of the following would you like:
1. The number of characters in the quote
2. The quote in all uppercase letters
3. The quote in all lowercase letters
4. The first character in the quote
5. The number of vowels in the string
6. The number of consonants in the string
7. To count the number of occurrences of a specific character in the string
8. Enter an new string
999. Quit the program
CHOICE:
7
What character are you looking for?
?
The number of times the character '?' occurs in the quote is 2

Which of the following would you like:
1. The number of characters in the quote
2. The quote in all uppercase letters
3. The quote in all lowercase letters
4. The first character in the quote
5. The number of vowels in the string
6. The number of consonants in the string
7. To count the number of occurrences of a specific character in the string
8. Enter an new string
999. Quit the program
CHOICE:
7
What character are you looking for?
.
The number of times the character '.' occurs in the quote is 4

Which of the following would you like:
1. The number of characters in the quote
2. The quote in all uppercase letters
3. The quote in all lowercase letters
4. The first character in the quote
5. The number of vowels in the string
6. The number of consonants in the string
7. To count the number of occurrences of a specific character in the string
8. Enter an new string
999. Quit the program
CHOICE:
999
Thanks for playing my game!
Sign up to view the entire interaction

Top Answer

Please download .Java files. Change package name as required by the course instructor.... View the full answer

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online