• 02-21-2009, 04:49 AM
leonardjr
This was my assignment for my computer science class, underneath I wrote a program for it but I can't seem to get it to compile, can anyone help :

Write a program to allow the user to calculate the area and perimeter of a square, or the area and circumference of a circle, or the area of a triangle. To do this, the user will enter one of the following characters: S, C, or T. The program should then ask the user for the appropriate information in order to make the calculation, and should display the results of the calculation. See the example program execution shown in class. The program should use dialog boxes. When expecting an S, C, or T, the program should reject other characters with an appropriate message.Get extra points for allowing both the uppercase and lowercase versions of a valid character to work. Name the program ShapesCalc.java.

import java.util.Scanner;

public class ShapesCalc {
public static void main(String[] args) {
//Create a Scanner
Scanner input = new Scanner(System.in);

//Prompt the user to Enter S,C, or T
System.out.print("Enter S, C, or T: ");
char shape = input.nextChar();

if (shape == S);
System.out.print("Enter length of side: ");
double length = input.nextDouble();
//Calculate perimeter and area of square
perimeter= (4*length);
area=(length*length);
System.out.println("Perimeter is equal to: " + perimeter + "Area is equal to: " + area);

else if (shape == C);
//Calculate circumference and area of circle
System.out.println("Circumference is equal to: " + circumference + "Area is equal to: " + area2);}

else if (shape == T);
System.out.print("Enter length of base: ");
double base = input.nextDouble();
System.out.print("Enter height of triange: ");
double height = input.nextDouble();
//Calculate area of triangle
area3=(base*1/2*height);
System.out.println("Area is equal to: " + area3);

else
System.out.println("Incorrect variable please enter S,C, or T only");
System.exit(0);

System.out.println("Justeena Leonard");
}

}
• 04-22-2009, 08:52 PM
leonardjr
for what?????