September 04, 2010, 05:31:30 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  Home Help Media Affiliates Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Help with Geometry.java  (Read 621 times)
0 Members and 1 Guest are viewing this topic.
Java_firstgrader
Junior Member
*

Reputation: 0
Offline Offline
Posts: 3
Referrals: 0

Awards
« on: June 04, 2010, 02:48:41 AM »

Code
GeSHi (java):
  1. [/import java.util.Scanner;
  2. import static java.lang.Math.*;
  3.  
  4.  
  5. /**
  6. This program demonstrates static methods
  7. */
  8.  
  9. public class Geometry
  10. {
  11. // define the private printMenu method with no parameters and doesn't return anything
  12. public static void printMenu()
  13.    {
  14.        System.out.println ("Choose what you woud like to calculate");
  15.          System.out.println ("1. Find the are of a circle");
  16.          System.out.println ("2. Find the area of a rectangle");
  17.          System.out.println ("3. Find the area of a triangle");
  18.          System.out.println ("4. Find the circumference of a circle");
  19.          System.out.println ("5. Find the perimeter of a rectangle");
  20.          System.out.println ("6. Find the perimeter of a triangle");
  21.          System.out.println ("Enter the number of your choice: ");
  22.    }
  23.  
  24.  
  25. public static void main (String [] args)
  26. {
  27.       System.out.println("This is a geometry calculator");
  28.  
  29.  
  30. int choice; //the user's choice
  31. double value = 0; //the value returned from the method
  32. char letter; //the Y or N from the user's decision to exit
  33. double radius; //the radius of the circle
  34. double area; //the area of the circle
  35. double length; //the length of the rectangle
  36. double width; //the width of the rectangle
  37. double height; //the height of the triangle
  38. double base; //the base of the triangle
  39. double side1; //the first side of the triangle
  40. double side2; //the second side of the triangle
  41. double side3; //the third side of the triangle
  42.  
  43. //create a scanner object to read from the keyboard
  44. Scanner keyboard = new Scanner (System.in);
  45.  
  46. //do loop was chose to allow the menu to be displayed first
  47. do
  48. {
  49. //call the printMenu method
  50. printmenu();
  51.  
  52. choice = keyboard.nextInt();
  53.  
  54. switch (choice)
  55. {
  56. case 1:
  57. System.out.print("Enter the radius of the circle:  ");
  58. radius = keyboard.nextDouble();
  59. value = circleArea(radius);
  60. /**
  61. *The circleArea method calculates the
  62. *@param radius
  63. *@param area
  64. ***/
  65. //call the circleArea method and store the result in the value variable
  66. public static double CircleArea(double radius)
  67.  {
  68.   double area = 0;
  69.         area= (PI * (radius * radius)); //compute and return the circle's area
  70.  
  71.  System.out.println("The area of the circle is " + value);
  72.  }
  73.  break;
  74. case 2:
  75. System.out.print("Enter the length of the rectangle:  ");
  76. length = keyboard.nextDouble();
  77. System.out.print("Enter the width of the rectangle:  ");
  78. width = keyboard.nextDouble();
  79. //call the rectangleArea method and store the result in the value variable
  80. public static double rectangleArea(double length, double width)
  81.  {
  82.   this.length = length;
  83.   this.width = width;
  84.    }
  85.  
  86. System.out.println("The area of the rectangle is " + value);
  87. break;
  88. case 3:
  89. System.out.print("Enter the height of the triangle:  ");
  90. height = keyboard.nextDouble();
  91. System.out.print("Enter the base of the triangle:  ");
  92. base = keyboard.nextDouble();
  93. //call the triangleArea method and store the result in the value variable
  94.  
  95. System.out.println("The area of the triangle is " + value);
  96. break;
  97. case 4:
  98. System.out.print("Enter the radius of the circle:  ");
  99. radius = keyboard.nextDouble();
  100. //call the circumference method and store the result in the value variable
  101.  
  102. System.out.println("The circumference of the circle is " + value);
  103. break;
  104. case 5:
  105. System.out.print("Enter the length of the rectangle:  ");
  106. length = keyboard.nextDouble();
  107. System.out.print("Enter the width of the rectangle:  ");
  108. width = keyboard.nextDouble();
  109. //call the perimeter method and store the result in the value variable
  110.  
  111. System.out.println("The perimeter of the rectangle is " + value);
  112. break;
  113. case 6:
  114. System.out.print("Enter the length of side 1 of the triangle:  ");
  115. side1 = keyboard.nextDouble();
  116. System.out.print("Enter the length of side 2 of the triangle:  ");
  117. side2 = keyboard.nextDouble();
  118. System.out.print("Enter the length of side 3 of the triangle:  ");
  119. side3 = keyboard.nextDouble();
  120. //call the perimeter method and store the result in the value variable
  121.  
  122. System.out.println("The perimeter of the triangle is " + value);
  123. break;
  124. default:
  125. System.out.println("You did not enter a valid choice.");
  126. }
  127. keyboard.nextLine(); //consumes the new line character after the number
  128. System.out.println("Do you want to exit the program (Y/N)?:  ");
  129. String answer = keyboard.nextLine();
  130. letter = answer.charAt(0);
  131. }while (letter != 'Y' && letter != 'y');
  132. }
  133. }]
  134. --------------------Configuration: <Default>--------------------
  135. I:\CSCI 2911\CSCI 2911\CSCI TEMP\0136095089_lmsc\Lab 5\Geometry.java:66: illegal start of expression
  136. public static double CircleArea(double radius)
  137. ^
  138. I:\CSCI 2911\CSCI 2911\CSCI TEMP\0136095089_lmsc\Lab 5\Geometry.java:66: illegal start of expression
  139. public static double CircleArea(double radius)
  140.       ^
  141. I:\CSCI 2911\CSCI 2911\CSCI TEMP\0136095089_lmsc\Lab 5\Geometry.java:66: ';' expected
  142. public static double CircleArea(double radius)
  143.             ^
  144. I:\CSCI 2911\CSCI 2911\CSCI TEMP\0136095089_lmsc\Lab 5\Geometry.java:66: '.class' expected
  145. public static double CircleArea(double radius)
  146.                                       ^
  147. I:\CSCI 2911\CSCI 2911\CSCI TEMP\0136095089_lmsc\Lab 5\Geometry.java:66: ';' expected
  148. public static double CircleArea(double radius)
  149.                                             ^
  150. I:\CSCI 2911\CSCI 2911\CSCI TEMP\0136095089_lmsc\Lab 5\Geometry.java:80: illegal start of expression
  151. public static double rectangleArea(double length, double width)
  152. ^
  153. I:\CSCI 2911\CSCI 2911\CSCI TEMP\0136095089_lmsc\Lab 5\Geometry.java:80: illegal start of expression
  154. public static double rectangleArea(double length, double width)
  155.       ^
  156. I:\CSCI 2911\CSCI 2911\CSCI TEMP\0136095089_lmsc\Lab 5\Geometry.java:80: ';' expected
  157. public static double rectangleArea(double length, double width)
  158.             ^
  159. I:\CSCI 2911\CSCI 2911\CSCI TEMP\0136095089_lmsc\Lab 5\Geometry.java:80: '.class' expected
  160. public static double rectangleArea(double length, double width)
  161.                                          ^
  162. I:\CSCI 2911\CSCI 2911\CSCI TEMP\0136095089_lmsc\Lab 5\Geometry.java:80: ';' expected
  163. public static double rectangleArea(double length, double width)
  164.                                                ^
  165. I:\CSCI 2911\CSCI 2911\CSCI TEMP\0136095089_lmsc\Lab 5\Geometry.java:80: ';' expected
  166. public static double rectangleArea(double length, double width)
  167.                                                              ^
  168. 11 errors
  169.  
  170. Process completed.
  171.  
Created by GeSHI 1.0.7.20
« Last Edit: June 04, 2010, 05:19:17 AM by Java_firstgrader » Logged
Javaforums.net :: a community about Java software development.
« on: June 04, 2010, 02:48:41 AM »

Your Ad Here
 Logged
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2620
Referrals: 13

WWW Awards
« Reply #1 on: June 09, 2010, 07:48:48 PM »

Welcome to Javaforums.net!

Bit late reply but i've been a bit busy. Ive expected that other people here would have helped you out by now but anyway, move out the static methods out of your switch.
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Javaforums.net :: a community about Java software development.
   

 Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC
TinyPortal v0.9.8 © Bloc
Valid XHTML 1.0! Valid CSS!
Page created in 0.481 seconds with 33 queries.

Google visited last this page Yesterday at 12:52:23 AM