Need a java program that calculates area of shapes using this code: http://paste
ID: 673820 • Letter: N
Question
Need a java program that calculates area of shapes using this code: http://pastebin.com/2jPWpXq0
--
Sample Output
Enter a list of shapes - 'done' to end
Enter the shape's color (or 'done')...
red
Enter shape type...
circle
Enter the radius...
5.0
Enter the shape's color (or 'done')...
green
Enter shape type...
rectangle
Enter the length and width...
2.0 4.0
Enter the shape's color (or 'done')...
blue
Enter shape type...
square
Enter the length of a side...
3.0
Enter the shape's color (or 'done')...
done
The list of shapes entered...
red circle with radius of 5.0 and area of 78.53975
green Rectangle with length of 2.0 and width of 4.0 and area of 8.0
blue Square with side length of 3.0 and area of 9.0
Sorting shapes into order by area...
The sorted list of shapes...
green Rectangle with length of 2.0 and width of 4.0 and area of 8.0
blue Square with side length of 3.0 and area of 9.0
red circle with radius of 5.0 and area of 78.53975
Explanation / Answer
import java.io.*;
class shape_color
{
public static void main(String args[]) throws IOException
{
DataInputStream o = new DataInputStream(System.in);
String[] shape=new String[1000];
String[] color=new String[1000];
int i=0,j;
int[] l=new int[1000];
int[] w= new int[1000];
int[] r=new int[1000];
int[] ll=new int[1000];
double[] area=new double[1000];
shape[0]="aa";
color[0]="aa";
while (!shape[i].equals("done") )
{
i++;
System.out.println("Enter shape type");
shape[i] = o.readLine();
System.out.println("Enter color");
color[i] = o.readLine();
if (shape[i].equals("circle"))
{
System.out.println("Enter the radius...");
r[i]=Integer.parseInt(o.readLine());
area[i]=3.142*r[i]*r[i];
}
else if (shape[i].equals("square"))
{
System.out.println("Enter the length of side...");
l[i]=Integer.parseInt(o.readLine());
area[i]=l[i]*l[i];
}
else if (shape[i].equals("rectangle"))
{
System.out.println("Enter the length and width...");
ll[i]=Integer.parseInt(o.readLine());
w[i]=Integer.parseInt(o.readLine());
area[i]=l[i]*w[i];
}
else
{
System.out.println("No shape");
}
}
System.out.println("The list of shapes entered...");
for(j=0;j<=i;j++)
{
if(shape[j].equals("circle"))
{
System.out.println(color[j] +" "+shape[j]+" with radius of" + r[j]+"area of" +area[j]);
}
if(shape[j].equals("square"))
{
System.out.println(color[j] +" "+shape[j]+" with side length of" + l[j]+"area of" +area[j]);
}
if(shape[j].equals("rectangle"))
{
System.out.println(color[j] +" "+shape[j]+" with length of " + l[j]+"and width of" + w[j] +"and area of" +area[j]);
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.