2013-02-01 16:37:49 UTC
HERE'S THE CODE THAT DOES THE CALCULATION:
import java.util.*;
import java.text.*;
/**
*
* @author oadeyemi
*/
public class CircleCarpet extends Carpet{
private int radius;
public CircleCarpet(String ID, double price2, int radius1){
super(ID, price2);
radius = radius1;
}
DecimalFormat form1 = new DecimalFormat("$##,##0.00");
public void computedTotalPrice(){
int rad2 = radius*radius;
double area = ((float)rad2)*Math.PI;
double hold = area*unitPrice;
totalPrice = hold;
}
public String toString(){
String line01 = "\nThe Carpet Shape:\tCircle\n";
String line02 = "The Radius:\t\t"+radius+"\n";
String line1 = "The CarpetId:\t\t"+carpetID+"\n";
String line2 = "The Area:\t\t"+area+"\n";
String line3 = "The Unit Price:\t\t"+form1.format(unitPrice)+"\n";
String line4 = "The Total Price:\t"+form1.format(totalPrice)+"\n\n";
return line01+line02+line1+line2+line3+line4;
}
}
HERE'S THE COMPLETE PROJECT CODE
Driver class: http://paste.ideaslabs.com/show/UE4glMCiY6
Carpet.java: http://paste.ideaslabs.com/show/9hCfEYZs2p
CarpetParser: http://paste.ideaslabs.com/show/g0AAQi1yxW
CLASSES THAT INVOLVE CALCULATION:
CircleCarpet: http://paste.ideaslabs.com/show/cNf1UjFvNj
RectangleCarpet: http://paste.ideaslabs.com/show/Cm7gOxXYk6
When the following inputs are received (when running Assignment5.java),
A
Circle/0002/2.20/20
A
Circle/0004/2.10/15
A
Rectangle/0005/3.10/30/20
L
C
L
D
0001
D
0004
Q
This is the output
Choice Action
------ ------
A Add Carpet
C Compute Total Price For Each Carpet
D Search for Carpet
L List Carpets
Q Quit
? Display Help
What action would you like to perform?
Please enter a carpet information to add:
What action would you like to perform?
Please enter a carpet information to add:
What action would you like to perform?
Please enter a carpet information to add:
What action would you like to perform?
The Carpet Shape: Circle
The Radius: 20
The CarpetId: 0002
The Area: 0
The Unit Price: $2.20
The Total Price: $0.00
The Carpet Shape: Circle
The Radius: 15
The CarpetId: 0004
The Area: 0
The Unit Price: $2.10
The Total Price: $0.00
The Carpet Shape: Rectangle
The Height: 30
The Width: 20
The CarpetId: 0005
The Area: 0
The Unit Price: $3.10
The Total Price: $0.00
What action would you like to perform?
total prices computed
What action would you like to perform?
The Carpet Shape: Circle
The Radius: 20
The CarpetId: 0002
The Area: 0 (ERROR SHOULD BE 1256)
The Unit Price: $2.20
The Total Price: $2,764.60 (ERROR SHOULD BE 2.764.60)
The Carpet Shape: Circle
The Radius: 15
The CarpetId: 0004
The Area: 0 (ERROR SHOULD BE 706)
The Unit Price: $2.10
The Total Price: $1,484.40 (ERROR: Should be 1482.60!!!)
The Carpet Shape: Rectangle
The Height: 30
The Width: 20
The CarpetId: 0005
The Area: 0 (ERROR)
The Unit Price: $3.10
The Total Price: $1,860.00
What action would you like to perform?
Please enter a carpetID to search:
carpet not found
What action would you like to perform?
Please enter a carpetID to search:
carpet found
What action would you like to perform?