Business Academy, Roskilde

Business Academy, Roskilde

/
Business Academy, Roskilde
Datamatician Course

Written Course Assignment No. 1

In the subject

Programming 1

From:25th March 2003 at 08:20 a.m.

To:26th March 2003 at 08:20 a.m.

All kind of aids is permitted

(For a further description see the Guidelines for Course Work)

This Course Assignment has the approximately weighting of

5 points of 100 points to the exam in Programming 1

It is allowed to make one overall solution treating all questions1a, 1b, 1c and 1d.

Please check that this paper consists of 4 pages including the front page.

Assignment 1 FastCar(5 point)

You are to develop a Java program for the car rental company ”FastCar” owned by Freddy Fast and Michael Fast. Of course FastCar has many different kind of business, but here we just look at their monthly rental of cars. For the sake of simplicity we shall assume that there are only 2 types of cars:

-"Standard" (monthly basis price 4.500 DKK)

-"Exclusive" (monthly basis price 5.500 DKK).

The program shall only handle registrations of a few cars, some simple calculations, various readings and print outs (e.g. bills) on the text based monitor/computer screen.

The program consists of a model class (a worker class) Car, which holds car-data and methods to carry out the calculations of prices, etc.

Further the program consists of an application class TMC_Car (alternatively name: CarApp), with the usual main method, handling the objects of the class Car, reading of user input and print outs on the screen.

Finally you are to use the Keyboard class for reading user input. The Keyboard class is uploaded on your teachers' home page.

For a start we need a simple version of the class Car:

Data fields:

String carNo (The Car No.; e.g. UB32805)

double price (The basis price per month in DKK; e.g. 4500.0)

int year (The year of registration; e.g. 2000)

Constructor:

Car, with a list of parameters so it can initialise all data-fields in the Car-class

Methods operating on the data fields:

set-methods for all data fields

get-methods for all data fields

carData returning some clarifying text and all the data fields as a String

(e.g. Car No. UB32805, price: 4500.0 DKK per month, registration year: 2000)

Turn to next page 

Question 1a Worker Class(1 point):

Create a class Car with the mentioned data fields, the constructor, the set-methods and get-methods for all data fields and the carData-method as described on the previous page.

Question 1b Application class(1 point):

Create an application class TMC_Car (alternatively CarApp) using objects of the class Car with the usual main method. In the TMC_Car class you must:

-show the declaration and construction of a variable, car1, for a "Standard" car with the data: Car No.: UB32805, price: 4500 DKK and registration year: 2002.

-show how the user can type in data on screen and show the declaration and construction of a variable for an "Exclusive" car: car2 based on these data

-show how one can change the Car No. of car1 to UX32805

-show how to print out all the car data of car1 and car2

Question 1c Car rental of several cars(1 point):

FastCar has a lot of rules for discounts on the basis price. One is the number of cars.

A discount depends on the number of cars rented as follows:

if number > 10: 15% discount 5 < number < = 10: 10% discount

1 < number < = 5: 5% discount

In TMC_Car show how one can read in the name of customer, number of cars and car type ("Standard" or "Exclusive").

Show how a monthly bill to a company customer can be calculated and printed out. The bill must state:

Customer name

Car type

Number of cars

Total price for a month

Average price for a month per car

You are welcome to do all this directly in main.

Question 1d Car rental for many months(2 point):

There are many rules for discounts on prices, when a specific car is rented for many months.

There are two types of customers: "NORMAL" and "COMPANY". For a company customer the price will always be reduced by 1000 DKK per month no matter the number of months. For a normal customer the rules for price reduction depends on the number of months as follows:

months <= 3: 0 DKK per month; i.e. no discount

3 < months < = 6: 750 DKK per month

6 < months : 975 DKK per month

In the Car class declare a new method with parameters for customer type and number of months, double calculatePrice(String customerType, int noMonths), which can handle these rules and return the real price per month.

Let us imagine that a customer wants to rent car1 a number of months.

In TMC_Car show how one can read in name of customer, customer type and the number of months.

Use calculatePrice and show how a bill can be printed out. The bill must state:

Customer name and type

Number of months

Total price for the whole period

The total price reduction

You are welcome to do this directly in main.

Side 1/4