Results 1 to 2 of 2
Thread: [SOLVED] Please Help!!
- 02-21-2009, 03:49 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 42
- Rep Power
- 0
[SOLVED] Please Help!!
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);
System.out.print("Enter radius: ");
double radius = input.nextDouble();
//Calculate circumference and area of circle
circumference= (2*3.14*radius);
area2=(3.14*radius*radius);
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, 07:52 PM #2
Member
- Join Date
- Feb 2009
- Posts
- 42
- Rep Power
- 0


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks