java - issue with user defined methods executing -


Code no longer runs because I can not know how to run a scanner, but how do I get the execution of methods For? Tips and help is appreciated. thank you in advanced.

For clarification, I want to run this code as a geometry calculator, although I do not really know the method (which I think is the problem here)

  Import java.util.Scanner; Import java.lang.Math; Public class geometry {Private static zero print menu} {System.out.println ("This is a geometry calculator"); System.out.println ("Choose what you want to calculate"); System.out.println ("1. Locate a rectangular area"); System.out.println ("2. Find the circumference of a rectangle"); System.out.println ("3. Find circumference of triangle"); System.out.println ("Enter the number of your choice:"); } Public static zero main (string [] args) {int choice; // user choice double value = 0; // value returned by four letters; // Y or N by the user's decision to exit the double radius; // circle radius double length; // Rectangular width double width; // Rectangular double height width; // the height of the triangle double base; // base of triangle double side 1; // on the first side of triangle double side 2; // on the other side of triangle double side 3; // third party scanner keyboard of triangle = new scanner (System.in); } Public static double rectangle (double length, double width, double value, scanner keyboard) {System.out.print ("Enter the length of the rectangle:"); Length = keyboard.nextDouble (); System.out.print ("Enter the width of the rectangle:"); Width = keyboard.nextDouble (); Value = length * width; System.out.println ("Area of ​​a rectangle" is + value); return value; } Public static double rectangle parameter (double length, double width, double value, scanner keyboard) {System.out.print ("Enter the length of the rectangle:"); Length = keyboard.nextDouble (); System.out.print ("Enter the width of the rectangle:"); Width = keyboard.nextDouble (); Value = (2 * length) + (2 * width); System.out.println ("rectangular perimeter" + value); return value; } Public stable double triangle parameter (double side 1, double side 2, double side 3, double value, scanner keyboard) {System.out.print ("Enter the length of 1 side of triangle" :); Side1 = keyboard.nextDouble (); System.out.print ("Enter the length of 2 along the edge of the triangle:"); Side2 = keyboard.nextDouble (); System.out.print ("Enter the length of 3 on the triangle:"); Side3 = keyboard.nextDouble (); // Call the periphery method and store the result in Valuable Value = (side1 + side2 + side3); System.out.println ("circumference of triangle" + value); return value; // default: //System.out.println("You did not enter a valid option. "); }}  

I assume that you want to finish in each of your case methods . Just create a new method for each.

Example for example 2:

  Private static double rectangle parameter (scanner keyboard) {System.out.print ("Enter the length of" Rectangle: "); Double length = keyboard.nextDouble (); System.out.print ("Enter the width of the rectangle:"); Double width = keyboard.nextDouble (); Double value = (2 * length) + (2 * width); System.out.println ("rectangular perimeter" + value); return value; }  

You would like it in your case block:

  switch (option) {case 1: value = rectangleArea (keyboard); break; Case 2: Value = Rectangle parameter (keyboard); break; Case 3: value = triangle parameter (keyboard); break; }  

Then you can redo some variables outside the main, such as the length and width


Comments