Results 1 to 4 of 4
  1. #1
    xabre1200 is offline Member
    Join Date
    Feb 2013
    Posts
    1
    Rep Power
    0

    Default How do I output messages that are in a public static double? Please help!

    Hi everyone, I'm stuck on a simple part of my program. I'm new to Java and our class does not even have a textbook so I've been trying to find my answer online with no success. Basically we are supposed to write a program that calculates perimeter and area of a rectangle while using
    public static double computeArea (double len, double wid) public static double computePerim (double len, double wid)
    to figure out area and perimeter of our rectangle and then we are supposed to output the results as well as the length/width entered by the user to a message box. I've gotten everything done but I cannot for the life of me figure out how to output the results calculated from the public static double functions to the message dialog box. If anyone could help me out I would greatly appreciate it.

    Java Code:
    import javax.swing.JOptionPane;
    
    public class Rectangle {
    
    public static void main(String[] args)
    {
    String in,out;
    double length,width,area,perim;
    
    in = JOptionPane.showInputDialog("Enter length");
    length = Double.parseDouble(in);
    
    in = JOptionPane.showInputDialog("Enter width");
    width = Double.parseDouble(in);
    
    out = "Length: " + length + "\n";
    out =  out + "Width: " + width + "\n";
    
    JOptionPane.showMessageDialog(null, out);
    
    }
    
    public static double computeArea (double length, double width){
    JOptionPane.showConfirmDialog(null, "Hi");
    double area = length * width;
    return area;	
    }
    
    public static double computePerim (double length, double width){
    JOptionPane.showConfirmDialog(null, "Hi");
    double perim = 2 * (length + width);
    return perim;	
    }
    }

  2. #2
    lenois is offline Member
    Join Date
    Feb 2012
    Posts
    59
    Rep Power
    0

    Default Re: How do I output messages that are in a public static double? Please help!

    just to the same you did for the other doubles you are calling a method you just made it so you need to call it and assign it to a value. Suggestion though, indent your code it makes it a lot more readable.

    Java Code:
    import javax.swing.JOptionPane;
    public class Rectangle {
     
    	public static void main(String[] args)
    	{
    		String in,out;
    		double length,width,area,perim;
     
    		in = JOptionPane.showInputDialog("Enter length");
    		length = Double.parseDouble(in);
    	 
    		in = JOptionPane.showInputDialog("Enter width");
    		width = Double.parseDouble(in);
     
    		out = "Length: " + length + "\n";
    		out =  out + "Width: " + width + "\n";
     
    		JOptionPane.showMessageDialog(null, out);
     
    	}
     
    	public static double computeArea (double length, double width)
    	{
    		JOptionPane.showConfirmDialog(null, "Hi");
    		double area = length * width;
    		return area;   
    	}
     
    	public static double computePerim (double length, double width)
    	{
    		JOptionPane.showConfirmDialog(null, "Hi");
    		double perim = 2 * (length + width);
    		return perim;  
    	}
    }
    Last edited by lenois; 02-07-2013 at 05:00 PM.

  3. #3
    lenois is offline Member
    Join Date
    Feb 2012
    Posts
    59
    Rep Power
    0

    Default Re: How do I output messages that are in a public static double? Please help!

    Java Code:
    fileNames=getFileNames(fileNames);
    sample method call
    the variable of the return type=methodName(the values the method will use);

    edit:should be better, I do apologize for my semantics.
    Last edited by lenois; 02-07-2013 at 05:00 PM.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: How do I output messages that are in a public static double? Please help!

    lenois, Java doesn't have functions. They are correctly called methods.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Can't get my JTextArea output thread messages.
    By Azaera in forum New To Java
    Replies: 1
    Last Post: 12-01-2012, 10:32 PM
  2. Replies: 1
    Last Post: 12-04-2010, 06:41 PM
  3. need opinion on public static final etc ...
    By mac in forum New To Java
    Replies: 4
    Last Post: 05-20-2010, 10:54 AM
  4. Public static method error
    By leapinlizard in forum New To Java
    Replies: 5
    Last Post: 04-30-2009, 12:10 AM
  5. Replies: 5
    Last Post: 03-21-2009, 10:32 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
  •