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

Thread: Method is not initiating formula

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    23
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Method is not initiating formula

    import java.util.Scanner;
     
    public class Quiz7
    {
    	public static void main(String[] args)
    	{
    		Scanner kb1 = new Scanner(System.in);
    		String programName;
    		String dueDate;
    		int radius;
    		int length;
    		int width;
    		width = 0;
    		System.out.print("What is the name of the program? ");
    		programName=kb1.nextLine();
    		System.out.print("What is the due date of the program? ");
    		dueDate=kb1.nextLine();
    		displayMyInfo(programName, dueDate);
    		int iMenuInput1 = menu();
     
     
    		menu();
     
    			switch(iMenuInput1)
    			{
    				case 1:
    						System.out.print("Enter the radius: ");
    						radius=kb1.nextInt();
    						double dAreaCircle;
    						dAreaCircle = areaCircle(radius);
    						System.out.print("The area of the circle is" +dAreaCircle);
    						break;
    				case 2:
    						System.out.print("Enter the radius: ");
    						radius=kb1.nextInt();
    						double dCircumference;
    						dCircumference = circumference(radius);
    						System.out.print("The circumference of the circle is " +dCircumference);
    						break;
    				case 3:
    						System.out.print("Enter the length: ");
    						length=kb1.nextInt();
    						System.out.print("Enter the width: ");
    						length=kb1.nextInt();
    						int iAreaRectangle;
    						iAreaRectangle = areaRectangle(length, width);
    						System.out.print("The area of the rectangle is " +iAreaRectangle);
    			}
    	}//end of main
     
    	public static void displayMyInfo(String programName, String dueDate)
    	{
    			System.out.print("The program name is" +programName);
    			System.out.print("The due date of the program is" +dueDate);
    	}//end of displayMyInfo
     
    	public static int menu()
    	{
    		Scanner kb2 = new Scanner(System.in);
    		int iMenuInput2;
    		System.out.print("* * * * * * * * M E N U * * * * * * * *");
    		System.out.print("\n\n1>   Area of a circle");
    		System.out.print("\n2>    Circumference of a circle");
    		System.out.print("\n3>    Area of a rectangle");
    		System.out.print("\n4>   Perimeter of a rectangle");
    		System.out.print("\n5>    Volume of a box");
    		System.out.print("\n6>    Volume of a cone");
    		System.out.print("Enter your choice ");
    		iMenuInput2=kb2.nextInt();
    		return iMenuInput2;
    	}//end of menu
     
    	public static double areaCircle(int radius)
    	{
     
    		final double PI = 3.1416f;
    		double dAreaCircle;
    		dAreaCircle = PI * radius * radius;
    		return dAreaCircle;
    	}//end of areaCircle
     
     
     
    	public static double circumference(int radius)
    	{
    		final double PI = 3.1416f;
    		float fCircumference;
    		fCircumference = (float)(2 * PI * radius);
    		return fCircumference;
    	}//end of circumference
     
    	public static int areaRectangle(int length, int width)
    	{
    		int iAreaRectangle;
    		iAreaRectangle = length * width;
    		return iAreaRectangle;
    	}//end of areaRectangle
     
    	public static int perimeterRectangle(int length, int width)
    	{
    		int iPerimeterRectangle;
    		iPerimeterRectangle = 2 *(length * width);
    		return iPerimeterRectangle;
    	}//end of perimeterRectangle
     
    	public static int volumeBox(int length, int width, int height)
    	{
    		int iVolumeBox;
    		iVolumeBox = length * width * height;
    		return iVolumeBox;
    	}//end of volumeBox
     
    	public static double volumeCone(int radius, int height)
    	{
    		final double PI = 3.1416f;
    		float fVolumeCone;
    		fVolumeCone = (float)(PI*radius*radius*radius*height)/3.0f;
    		return fVolumeCone;
     
    	}//end of volumeCone
     
     
    }//end of Quiz7

    The method on line 92 is not initiating the formula for option 3. Why is this?


  2. #2
    Member
    Join Date
    Mar 2011
    Posts
    66
    My Mood
    Relaxed
    Thanks
    12
    Thanked 4 Times in 4 Posts

    Default Re: Method is not initiating formula

    Well, I was testing your program and I noticed that your menu(); repeats itself before actually using your switch. For example,
    What is the name of the program? 5
    What is the due date of the program? 5
    The program name is: 5
    The due date of the program is: 5
    * * * * * * * * M E N U * * * * * * * *
     
    1>   Area of a circle
    2>    Circumference of a circle
    3>    Area of a rectangle
    4>   Perimeter of a rectangle
    5>    Volume of a box
    6>    Volume of a cone
    Enter your choice: 3
    * * * * * * * * M E N U * * * * * * * *
     
    1>   Area of a circle
    2>    Circumference of a circle
    3>    Area of a rectangle
    4>   Perimeter of a rectangle
    5>    Volume of a box
    6>    Volume of a cone
    Enter your choice: 3
    Enter the length: 4
    Enter the width: 5
    The area of the rectangle is 20

    So i just took out the menu(); that was by itself since the first one didn't do anything. Also, I think the reason why your method wasn't initiating was because
    case 3:
                    System.out.print("Enter the length: ");
    		length=kb1.nextInt();
    		System.out.print("Enter the width: ");
    		width=kb1.nextInt();                         // this was length, instead of width
    		int iAreaRectangle;
    		iAreaRectangle = areaRectangle(length, width);
    		System.out.print("The area of the rectangle is " +iAreaRectangle);

  3. The Following User Says Thank You to Actinistia For This Useful Post:

    CrimsonFlash (October 22nd, 2011)

  4. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    23
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Method is not initiating formula

    Thank you, I figured it out before you posted thankfully, but you guys are very helpful, and I appreciate it very much.

Similar Threads

  1. How do I call a method from the main method?
    By JavaStudent1988 in forum Java Theory & Questions
    Replies: 5
    Last Post: October 19th, 2011, 08:37 PM
  2. "Static method cannot hide instance method from implemented Interface"
    By Gthoma2 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 21st, 2011, 03:03 AM
  3. Can you pass parameters from one method into another method?
    By u-will-neva-no in forum Java Theory & Questions
    Replies: 2
    Last Post: April 14th, 2011, 07:46 AM
  4. Help with toString method and an addObject method?
    By Camisado in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 12th, 2011, 07:00 AM
  5. Can i call init() method in destroy method.?
    By muralidhar in forum Java Servlet
    Replies: 1
    Last Post: October 22nd, 2010, 11:18 AM