Java Reference
In-Depth Information
Programming Projects
Visit www.myprogramminglab.com to complete select exercises online and get instant
feedback.
1. You operate several hot dog stands distributed throughout town. Define a class
named HotDogStand that has an instance variable for the hot dog stand's ID num-
ber and an instance variable for how many hot dogs the stand has sold that day.
Create a constructor that allows a user of the class to initialize both values.
Also create a method named justSold that increments by one the number of hot
dogs the stand has sold. The idea is that this method will be invoked each time the
stand sells a hot dog so that you can track the total number of hot dogs sold by the
stand. Add another method that returns the number of hot dogs sold.
Finally, add a static variable that tracks the total number of hot dogs sold by all hot
dog stands and a static method that returns the value in this variable.
Write a main method to test your class with at least three hot dog stands that each
sell a variety of hot dogs.
2. Define a class called Fraction . This class is used to represent a ratio of two inte-
gers. Include mutator methods that allow the user to set the numerator and the
denominator. Also include a method that displays the fraction on the screen as a
ratio (e.g., 5
9). This method does not need to reduce the fraction to lowest terms.
>
Include an additional method, equals , that takes as input another Fraction and
returns true if the two fractions are identical and false if they are not. This
method should treat the fractions reduced to lowest terms; that is, if one fraction
is 20
3, then the method should return true .
Embed your class in a test program that allows the user to create a fraction. Then
the program should loop repeatedly until the user decides to quit. Inside the body
of the loop, the program should allow the user to enter a target fraction into an
anonymous object and learn whether the fractions are identical.
3. In the land of Puzzlevania, Aaron, Bob, and Charlie had an argument over which
one of them was the greatest puzzler of all time. To end the argument once and
for all, they agreed on a duel to the death. Aaron was a poor shooter and only hit
his target with a probability of 1
>
60 and the other is 1
>
>
3. Bob was a bit better and hit his target with a
probability of 1
2. Charlie was an expert marksman and never missed. A hit means
a kill and the person hit drops out of the duel.
>
To compensate for the inequities in their marksmanship skills, the three decided
that they would fire in turns, starting with Aaron, followed by Bob, and then by
Charlie. The cycle would repeat until there was one man standing, and that man
would be the Greatest Puzzler of All Time.
An obvious and reasonable strategy is for each man to shoot at the most accurate
shooter still alive, on the grounds that this shooter is the deadliest and has the best
chance of hitting back.
 
Search WWH ::




Custom Search