Object Oriented Programming
Task 1
In a bookstore, customers can choose to have their books sent to their address to avoid
ca
ying them by themselves. The books will then be packed in boxes. Max 5 books per box.
Write an application for the bookstore. The application should ask the user to enter the
number of books they want to be shipped and then the program should calculate how many
oxes that are needed as well as number of books in each box. The main rule is that, if
possible, the boxes must be packed full (with the maximum number of books).
The application must then calculate the shipping fee and display the sum on the console
window. Shipping fee for an order of 1-5 boxes is 8 SEK / box. When ordering 6-50 boxes, the
shipping fee is 5 SEK / box.
It should not be possible to order less than one book. In this case, a message should be
printed asking the user to try again and it should be possible to try again without needing to
un the program again.
The application shall be robust and user friendly so that customers feel comfortable using it.
You need to write at least one method (In addition to the main method) for the calculations.
Test the application with different inputs and check if it works properly.
An example output of the application can be as follows:
How many books do you have for shipping?
-4
Not a valid number, try again.
How many books do you have for shipping?
abc
Not a valid number, try again.
How many books do you have for shipping?
8
You will receive 2 boxes, one box containing 5 books and one box containing 3 books.
The shipping price will be: 16 SEK
Task 2
Your program should prompt the user for a number of integers, calculate the minimum
number and display the result in the console window as soon as the user enters the number
0.
Here you can see an output example to such an application. It is always good to give the user
some information in the beginning of each application about how the application works,
which is missing here in this output example.
Example of output:
Write a number:
20
Write another number:
45
Write another number:
7
Write another number:
0
The minimum number that you have entered was: 7
Task 3
Write a program that calculates the remaining travel time if you know the average speed in
km / h and the remaining mileage in miles. You can assume that the average speed is the
same throughout the remaining mileage. (You can use Math.round() to round a double
value).
The result shall look like the following example:
Enter the average speed
:
120
Enter the remaining mileage :
20
Your remaining travel time is: 1 hour(s) and 40 minutes.