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 11 of 11

Thread: Area calculator.

  1. #1
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Area calculator.

    What am I missing? There is no errors in the actual script, but when I run it it just says successful and isn't asking for variables. What am I missing?

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /**
     *
     * @author Logan
     */
    import java.util.Scanner;
    public class area {
     
     
        public static void main(String[] args) 
        {
            //Declaring Variables.
            int triHeight, triBase, lengthRect, widthRect, shapeNum;
            double circRadi;
     
            Scanner reader = new Scanner (System.in);
     
            //Receiving Input
            System.out.println ("Which shape do you want area for?");
            System.out.println("1 Triangle 2 Circle 3 Rectangle 0 None");
            shapeNum = reader.nextInt ();
            if (shapeNum == 1) {
                System.out.println("Base of triangle?");
                triBase = reader.nextInt ();
                System.out.println("Height of triangle");
                triHeight = reader.nextInt ();           
             }
            if (shapeNum == 2) {
                System.out.println("Radius of circle?");
                circRadi = reader.nextDouble ();
            }
            if (shapeNum == 3) {
                System.out.println ("Length of rectangle?");
                lengthRect = reader.nextInt ();
                System.out.println("Width of rectangle?");
                widthRect = reader.nextInt ();
     
            }
     
     
     
     
        }
        public static void areaTriangle(int triBase,int triHeight, int triOutput) {
            triOutput = (triBase*triHeight)/2;
        }
     
        public static void areaCircle (double circOutput,int circRadi ) {
            circOutput = (circRadi*Math.PI);
        }
     
        public static void areaRectangle(int rectOutput, int lengthRect, int widthRect) {
            rectOutput = lengthRect*widthRect;
        }
    }


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Area calculator.

    I don't see any reason why the program itself won't ask for user inputs. There's no code for displaying the computed areas, though (only for calculating them).

    Things to try:

    1. Try saving and re-compiling your code. Perhaps you're running an older version.

    2. Make sure you're running the correct program. This should be easier to do with command-line, a little more difficult in some IDE's (if you're using one, let us know which one you're using).

    3. Are you actually running the program, or just compiling it? Reason I ask is because usually the compiler will tell you it successfully compiled the code, while running a program which does nothing will just have an empty output. If you're using the command-line, please copy/paste your commands and any outputs given.

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    26
    My Mood
    Bored
    Thanks
    6
    Thanked 5 Times in 4 Posts

    Default Re: Area calculator.

    I'm using textpad, and just copy/pasting the code it runs perfectly. It asks for variables, it didn't display anything, as helloworld pointed out, but it does ask for the variables. What are you using to compile/run?

  4. #4
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Area calculator.

    I am using NetBeans.

  5. #5
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Area calculator.

    Also, I have hit run>mainproject> and set it to area which is the program im trying to run

  6. #6
    Junior Member
    Join Date
    Sep 2012
    Posts
    26
    My Mood
    Bored
    Thanks
    6
    Thanked 5 Times in 4 Posts

    Default Re: Area calculator.

    Quote Originally Posted by LoganC View Post
    Also, I have hit run>mainproject> and set it to area which is the program im trying to run
    Unfortunately, I don't know anything about NetBeans, but the code works perfectly, no errors. The only thing is it doesn't display the numbers it computes, but it does asks for the variables and computes them, had to be an error in terms of either your computer or a glitch in the program, as the code is fine.

  7. #7
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Area calculator.

    I've only very briefly tried Netbeans a long time ago, but I think you have to manually re-compile to code before running it.

  8. #8
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Area calculator.

    The only thing I have seen is build and run.... I have built it but it didn't change the results for me.

  9. #9
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Area calculator.

    hmm... that's really odd. Can you try compiling/running the program from the command-line?

  10. #10
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Area calculator.

    Fixed, under my packages, it was named area.java and not Area.java. Thanks guys. But also, may I help some help as to what I should do to output the math that the program is computing? Im confused on where to start.
    Last edited by LoganC; September 22nd, 2012 at 05:33 PM.

  11. #11
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Area calculator.

    Quote Originally Posted by LoganC View Post
    Fixed, under my packages, it was named area.java and not Area.java. Thanks guys. But also, may I help some help as to what I should do to output the math that the program is computing? Im confused on where to start.
    If you have a new question, please start a new thread so that searching a forum is more useful. Post the related code and your instructions to make it easy to understand. Finally be sure to ask a question specifically about what problem you have. The first step in solving any problem is understanding the problem to be solved. Then you need to decide how to solve it without worrying about code. When ever you get stuck you will have a good question to ask by default.

Similar Threads

  1. [SOLVED] [Asking] Listener on Text Area
    By ardisamudra in forum AWT / Java Swing
    Replies: 7
    Last Post: September 30th, 2012, 06:01 AM
  2. Updating a text area from a JtextField! HELP
    By Java Programmer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 22nd, 2012, 08:05 PM
  3. Display in a text area
    By susieferrari in forum Java Theory & Questions
    Replies: 21
    Last Post: March 22nd, 2011, 09:56 AM
  4. Problem in implementing mortgage calculator
    By American Raptor in forum AWT / Java Swing
    Replies: 1
    Last Post: April 1st, 2009, 02:09 PM
  5. How to read character from image area(jpg image)?
    By sundarjothi in forum Java Theory & Questions
    Replies: 5
    Last Post: August 6th, 2008, 02:08 AM