Question
Questions 8.2,8.4 and 8.5. In Q.P8.2 Create a variable in the Counter class called max , and add the setLimit method given in the book
Questions 8.2,8.4 and 8.5.
In Q.P8.2 Create a variable in the Counter class called max, and add the setLimit method given in the book to the class. Next, modify the count() method to check if value has reached the max - if so, updating value would exceed the limit, so print the warning message. To test your program, create a Counter object in main and set the limit to 10. Then run a for-loop 12 times. For times 11 and 12, it should print the warning message.
Q. P8.4 - Since zipcode might have a '0' as the first character, it should be a String variable. To see if one string comes before another string, you can use the compareTo method of the String class. For example, for str1 and str2, str1.compareTo(str2) is < 0 if str1 comes before str2, and it is > 0 if str2 comes before str1. So if str1="19610" and str2="19611", then str1.compareTo(str2) < 0 returns the boolean value true
P8.2 Simulate a tally counter that can be used to admit a limited number of people. First, the limit is set with a call public void setLimit(int maximum) If the count button was clicked more often than the limit, simulate an alarm by printing out a message Limit exceeded. ..P8.3 Reimplement the Menu class so that it stores all menu items in one long string. Hint: Keep a separate counter for the number of options. When a new option is added, append the option count, the option, and a newline character. P8.4 Implement a class Address. An address has a house number, a street, an optional apartment number, a city, a state, and a postal code. Supply two constructors: one with an apartment number and one without. Supply a print method that prints the address with the street on one line and the city, state, and zip code on the next line. Supply a method public boolean comesBefore(Address other) that tests whether this address comes before another when the addresses are compared by postal code. P8.5 Implement a class SodaCan with methods getSurfaceArea() and get- Volume(). In the constructor, supply the height and radius of the can. P8.6 Implement a class Car with the following properties. A car has a certain fuel efficiency (measured in miles/gallon) and a certain amount of fuel in the gas tank. The efficiency is specified in the constructor, and the initial fuel level is 0. Supply a method drive that simulates driving the P8.2 Simulate a tally counter that can be used to admit a limited number of people. First, the limit is set with a call public void setLimit(int maximum) If the count button was clicked more often than the limit, simulate an alarm by printing out a message Limit exceeded. ..P8.3 Reimplement the Menu class so that it stores all menu items in one long string. Hint: Keep a separate counter for the number of options. When a new option is added, append the option count, the option, and a newline character. P8.4 Implement a class Address. An address has a house number, a street, an optional apartment number, a city, a state, and a postal code. Supply two constructors: one with an apartment number and one without. Supply a print method that prints the address with the street on one line and the city, state, and zip code on the next line. Supply a method public boolean comesBefore(Address other) that tests whether this address comes before another when the addresses are compared by postal code. P8.5 Implement a class SodaCan with methods getSurfaceArea() and get- Volume(). In the constructor, supply the height and radius of the can. P8.6 Implement a class Car with the following properties. A car has a certain fuel efficiency (measured in miles/gallon) and a certain amount of fuel in the gas tank. The efficiency is specified in the constructor, and the initial fuel level is 0. Supply a method drive that simulates driving theStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started