Many gas pumps have displays that spin digits (either analog or digital) while the gas is being pumped into your car's gas tank. The display's digits change to indicate the amount of gas in the tank and the current price. Write a program that displays the spinning of the digits. Your GasPumpDisplay class will allow you to create a "gas pump" display with a specified number of display places and will allow you to specify the highest digit in use. You will simplify a gas pump display by using a smaller display of only three digits where the digits are in the limited range of 0-4 inclusive. public class GasPumpDisplay{ public GasPumpDisplay (int numberOfPosition){ } public String nextElement (){ } public Boolean hasMoreElements(){ } private int digits; private GasPumpDisplay tail; private int currentDigit; private static final MAX_DIGIT=4; } public class GasPumpTester{ public static void main (String[] args){ GasPumpDisplay d = new GasPumpDislay (3); } } Output: GasPumpTester prints the following permutations. 000 001 002 003 004 010 011 012 013 014 020 021 022 023 024 030 031 032 033 034 040 041 042 043 044 100 101 102 103 104 110 111 112 113 114 120 121 122 123 124 130 131 132 133 134 140 141 142 143 144 200 201 202 203 204 210 211 212 213 214 220 221 222 223 224 230 231 232 233 234 240 241 242 243 244 300 301 302 303 304 310 311 312 313 314 320 321 322 323 324 330 331 332 333 334 340 341 342 343 344 400 401 402 403 404 410 411 412 413 414 420 421 422 423 424 430 431 432 433 434 440 441 442 443 444
Added by Sergio C.
Close
Step 1
The provided code is a partial implementation of a `GasPumpDisplay` class and a `GasPumpTester` class. The `GasPumpDisplay` class is incomplete, lacking the implementation of its methods. The `GasPumpTester` class creates an instance of `GasPumpDisplay` with 3 Show more…
Show all steps
Your feedback will help us improve your experience
Akash M and 70 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Many gas pumps have displays that spin digits (either analog or digital) while the gas is being pumped into your car's gas tank. The display's digits change to indicate the amount of gas in the tank and the current price. Write a program that displays the spinning of the digits. Your GasPumpDisplay class will allow you to create a gas pump display with a specified number of display places and will allow you to specify the smaller display of only three digits where the digits are in the limited range of 0-4 inclusive. public class GasPumpDisplay { public GasPumpDisplay(int numberOfPositions) { } public String nextElement() { } public Boolean hasMoreElements() { } private int digits; private GasPumpDisplay tail; private int currentDigit; private static final int MAX_DIGIT = 4; } public class GasPumpTester { public static void main(String[] args) { GasPumpDisplay d = new GasPumpDisplay(3); } } Output: GasPumpTester prints the following permutations. 000 001 002 003 004 010 011 012 013 014 020 021 022 023 024 030 031 032 033 034 040 041 042 043 044 100 101 102 103 104 110 111 112 113 114 120 121 122 123 124 130 131 132 133 134 140 141 142 143 144 200 201 202 203 204 210 211 212 213 214 302 303 304 342 343 344 432 433 434 440 441 442 443 444
Akash M.
JAVA 7.1.3 Programming Challenge: FRQ Digits This programming challenge is based on the 2017 Free Response Question part 1a on the 2017 AP CS A exam. In this question, you are asked to write a constructor for a class called Digits. This constructor takes an integer number as its argument and divides it up into its digits and puts the digits into an ArrayList. For example, new Digits(154) creates an ArrayList with the digits [1, 5, 4]. First, let's discuss how to break up a number into its digits. Try the code below. What happens if you divide an integer by 10? Remember that in integer division, the result truncates (cuts off) everything to the right of the decimal point. Which digit can you get by using mod 10, which returns the remainder after dividing by 10? Try a different number and guess what it will print and then run to check. This is the code that is already given: public class DivideBy10 { public static void main(String[] args) { int number = 154; System.out.println(number / 10); System.out.println(number % 10); } }
Supreeta N.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD