Results 1 to 9 of 9

Thread: I'm lost :(

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

    Default I'm lost :(

    These are the instructions:

    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.

    Use a while loop to allow the user to get multiple calculations of results. Ask the user to enter a Q to indicate that he or she wishes to quit.

    See the example program execution shown in class.

    Only display your name once.

    The program should use dialog boxes.

    When expecting an S, C, T, or Q 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.

    Here is what I have so far

    import javax.swing.JOptionPane;

    public class ShapesCalcLoop {
    public static void main(String[] args) {

    //Prompt the user to Enter S, C, T, or Q to quit

    char shape = JOptionPane.showInputDialog("Enter S, C, T, or Q to quit: ").charAt(0);
    switch(shape) {
    while (shape != 'Q'){
    case 's':;
    case 'S': {
    String lengthString = JOptionPane.showInputDialog("Enter length of side: ");
    double length = Double.parseDouble(lengthString);
    //Calculate perimeter and area of square
    double perimeter= ( 4 * length);
    double area=(length*length);
    String output = "Perimeter is equal to: " + perimeter + "\n" + "Area is equal to: " + area;
    JOptionPane.showMessageDialog(null,output);
    }; break;
    case 'c':;
    case 'C': {
    String radiusString = JOptionPane.showInputDialog("Enter radius: ");
    double radius = Double.parseDouble(radiusString);
    //Calculate circumference and area of circle
    double circumference= (2*3.14*radius);
    double area = (Math.PI * (radius * radius));
    String output2 ="Circumference is equal to: " + circumference + "\n" + "Area is equal to: " + area;
    JOptionPane.showMessageDialog(null,output2);
    }; break;
    case 't':;
    case 'T': {
    String baseString = JOptionPane.showInputDialog("Enter length of base: ");
    double base = Double.parseDouble(baseString);
    String heightString = JOptionPane.showInputDialog("Enter height of triange: ");
    double height = Double.parseDouble(heightString);
    //Calculate area of triangle
    double area = (base * height) / 2;
    String output3 = "Area is equal to: " + area;
    JOptionPane.showMessageDialog(null,output3);
    }; break;
    default: {
    JOptionPane.showMessageDialog(null,"Incorrect variable please enter S,C, or T only");
    System.exit(1);
    }
    };
    }
    JOptionPane.showMessageDialog(null,"This program was written by Justeena Leonard");
    }
    }

  2. #2
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    and what exactly would you like help with?

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

    Default

    I don't really understand how to do the which loop

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

    Default

    I mean the while loop

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

    Default

    I don't even know where to start

  6. #6
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    in that case, you need to organize yourself and plan how you're gonna tackle the project if you don't know where to start.

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

    Default

    I made a flow chart I know where i want to put the while loop and what i want it to do but i really don't know how to write it up

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

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

    Default

    Ok I looked at the tutorial and built this but when i run it the loop doesn't let me pick another shape it just keeps asking me to enter the numbers

    import javax.swing.JOptionPane;

    public class ShapesCalcLoop {
    public static void main(String[] args) {

    //Prompt the user to Enter S, C, T, or Q to quit

    char shape = JOptionPane.showInputDialog("Enter S, C, T, or Q to quit: ").charAt(0);
    while (shape != 'Q'){
    switch (shape){
    case 's':;
    case 'S': {
    String lengthString = JOptionPane.showInputDialog("Enter length of side: ");
    double length = Double.parseDouble(lengthString);
    //Calculate perimeter and area of square
    double perimeter= ( 4 * length);
    double area=(length*length);
    String output = "Perimeter is equal to: " + perimeter + "\n" + "Area is equal to: " + area;
    JOptionPane.showMessageDialog(null,output);
    }; break;
    case 'c':;
    case 'C': {
    String radiusString = JOptionPane.showInputDialog("Enter radius: ");
    double radius = Double.parseDouble(radiusString);
    //Calculate circumference and area of circle
    double circumference= (2*3.14*radius);
    double area = (Math.PI * (radius * radius));
    String output2 ="Circumference is equal to: " + circumference + "\n" + "Area is equal to: " + area;
    JOptionPane.showMessageDialog(null,output2);
    }; break;
    case 't':;
    case 'T': {
    String baseString = JOptionPane.showInputDialog("Enter length of base: ");
    double base = Double.parseDouble(baseString);
    String heightString = JOptionPane.showInputDialog("Enter height of triange: ");
    double height = Double.parseDouble(heightString);
    //Calculate area of triangle
    double area = (base * height) / 2;
    String output3 = "Area is equal to: " + area;
    JOptionPane.showMessageDialog(null,output3);
    }; break;
    default: {
    JOptionPane.showMessageDialog(null,"Incorrect variable please enter S,C, or T only");
    System.exit(1);

    };


    JOptionPane.showMessageDialog(null,"This program was written by Justeena Leonard");
    }
    }

    }
    }

Similar Threads

  1. So Lost
    By kandt in forum New To Java
    Replies: 5
    Last Post: 12-13-2008, 09:55 PM
  2. need help with program im lost
    By lifeturn in forum JCreator
    Replies: 1
    Last Post: 10-28-2008, 07:09 PM
  3. Lost my javadocs
    By orchid in forum Eclipse
    Replies: 3
    Last Post: 04-30-2008, 09:45 PM
  4. Absolutely Lost
    By Lehane_9 in forum New To Java
    Replies: 2
    Last Post: 12-03-2007, 06:25 PM
  5. Help Needed - I'm so lost
    By adlb1300 in forum New To Java
    Replies: 3
    Last Post: 11-14-2007, 01:54 AM

Posting Permissions

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