4A

Enhance the car viewer program in Section 3.8. If you have not downloaded the source code from the companion web site - now would be a good time to do so.

Modify the Car class so that the constructor also takes a Color parameter. In the draw method, fill the body with the color (use the fill method), leaving the roof and wheels black.

Modify the CarComponent class to instantiate a blue Car at (0,0) a red car at (100, 0) and a green car at (50, 30).

cars

For the draft, simply draw the three cars. You do not need to change the color, but think about what will be involved and ask questions if you need to.

4A draft: http://cs12.cs.sjsu.edu:8080/netbrat/files?repo=ext&problem=13011211131328831428923843612
4A final: http://cs12.cs.sjsu.edu:8080/netbrat/files?repo=ext&problem=13011211131328831428923843612&level=2

4B

Write a program that displays the Olympic rings in the Olympic colors. Supply a class Ring. The Ring constructor takes x, y coordinates, a radius, and a color. It also has a draw() method that takes a Graphics2D parameter.

Your Ring class should draw rings that are 3 pixels fat. (Draw 3 skinny rings with the same center.)

rings

OlympicRingsViewer is provided for you.

For the draft, write the constructor for the Ring class. In the draw method, draw a regular circle 1 pixel wide in blue. The OlympicRingComponent is provided for the draft

For the final, draw the ring 3 pixels fat and complete the OlympicRingComponent to draw all five Rings.

4B draft: http://cs12.cs.sjsu.edu:8080/netbrat/files?repo=ext&problem=13011121398491931934940402055
4B final: http://cs12.cs.sjsu.edu:8080/netbrat/files?repo=ext&problem=13011121398491931934940402055&level=2

4C

An ice cream cone is composed of a sphere of ice cream resting in a cone. (Assume the cone-shaped "cone"). The cone and the sphere have the same diameter so half of the scoop of ice cream is inside the cone. The height of the cone is twice the diameter.

Sometimes when you get a single scoop of ice cream you only get the scoop, but some times you are lucky and the cone is filled too. So how much extra ice cream you do you get? This problem will tell you.

Make a class called IceCreamCone .This class should have the following:

Constructor:

public IceCreamCone(double diameter)
which takes the diameter of the scoop (in inches) as the construction parameter.

Methods:

public double filledVolume()
returns the volume if the bottom of the cone is filled. The volume of the whole IceCreamCone is the volume of the cone plus HALF the volume of the sphere (since half the scoop is inside the cone).
public double scoopVolume()
returns the volume of just the scoop - that's the volume of the sphere.
public double extraVolume()
returns the volume of the extra ice cream in a totally filled IceCreamCone

Provide javadoc

Use these formulas for the volume of a sphere and the volume of a cone.

Make sure to use the Java's built-in value for π.

For the draft, complete the constructor and scoopVolume(). Also make stubs for filledVolume() and extraVolume() that always return 0. Otherwise IceCreamConeTester class will not compile.

4C draft: http://cs12.cs.sjsu.edu:8080/netbrat/files?repo=ext&problem=13011117217244092434884920363
4C final: http://cs12.cs.sjsu.edu:8080/netbrat/files?repo=ext&problem=13011117217244092434884920363&level=2

Adapted from a problem by Natalie Linnel