File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Stuck on a question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Stuck on a question" Watch "Stuck on a question" New topic
Author

Stuck on a question

Shannon Pink
Greenhorn

Joined: May 14, 2003
Posts: 6
I'm currently studying java at uni (first year). I just signed up with these forums cos I'm stuck on one of my practicle tasks. Any help would be appeciated.
In this task I have to expand on my previous task I have completed, so I will post the answer to the first task.
// File: P07Main.java
// Name: DINGO
// Description: Asks th user if they would like to construct a circle. If they enter 'y' or 'Y' then the program
//Creates a circle object from the circle class. They program also prompts the user for the circles area which is
// also obtained from the circle class. Then the program loops until the user enters anything other
//then 'y' or 'Y' when asked to construct a circle. Finally the program displays the maximum area and the average area of the circles created.
import cs1.Keyboard;
import java.text.DecimalFormat;
public class P07Main
{

public static void main (String [] args)
{
double diameter = 0.0, //the diameter if the circle
radius = 0.0,//the calculated area of the circle
maxArea = 0.0,//the max area of the circles created
averageArea = 0.0, //the average area of all circles created
area = 0.0,//the area of the circle
totalArea = 0.0;//total area of circles created

int count = 0;//the amount of circles created

charanswer;//whether or not a circle is to be created

//prompts the user and then reads whether they want to create a circle
System.out.print("Construct a circle?");
answer = Keyboard.readChar();

//loops while the user wants to create a circle
while (answer == 'y' || answer == 'Y')
{
count++; //adds 1 to the count
System.out.print("Enter the diameter>"); //prompts the user to enter diameter
diameter = Keyboard.readDouble();//reads and stores diameter
radius = diameter / 2;//calcultes radius
Circle circle;
circle = new Circle(radius); // construct new obj
area = circle.getArea( );//returns the area
totalArea += area;//calculates the total area
if (area > maxArea)//stores the largest area
maxArea = area;

DecimalFormat fmt = new DecimalFormat ("0.###"); //makes a new format object
System.out.println("Area: " + fmt.format(area) + " square metres."); //outputs formatted area
//prompts the user and then reads whether they want to create another circle
System.out.print("Construct another circle?");
answer = Keyboard.readChar();

}
//creates 2 new format objects
DecimalFormat fmt2 = new DecimalFormat ("0.###");
DecimalFormat fmt3 = new DecimalFormat ("0.###");
System.out.println("Maximum Area: " + fmt2.format(maxArea) + " square metres."); //outputs the formatted max area
System.out.println("Average Area: " + fmt3.format(totalArea/(double)count) + " square metres."); //outputs the formatted total area
}
}
public class Circle
{
private double radius; //radius

public Circle (double radius) //constructor for creating a circle
{
this.radius = radius;
}

public double getArea( ) //constructor for calculating the cirles area
{
return Math.PI* Math.pow(radius, 2);
}

public double getCartonVolume()
{
return

} // class Circle

And here is the new task I have had problems with:
Specifications
Write an application with a class P08Main that takes an order for a number of balls of different size that are all stored in separate display boxes and works out the appropriate van that can deliver the order, based on the volume of the delivery and the size of the van. Some of the balls may be larger than the smallest dimension in a van so the largest ball size must be calculated
In this practical the program will
1 for each line in the order
� prompt the user for the diameter of the balls in millimetres
� prompt the user for the number of balls of that size
� if this ball size is the largest based on carton length, store this size
� calculate the volume of this line (number * carton length) and convert it to cubic metres
� output the details of each line in the order
2 calculate the total volume of the order in cubic metres
3 select which van is suitable for the order based on the largest ball to be carried and the total volume, giving error messages if no van is big enough.
4 expand the Circle class from practical 7 to include a method getCartonVolume() that has no parameters and calculates the volume in cubic mm of the containing carton where the thickness of the carton wall is 25 millimetres
5 expand the Circle class from practical 7 to include a method getCartonLength() that has no parameters and returns the value of the carton length
The vans that can be used are:
Name
Volume (m3)
Smallest Dimension (mm)

Little Bertie
1.200
500

Mel
1.728
1200

George
26.460
2100


Step 1
Expand the Circle class from practical 7 with method getCartonVolume
1 Modify the Circle constructor to take the diameter as a parameter
2 The constructor body also sets the carton length = diameter + the thickness of the carton wall * 2 (thickness is 25mm)
3 The method getCartonVolume() returns a double representing the volume of the carton in cubic millimetres
4 the volume of the carton is calculated using the carton length (assume it is a cube)
Step 2
Pseudocode.
P08Main has the following structure:
Print "Would you like to place an order?"
while (answer is 'y' or answer is 'Y')
{ Read the diameter of the circle
Create a new Circle object
Read the number of balls of that size
Calculate the carton volume
Output the summary of the line in the order
Calculate the total volume of that line in the order
If the diameter of the carton is larger than the current largest
Replace the old largest with the new
End If
Ask "Any more balls in the order?"
} End While
If an order was placed
If the order can be delivered
Select the van to be used for delivery
Display the summary
Else
Display an appropriate error message
Else
Display an appropriate message
Output
The program produces output in exactly the format shown below. All volumes must be displayed correct to at most three decimal places.
Example 1 - carton length and volume small enough for the smallest van
Fred Bloggs. 0234567X. Friday 9. Room F1-15
*******************************************
This is my own work as defined by the
University's Academic Misconduct Policy.

Would you like to place an order? y
Enter the diameter (in mm)> 450
Enter the number of balls of this size required> 5
5 balls with a diameter of 450mm gives a volume of 0.625 cubic metres.

Any more balls in the order? y
Enter the diameter> 100
Enter the number of balls of this size required> 5
5 balls with a diameter of 100mm gives a volume of 0.017 cubic metres.

Any more balls in the order? n

Largest carton length is 500mm. Total volume is 0.642 cubic metres.
Litte Bertie is the van to use.

Example 2 - volume small enough for the smallest van but carton length too long
Would you like to place an order? y
Enter the diameter> 500
Enter the number of balls of this size required> 5
5 balls with a diameter of 500mm gives a volume of 0.832 cubic metres.

Any more balls in the order? y
Enter the diameter> 100
Enter the number of balls of this size required> 5
5 balls with a diameter of 100mm gives a volume of 0.017 cubic metres.

Any more balls in the order? n

Largest carton length is 550mm. Total volume is 0.849 cubic metres.
Mel is the van to use.

Example 3 - volume too large for one van but carton length ok for any van
Would you like to place an order? y
Enter the diameter> 300
Enter the number of balls of this size required> 1000
1000 balls with a diameter of 300mm gives a volume of 42.875 cubic metres.

Any more balls in the order? n

Largest carton length is 350mm. Total volume is 42.875 cubic metres.
No van is large enough take the order in a single trip.

Example 4 - volume ok but carton length too large for any van
Would you like to place an order? y
Enter the diameter> 2100
Enter the number of balls of this size required> 1
1 balls with a diameter of 2100mm gives a volume of 9.938 cubic metres.

Any more balls in the order? n

Largest carton length is 2150mm. Total volume is 9.938 cubic metres.
No van is large enough take the order.

Example 5 - no order placed
Fred Bloggs. 0234567X. Friday 9. Room F1-15
*******************************************
This is my own work as defined by the
University's Academic Misconduct Policy.

Would you like to place an order? n

No order placed.
jim gotti
Ranch Hand

Joined: Jul 02, 2002
Posts: 36
When posting massive code , put it in between code tags (code) (/code) where the parentesis() are actually brackets[]
what exactly are you having problems with? can you be more specific?
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
DINGO,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stuck on a question