Вы находитесь на странице: 1из 2

COMP1405 - Assignment #1

(Due: Monday, September 21st at 9:00AM)


(1) Wrapping
Write a program called BoxWrapperProgram.java that asks the user using
JOptionPane.showInputDialog() for the dimensions of a box (length, width and height) in
centimeters.
Using these dimensions, your program should then
compute the length and width of a rectangular piece
of paper that is needed to wrap the box. The paper
should not just exactly fit but should overlap by one
centimeter in the width and the height.
Display the resulting paper dimensions using JOptionPane.showMessageDialog() . Be sure to test
your code with the following different box sizes (L,W,H). Either set of answers is correct:
Length
1
10
20
10
1
0

Width
1
10
20
20
20
0

Height
1
10
20
30
30
0

Answer A

Answer B

(folds length-wise first)

(folds width-wise first)

5
41
81
81
63
1

cm
cm
cm
cm
cm
cm

x
x
x
x
x
x

4
31
61
81
81
1

cm
cm
cm
cm
cm
cm

4
31
61
71
62
1

cm
cm
cm
cm
cm
cm

x
x
x
x
x
x

5 cm
41 cm
81 cm
101 cm
101 cm
1 cm

-------------------------------------------------------------------------------------------------------------------------------------------

(2) Packing
Write a program called BallPackerProgram that asks the user for three
integers (one at a time) representing the dimensions of a box (in cm)
and a float that represents the radius of a ball (in cm). The program
should compute the number of whole balls that would fit in the box,
assuming that the balls are stacked one on top of another and aligned
nicely, as shown in the picture here. Display the results in the Java
console. Test your code with the values below:
Length
Width
Height
Ball Radius
Answer
0
1
1
1
1
1
1
2
2
2
0
1.01
2
2
2
1
1
3
3
3
2
1
4
3
3
8
1
4
4
4
1
2
4
4
4
750
2
20
40
60
125
10
100
100
100
0
0
0
0
0
-------------------------------------------------------------------------------------------------------------------------------------------

(3) Chocolate Bars


Assume that you have a corner store and need to order some chocolate bars. Write a program called
ChocolateBarsProgram that displays the following menu in the JAVA System.out console:
1.
2.
3.
4.
5.

Oh Henry
Coffee Crisp
Aero
Smarties
Crunchie

$0.65
$0.80
$0.60
$0.70
$0.75

Your program should then use a Scanner object to ask the user for the number of boxes of each type of
chocolate bar to be ordered:
How
How
How
How
How

many
many
many
many
many

boxes
boxes
boxes
boxes
boxes

of
of
of
of
of

Oh Henry bars would you like (48 bars per box) ?


Coffee Crisp bars would you like (48 bars per box) ?
Aero bars would you like (48 bars per box) ?
Smarties would you like (48 bars per box) ?
Crunchie bars would you like (48 bars per box) ?

3
2
0
4
1

Your program should then display the total cost for each type of chocolate bar and the sub total
indicating the final cost before taxes. It should also then display the HST (13%) amount followed by the
total amount due as follows:
3
2
0
4
1

boxes
boxes
boxes
boxes
boxes

of
of
of
of
of

Oh Henry
Coffee Crisp
Aero
Smarties
Crunchie

($0.65
($0.80
($0.60
($0.70
($0.75

x
x
x
x
x

48)
48)
48)
48)
48)

=
=
=
=
=

$ 93.60
$ 76.80
$ 0.00
$134.40
$ 36.00

----------------------------------------------Sub Total
= $340.80
HST
= $ 44.30
===============================================
Amount Due
= $385.10

Test your program with each the following test cases:


Oh Henry Coffee Crisp Aero
1
1
1
1
0
0
0
0
0
2
0
0
1
2
3
3
2
0
0
0
0

Smarties Crunchie
1
1
0
0
0
1
0
0
4
5
4
1
0
0

SubTotal

HST

Amount Due

$168.00
$ 31.20
$ 36.00
$ 62.40
$508.80
$340.80
$ 0.00

$ 21.84
$ 4.06
$ 4.68
$ 8.11
$ 66.14
$ 44.30
$ 0.00

$189.84
$ 35.26
$ 40.68
$ 70.51
$574.94
$385.10
$ 0.00

Your program ONLY has to work for the test cases above. Do not worry about invalid inputs.
NOTE: For each question, submit your .java file. Submit your assignment using CULearn. Note that if your internet
connection at home is down or does not work, we will not accept this as a reason for handing in an assignment late ... so
make sure to submit the assignment WELL BEFORE it is due !

Please NOTE that you WILL lose marks on this assignment if any of your files are missing. You
will also lose marks if your code is not written neatly with proper indentation. See examples in
the notes for proper style.

Вам также может понравиться