Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: I am not sure what else do I need to complete it

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    25
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default I am not sure what else do I need to complete it

    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
     
    /**
     * The Geometry DEMO
     * 
     * @author Luis Fierro
     * @version 4/1/2014
     */
    public class GeometryCalculatorDemo extends JFrame
    {
        private JPanel panel;             //a holding panel
        private JLabel messageLabel;      // a message to the user
        private JLabel textLabel1;        //show what radius, length or base depending on user choice
        private JLabel textLabel2;        //shows width or height depending on user choice
        private JTextField measurement1Text;
        private JTextField measurement2Text;
        private JRadioButton circButton;
        private JRadioButton rectButton;
        private JRadioButton triButton;
        private JRadioButton endButton;
        private ButtonGroup radioButtonGroup;    
        private final int WINDOW_WIDTH = 400;
        private final int WINDOW_HEIGHT = 100;
     
     
        /**
         * Constructor for objects of class GeometryCalculator
         */
        public static void main (String []args)
        {
            // initialise instance variables
            char again; //do I run again
            int choice; //find out what to calculate
     
            do
            {
                switch( e.getSource())
                {
                    case circButton:
                            textLabel1.setText("Enter the radius");
                            circle();
                            break;
                    case rectButton:  rectangle();
                            break;
                    case triButton:   triangle();
                            break;
                    case endButton: JOptionPane.showMessageDialog(null, "Bye-bye!!");
                            break;
                }
            } while (choice !=4);
     
        }
     
        /**
         * 
         */
        public void getMenuChoice()
        {
            //set the title
            setTitle ("Geometry Calculator");
            //set the size of the window
            setSize (WINDOW_WIDTH, WINDOW_HEIGHT);
            //actions for the close button
            setDefaultCloseOperation(JFrane.EXIT_ON_CLOSE);
            //build a pane
            buildPane();
            //add the pane to the frame
            add(panel);
            //show window
            setVisible(true);
        }
        private void buildPane()
        {
            messageLabel=new JLabel("Select a shape to calculate the area: ");
            textLabel1=new JLabel("");
            textLabel2=new JLabel("");
            measurement1Text= new JTextField(4);
            measurement2Text= new JTextField(4);
            circButton=new JRadioButton("Circle");
            rectButton=new JRadioButton("Rectangle");
            triButton=new JRadioButton("Triangle");
            endButton=new JRadioButton("End Program");
     
            //group the buttons
           radioButtonGroup= new ButtonGroup();
           radioButtonGroup.add(circButton);
           radioButtonGroup.add(rectButton);
           radioButtonGroup.add(triButton);       
           radioButtonGroup.add(endtButton);
     
     
        }    
     
        public static void circle()
        {
                double rad;
                String input;
     
              input = measurement1Text.getText;
              rad = Double.parseDouble(input);
              JOptionPane.showMessageDialog(null, Geometry.circArea(rad));               
        }
     
        public static void rectangle()
        {
                 double len;
                 double wid;
                 String input;
                 String input2;
     
               input = measurement1Text.getText;
               leng = Double.parseDouble(input);
               input2 = measurement2Text.getText;
               wid = Double.parseDouble(input2);
               JOptionPane.showMessageDialog(null, Geometry.rectArea(len,wid));
     
        }
     
        public static void triangle()
        {
                 double base;
                 double heig;
                 String input;
                 String input2;
     
               input =  measurement1Text.getText;
               base = Double.parseDouble(input);
               input2 = measurement2Text.getText;
               heig = Double.parseDouble(input2);
               JOptionPane.showMessageDialog(null, Geometry.triArea(base, heig));
     
        }
     
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: I am not sure what else do I need to complete it

    We aren't either. What's your question?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Mar 2014
    Posts
    25
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default Re: I am not sure what else do I need to complete it

    I'm supposed to write a code where the class has static methods: to accept radius and calculate area, accept length and with to calculate a rectangle's area, and accept base and height for a triangle's area. It should display error if there are negatives values

    Then I need to write a program to test the class, displaying the following menu:
    Geometry Calculator

    1. Calculate the area of a circle
    2. Calculate the area of a rectangle
    3. Calculate the area of a triangle
    4. Quit

    Enter your choice (1-4): Display error if numbers out of 1-4 range

    I was thinking that my class should be close to this: but still I don't know how to state the calculations because it says <identifier> expected
    public class GeometryCalculator
     { 
     
     
        public static double circArea
                (double r);
        {
     
            {
                return Math.PI*r*r;
     
            }
        }   
     
        public static double rectArea
                (double len, wid);
        {
     
            {
                return l*w;
            }               
        }
     
        public static double triArea
                (double base,heig);
        {
     
            {
                return h*b*0.5;
            }
     
        }
      }

    Also in my first code says error where e.getSource saying that is wasn't declared

    --- Update ---

    Never mind I figured it out everything, still thanks!!

  4. #4
    Member
    Join Date
    Apr 2012
    Posts
    161
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Default Re: I am not sure what else do I need to complete it

    When you declare a method each parameter must be given a type. There are some instances where you did not specify a type like
    public static double triArea
               (double base,heig);
    {
        {
              return h*b*0.5;
        }
    }

    As I said earlier, both parameters must have types
    public static double triArea(double base, double heig)

    Also, you are using different variable names throughout the methods
    If you define the variable base, and heig, your program does not know what h or b are. You have to use consistent names.

  5. The Following User Says Thank You to Parranoia For This Useful Post:

    Gerock7 (April 22nd, 2014)

  6. #5
    Junior Member
    Join Date
    Mar 2014
    Posts
    25
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default Re: I am not sure what else do I need to complete it

    I wasn't completely focused in the code thanks, I saw what I had wrong

Similar Threads

  1. Complete Newbie needs help Please!
    By kungfuthug in forum Java IDEs
    Replies: 0
    Last Post: February 27th, 2013, 10:49 PM
  2. Complete java
    By abhaygautam in forum Java Theory & Questions
    Replies: 2
    Last Post: February 24th, 2013, 02:22 PM
  3. [SOLVED] Code Complete?
    By remedys in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 15th, 2013, 07:15 AM
  4. my assignment..not able to complete it...please help...
    By d4divya2005 in forum What's Wrong With My Code?
    Replies: 13
    Last Post: December 7th, 2012, 11:39 AM
  5. How to complete code
    By Shay in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 5th, 2010, 01:59 PM

Tags for this Thread