Java Programming Assignment 2

 

This assignment represents 15% of the assessment for the course.

 

In each case the program should produce an appropriate prompting message before reading data from the keyboard, and should output the answer(s) on a new line with an appropriate message.

 

  1. The front tyres of a car should both have the same pressure. Also, the rear tires of a car should both have the same pressure (but not necessarily the same pressure as the front tires.)

    Write a program Tyre1.java that reads in the pressure of the four tyres and writes a message that says if the inflation is OK or not.

 

Example:

 

Input right front pressure

38

Input left front pressure

38

Input right rear pressure

42

Input left rear pressure

42

 

Inflation is OK

 

  1. Modify the program in exercise 1 (Tyre2.java) so that it also checks that each tyre has a pressure between 35 and 45. If a tire is out of range, write out an error message immediately, but continue inputting values and processing them:

 

Example:


Input right front pressure

32

Warning: pressure is out of range

 

Input left front pressure

32

Warning: pressure is out of range

 

Input right rear pressure

42

Input left rear pressure

42

 

Inflation is BAD

 

If there have been any warnings, write out a final error message. (Hint: declare a boolean variable goodPressure that is initialized to true but is changed to false when an out of range tire is first found.)

 

 

Deadline: Please submit your answers (2 java file attachments) to me by email by 22nd November.

 

References:

 

·         Savitch Chapter 3.1 contains most of the information.

·         Otherwise, a good starting point for tutorial material is http://java.sun.com/docs/books/tutorial/java/index.html

·         Otherwise, use Google to search for “java tutorial”

 

 

 

MR

[08/11/2006]