Results 1 to 4 of 4
  1. #1
    tkelley1620 is offline Member
    Join Date
    May 2010
    Location
    Pittsburgh, PA
    Posts
    10
    Rep Power
    0

    Default New to this stuff.. need help..

    I am new to java and need some help..
    The program that I am to right is have a dialong box open and ask for either a Circle, Right Triangle , Rectangle and a Square.
    Then it we get input for the area of each..

    I belive that I have done that but am coming up with numerous problems. can someone please look over this and see what I might be doing wrong.

    Java Code:
    import javax.swing.JOptionPane;
    public class assingment3a {
    
    	public static void main(String[] args)
    	{
    	int type = 0;
    	String Circle;
    	String Rtangle;
    	int carea ;
    	int area = 0;
    	int radius;
    	String height = 0;
    	int rarea = 0;
    	String base1;
    	int rtriangle;
    	int square;
    	int ssquare;
    	int sbase;
    	int height1;
    	String base;
    		String type1;
    		String carea;
    		String radius;
    		String Rectangle;
    		
    		
    		
    		// prompt for name of shape
    		
    		type1 =JOptionPane.showInputDialog(null,
    				"Enter the Name of Shape:Circle, Rectangle, Rtriangle and Square", " Input Data",JOptionPane.QUESTION_MESSAGE);
    		String intString;
    		int inttype = Integer.parseInt(intString);
    		
    		
    	    if (type1 == Circle){
    	    	radius = JOptionPane.showInputDialog(null,"Enter the radius of the circle ", "Input Data", JOptionPane.QUESTION_MESSAGE);
    	    //area of a circle calculation
    	        carea = (radius * radius* PI);
    	        System.out.println("The area of a circle is " + carea);
    	    }
    	        
    	   else if (type1 == Rectangle) {
    		    base = JOptionPane.showInputDialog(null,
    		    		"Enter the base of the rectangle ", "Input Data", JOptionPane.QUESTION_MESSAGE);
    		    base = Integer.parseInt(intString);
    		    height= JOptionPane.showInputDialog(null,
    		    		"Enter the height of the rectangle", "Input Data", JOptionPane.QUESTION_MESSAGE);
    		    
    		    // area of a rectangle calculation
    		   rarea = (base * height);
    		   System.out.println("The are of a Rectangle is " + rarea);
    		   
    	   }
    	   else if (type1 == Rtriangle){
    		   base1 =JOptionPane.showInputDialog(null,
    				   "Enter the base of the the Rtriangle ", "Input Data", JOptionPane.QUESTION_MESSAGE);
    		   height1 = JOptionPane.showInputDialog(null,
    				   "Enter the height of the Rtriangle ", "Input Data", JOptionPane.QUESTION_MESSAGE);
    		   
    		   //area of a right rtriangle calculation
    		   rtarea = (base1* height1)/2;
    		   System.out.println("The area of the Right Triangle ",+ rtrea);	   
    	   }
    	   else if (type1 == Square){
    		   sbase = JOptionPane.showInputDialog(null,
    				  "Enter the base of the Square", "Input Data", JOptionPane.QUESTION_MESSAGE);
    		   // calculate area of a square
    		   ssquare = (sbase *sbase);
    		   System.out.println("The area of the Square", + ssquare);
    		   
    	   }
    	   }
    	        
    	    
    	    }

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: New to this stuff.. need help..

    What are the problems?

  3. #3
    tkelley1620 is offline Member
    Join Date
    May 2010
    Location
    Pittsburgh, PA
    Posts
    10
    Rep Power
    0

    Default Re: New to this stuff.. need help..

    eclips is saying that the * is an operator that can not be resolved.. in most of the calcualations
    mismatch string in height1

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: New to this stuff.. need help..

    eclips is saying that the * is an operator that can not be resolved
    I'm seeing "The operator * is undefined for the argument type(s) java.lang.String, java.lang.String" on the line "carea = (radius * radius* PI);" which I guess is the same thing. (It's a good idea to quote compiler messages like this exactly and say what line they refer to). In fact you have two variables radius declared. You have declared radius (the second time) as a String and the compiler is pointing out that there is no * operator for strings.

    The first thing to do is get rid of any duplicate declarations. This may well help some of the other messages to go away. As part of that think a bit about what text you choose as variables. For instance if you think that variables may be used in pairs (a string from the dialog, and a number you calculate with) then make the variables similar but easily distinguishable:

    Java Code:
    String radiusStr;
    int radius;
    Try that and post back if you get stuck. Remember that the dialogs return strings, and you do the arithmetic with numbers.

Similar Threads

  1. Images and stuff
    By Coold0wn in forum New To Java
    Replies: 82
    Last Post: 08-13-2011, 06:49 PM
  2. where the stuff goes?
    By Izabela in forum New To Java
    Replies: 16
    Last Post: 08-31-2010, 03:00 PM
  3. Replies: 6
    Last Post: 05-26-2010, 01:17 AM
  4. Simple Stuff 0.1
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 07-19-2008, 05:27 PM

Posting Permissions

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