Results 1 to 2 of 2
  1. #1
    leonardjr is offline Member
    Join Date
    Feb 2009
    Posts
    42
    Rep Power
    0

    Default [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");
    }

    }

  2. #2
    leonardjr is offline Member
    Join Date
    Feb 2009
    Posts
    42
    Rep Power
    0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •