I am in an introductory class for Java, and I am having a problem getting a small easy program to compile... can anyone point me in a direction to check.. because I am completely clueless.
I have an 'if' for every 'else' and not sure if there is something I just don't know, or if there is like a small ( or { I am missing anywhere... can anyone help out a little? Thanks.
Assignment
Code: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.
What I could create
Code:import javax.swing.JOptionPane;
public class ShapesCalc {
public static void main(String[] args) {
//Enter S,C, or T
String input = JOptionPane.showInputDialog("Enter S,C, or T");
//If Statements
//Square
if (input == 'S'){
switch(input) {
case 's':;
case 'S':; }
String length = JOptionPane.showInputDialog("Enter length of a square");
String area = length * length;
String perimeter = length * 4;
String ouput = "The area is " + area + " and the perimeter is " + perimeter;
JOptionPane.showMessageDialog(null, output);}
//Circle
else if (input == 'C'){
switch(input) {
case 'c':;
case 'C': }
String radius = JOptionPane.showInputDialog("Enter the radius of a circle");
String area = 3.14159 * radius * radius;
String circumference = 2 * 3.14159 * radius;
String output = "The area is " + area + " and the circumference is " + circumference;
JOPtionPane.showMessageDialog(null, output);}
//Triangle
else if (input == 'T'){
switch(shape) {
case 't':;
case 'T': }
String base = JOptionPane.showInputDialog("Enter the base of a triangle");
String height = JOptionPane.showInputDialog("Enter the height of a triangle");
String output = "The area is " + (base * height) / 2;
JOptionPane.showMessageDialog(null,output);}
//Error Message
else {
String error = "Incorrect variable please enter S,C, or T only.";
JOptionPane.showMessageDialog(null,error);}
}
}

