Assignment 3: Do you want a car wash with that?

Reading & Hints/Suggestions

Chapter 4 (pages 177 - 232) in Java Programming: From Problem Analysis to Program Design, 3rd Edition, by D. S. Malik, Thomson Course Technology, 2008.  If you wish to read ahead for next week's class you should read Chapter 5 (pages 237 - 311).

char Data Type: There are times in this assignment where you may wish to use the data type ‘char’.  It is possible to do the assignment without it, but easier if you make use of it.  We have not discussed this data type in class. That was intentional.  I would like YOU to try and work it out by reading up on it in your textbook or from an online resource.

Identifiers:  Be sure to choose identifiers such as variable names wisely! Don’t be afraid to have identifiers with two or even three words in them (although shorter tends to be better).  The important thing is that your code should be easy to follow.

Hard-Coding Values: Earlier on in your testing, you may get tired of having to type in the “user” choices (e.g. pay by cash, entering credit card number, type of gas, etc).  Initially, you may want to hard code those values.  For example:

int gasType;

// System.out.println("What type of gas, etc, etc?");

// gasType = console.nextInt()  --> commented out so that I can temporarily hard-code

// Later, I will uncomment this line

gasType = 1;  //I have hard coded the choice for gas type.  Will remove this line later on


The goal of this assignment is to practice your understanding of the following concepts: algorithmic thinking, problem solving, writing a JEnglish version of your solution, gathering input from the user, use of conditional statements, use of the Java API, and the use of the Math class. 

This assignment has two parts.  All parts must be completed for full credit.  This is an individual assignment.

Part 1: Do you want a car wash with that?

You have been hired by the development group at Benzina International, a company manufacturing the machines you interact with when pumping gas as a self-serve gas station.  The team you work with is in charge of designing and implementing a Java program that drives the dialog with the user.  A different team will use your program and build the touch screen interface, so for now all your communication with the user will be text based and on the terminal/console window.  Here are the details of the dialogue your program needs to handle:

  1. (5 points) Display a welcome message: "Good morning.  Welcome to yourCuteCompanyName (where you should choose the cute company name that will be displayed).  Please choose a payment method:
    1. Cash pay inside
    2. Credit/Debit card"
  2. (10 points) The next step will depend on the user selection.  If the user chooses the second option, tell the user to enter his/her credit card number.  Note that you would normally ask the user to swipe the card, but that part will be done by the machine once this is implemented.  For now we are just simulating this action by having the user enter the number.  If the user chooses the first option, do nothing.  Later, when the program is fully implemented, the machine will not work until the credit card is authorized through the station network.
  3. (5 points) The next step will deal with the car wash selection.  You should ask the user: "Do you want a car wash?"  Make sure you clearly indicate to the user how to respond.  We have not covered String methods so you might want to still use integers or single characters for user selection.  Alternatively, you can look up the String class in the API and check how to compare two Strings.
  4. (10 points) If the user chooses to purchase a car wash you need to present him/her with a choice of three possible car washes.  Include the car wash price in your menu.  For example (feel free to choose your own names and prices):
    1. Basic ($6.00)
    2. Premium ($8.00)
    3. Salt Buster Special ($10.00)
  5. (10 points) If the user wants a car wash, you need to generate a random 4-digit code for the car wash receipt.  If the user wants a car wash, you should do that at this point.  Note: If you want a 4-digit random integer, what should your boundaries be for the formula involving the Math.random() method?
  6. (10 points) At this point you will display the message: "Remove nozzle, select gas grade, and start pumping."  You need to display three types of gas and their prices.  For example (feel free to choose your own names and prices):
    1. Basic ($1.75)
    2. Premium ($2.05)
    3. Super ($2.25)
  7. (5 points) Make sure you capture the user's selection since you will need it in Step 11 to calculate the final price for the transaction.
  8. (5 points) Normally the machine will know when the user is done pumping gas, so we will skip that part and imagine that it only takes a second.  Since there will be no way to check how many gallons of gas they put in, you will simulate this by randomly generating the number of gallons used.  This number should be between 5 and 15.
  9. (5 points) Display the following message: "Do you want a receipt?"  Note that you should again tell the user how to answer.  See the comments in Step 3 above.
  10. (5 points) If a receipt was not requested, simply display a good-bye message.
  11. (15 points) Otherwise display in the console window the following information: the credit card number that was entered (if applicable), the type of car wash selected (if applicable), the car wash code (if applicable), and the total price for the transaction.  The total price for the transaction is the price of the selected car wash (if applicable) plus the price of gas.  The price of gas is the number of gallons generated in Step 8 times the price of the selected grade of gas.

How to proceed

  1. Make sure that you read the instructions in their entirety and fully understand the problem. 
  2. Create a folder called YourLastName_H3 where YourLastName is your last name.  This folder will contain all files you need for this assignment.  You will zip it and submit.
  3. (10 points) In a Word or text file, write up the JEnglish version of your solution.  Make sure you include all the small steps you plan to implement.  Also include your name, homework number, and class information.
  4. Open BlueJ and create a new project (Click on Project → New Project).  Make sure the project is located in the YourLastName_H3 folder you just created.  Call the project myH3.  This step will create a folder called myH3 inside the folder YourLastName_H3.
  5. Ignore the README.txt file that BlueJ automatically puts in for you and click on NewClass.  This will create a new class which you should call GetGas.
  6. Open the GetGas class and add a description of the class in the comment section, including your name, date, homework number, and class information.
  7. Delete everything after the comment section and set up the class structure with the main method.  The entire dialogue will be coded in the main method.  Use the third lab as a guide.

Part 2: How was it?

(5 points) In the folder YourLastName_H3 create a short ReadMe Word or text file (ReadMe.doc or ReadMe.txt) containing the following information:

  1. Your full name
  2. Class, section, and homework number
  3. A couple of paragraphs describing the main difficulties encountered when completing this assignment as well as the aspect that was the most fun.

Submitting the assignment

You must submit the assignment using the online homework submission system on the COL site.  Create a .zip file with the necessary documents from each part of the assignment and upload this file to the COL site.  The .zip file should be called where yourLastName is your last name and should contain the following items:

  1. The Word or text file JEnglish/pseudocode version of your solution
  2. The folder myH3 containing your BlueJ project with the code
  3. The ReadMe file with your reflection on the assignment


The assignment is worth 100 points.  The points for each required item are indicated above.