Question: Chapter 1 exercises Design a class to represent a credit card. Think about the attributes of a credit card; that is, what data is on

Chapter 1 exercises

Design a class to represent a credit card. Think about the attributes of a credit card; that is, what data is on the card? What behaviors might be reasonable for a credit card? Use the answers to these questions to write a UML class diagram for a credit card class. Then give three examples of instances of this class.

Repeat Exercise 1 for a credit card account instead of a credit card. An account represents the charges and payments made using a credit card.

Repeat Exercise 1 for a coin instead of a credit card.

Repeat Exercise 1 for a collection of coins instead of a credit card.

Consider a Java class that you could use to get an acceptable integer value from the user.

An object of this class will have the attributes

Minimum accepted value

Maximum accepted value

Prompt string

The following method:

getValue displays the prompt and reads a value using the class Scanner. If the value read is not within the allowed range, the method should display an error message and ask the user for a new value, repeating these actions until an acceptable value is entered. The method then returns the value read.

Implement the class in Java.

Write some Java statements that test the class.

Consider a class that keeps track of the sales of an item. An object of this class will have the attributes

number sold

total sales

total discounts

Cost per item

Bulk quantity

Bulk discount percentage

and the following methods:

registerSale(n) records the sale of n items. If n is larger than the bulk quantity, the cost per item will be reduced by the bulk discount.

displaySales displays the number sold, the total sales, and total discount.

Implement the class in Java.

Write some Java statements that test the class.

Consider a class MotorBoat that represents motorboats. A motorboat has attributes for

the capacity of the fuel tank

the amount of fuel in the tank

the maximum speed of the boat

the current speed of the boat

the efficiency of the boats motor

the distance traveled

The class has methods to

Change the speed of the boat

operate the boat for an amount of time at the current speed

refuel the boat with some amount of fuel

return the amount of fuel in the tank

return the distance traveled so far

If the boat has efficiency e, the amount of fuel used when traveling at a speed s for time t is e s2 t. The distance traveled in that time is s t.

Write a method heading for each method.

Write some Java statements that test the class.

Implement the class.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!