You are on page 1of 3

CSCI - 105 Programming 125

Final project

Main Class
import ​java.util.Scanner​;

public class ​Main{

​public static void ​main ​(String [] args) {

GasPumpDisplay pumpCar = ​new ​GasPumpDisplay(​3​)​;

​ canner in = ​new ​Scanner(System.​in​)​; ​System.​out​.println(​"To check the next element


S
enter 7"​)​; ​System.​out​.println(​"To check if there is any more elements

enter 8"​)​;

​System.​out​.println(​"If you are done enter 9"​)​; int ​x = ​3​;

while ​(a==​3​){

​switch ​(in.nextInt()) { ​case ​7​:

System.​out​.println(pumpCar.nextElement())​;

break; case ​8​:

System.​out​.println(pumpCar.hasMoreElements())​;

break; case ​9​:

a++​; ​}

}}

Subclass

import ​java.util.Scanner​;
public class ​GasPumpDisplay {

​public ​GasPumpDisplay ​(​int ​numberOfPosition) {

Scanner in = ​new ​Scanner(System.​in)​​;

​ ystem.​out​.println(​"Enter 1 to pump gas. Keep entering 1 until you don't need more gas.
S
To terminate this sequence enter any other number."​)​;

int ​num = numberOfPosition​; int ​firstDigit=​0​;

int ​secondDigit=​0​;

int ​thirdDigit=​0​;

int ​a=​3​; do ​{

​if (​in.nextInt() == ​1​) {

System.​out.​print(thirdDigit)​;

​System.o​ut.​print(secondDigit)​;

​System.o​ut.​print(firstDigit)​;

​System.o​ut.​println()​; ​//System.out.printf("%" + num + "d%d%d%n",

thirdDigit, secondDigit, firstDigit);

​currentDigit ​= Integer.​valueOf(​String.​valueOf(​thirdDigit) +

String.​valueOf(​secondDigit) + String.​valueOf(​firstDigit))​; ​firstDigit++​;

if ​(firstDigit == ​5​) { firstDigit = ​0​;

​secondDigit++​; ​}

​if (​secondDigit == ​5​) { secondDigit = ​0​; ​thirdDigit++​;

​}

​if

(thirdDigit==​max_Digit&​&secondDigit==​max_Digit&​&firstDigit==​max_Digit​)

{
element

​public ​String ​nextElement ​() {

String currentValue = String.​valueOf​(​currentDigit​)​; return ​currentValue​;

​//change this method so that it gets nex to get next

​}

​public ​Boolean ​hasMoreElements ​() {

​}

​break; ​}

} ​else ​{a++​;​} } ​while ​(a==​3​)​;

​boolean ​moreElements​; if ​(​currentDigit​==​444​){

moreElements=​false; ​} ​else ​{

moreElements=​true; ​}

​return ​moreElements​; ​}

​private int ​digits;​

private ​GasPumpDisplay t​ail​;

private int ​currentDigit​;

private static final int ​max_Digit ​= ​4​;

​}

You might also like