473,395 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

illegal start of type and identifier error

I'm getting these 2 errors and haven't got a clue whats causing them please

java 43: illegal start of type
for (i=0;i< Number_of_squares; i++)

java 215 identifier expected
}


heres the whole code
Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2.  
  3. public class areaCalculation3
  4. {
  5.     // Set-up data input 
  6.  
  7.     Scanner data_input = new Scanner(System.in); 
  8.     public static double valid_data(String input_message) 
  9.     Scanner data_input = new Scanner(System.in); 
  10.     boolean valid_data = false; 
  11.     double data = 0; 
  12.  
  13.     do 
  14.     { 
  15.         System.out.print(input_message); 
  16.  
  17.         try 
  18.         { 
  19.             data = data_input.nextDouble(); 
  20.             valid_data = true; 
  21.         } 
  22.         catch (InputMismatchException e) 
  23.         { 
  24.     // Remove invalid data 
  25.     data_input.next(); 
  26.     // Output error message 
  27.     System.out.println("Invalid input, please enter a valid number."); 
  28.         } 
  29.  
  30.     } while (! valid_data); 
  31.  
  32.     return data; 
  33.     } 
  34.  
  35.     //method for the area of the square
  36.  
  37.     public static void area_of_square(String area);
  38.     // Declare variables 
  39.             double Length, Number_of_squares, Increment, Area, value_of_increment, i; 
  40.             String area;
  41.  
  42.         for (i=0;i< Number_of_squares; i++) 
  43.         { 
  44.             Area = Length * Length; 
  45.  
  46.             System.out.printf("%nLength of square: %f", Length); 
  47.             System.out.printf(", Area of square: %f", Area); 
  48.  
  49.             Length = Length + Increment; 
  50.         }
  51.             {
  52.             Scanner data_input = new Scanner(System.in); 
  53.  
  54.             // Declare variables 
  55.             double Length, Number_of_squares, Increment, Area, i; 
  56.             string area;
  57.  
  58.             Length = valid_data("Please enter the length: "); 
  59.  
  60.             Number_of_squares = valid_data("Please enter the number of triangles"); 
  61.  
  62.             Increment = valid_data("Please enter the increment: "); 
  63.  
  64.             for (i=0;i<Number_of_squares;i++) 
  65.             { 
  66.                 Area = Length * Length; 
  67.                 System.out.printf("%nLength of square: %f", Length); 
  68.                 System.out.printf(", Area of square: %f", Area); 
  69.  
  70.                 Length = Length + Increment; 
  71.             } 
  72.             }
  73.         //Rectangle area method
  74.         public static void area_of_rectangle(String [] args)
  75.         // Set-up data input 
  76.         Scanner data_input = new Scanner(System.in); 
  77.  
  78.         // Declare variables 
  79.         double Length, Width, Number_of_rectangles, Increment, Area, i; 
  80.         String area;
  81.             Length = valid_data("Plase enter the length: "); 
  82.             Width=    valid_data("Plase enter the width: "); 
  83.  
  84.             Number_of_rectangles = valid_data("Please enter the number of  rectangles"); 
  85.  
  86.             Increment = valid_data("Please enter the increment: "); 
  87.  
  88.             for (i=0;i<Number_of_rectangles;i++) 
  89.             { 
  90.                 Area = Length * Width; 
  91.  
  92.                 System.out.printf("%nLength of rectangles: %f", Length); 
  93.                 System.out.printf("%nWidth of rectangles: %f", Width);
  94.                 System.out.printf(", Area of rectangles: %f", Area); 
  95.  
  96.                 Length = Length + Increment;
  97.             } 
  98.     } 
  99.  
  100.     //Area of Triangle method
  101.     public static void area_of_triangle(String [] args) 
  102.     { 
  103.         // Set-up data input 
  104.         Scanner data_input = new Scanner(System.in); 
  105.  
  106.         // Declare variables 
  107.         double Base, Height, Number_of_triangles, Increment, Area, i; 
  108.         String area;
  109.  
  110.         Length = valid_data("Plase enter the base: "); 
  111.         Height = valid_data("Plase enter the Height: "); 
  112.         Number_of_triangles = valid_data("Please enter the number of triangles"); 
  113.  
  114.         Increment = valid_data("Please enter the increment: "); 
  115.  
  116. for (i=0;i<Number_of_triangles;i++) 
  117.     { 
  118. Area = Base/2 * Height; 
  119.  
  120. System.out.printf("%nBaseof triangle: %f", Base); 
  121. System.out.printf(", Area of square: %f", Area); 
  122.  
  123. Base = Base + Increment; 
  124. Height= Height+Increment;
  125.     } 
  126.     } 
  127.  
  128.         //Circle method
  129.         public static void area_of_circle(String [] args) 
  130.      { 
  131.          // Set-up data input 
  132.          Scanner data_input = new Scanner(System.in); 
  133.  
  134.          // Declare variables 
  135.          double Radius, Number_of_circles, Increment, Area, i; 
  136.  
  137.         Radius = valid_data("Plase enter the radius: "); 
  138.  
  139.         Number_of_circles = valid_data("Please enter the number circles"); 
  140.  
  141.         Increment = valid_data("Enter the increment: "); 
  142.  
  143.         for (i=0;i<Number_of_circles;i++) 
  144.         { 
  145.     Area = Radius * Radius * 3.1415927; 
  146.  
  147.     System.out.printf("%nRadius of Circle: %f", Radius); 
  148.     System.out.printf(", Area of square: %f", Area); 
  149.  
  150.     Radius = Radius + Increment; 
  151.         } 
  152.      } 
  153.             public static void main (String [] args)
  154. {    //Declare variables
  155.      int user_choice;
  156.     boolean quit = false;
  157.     String continue_pref;
  158.  
  159.     //Menu System
  160.     do
  161.     {
  162.         Scanner data_input = new Scanner(System.in);
  163.  
  164.         System.out.printf ("%n%nPlease choose one of the following:%n%n");
  165.             System.out.println("1.    Calculate The Area Of A Square");
  166.             System.out.println("2.    Calculate The Area Of A Rectangle");
  167.             System.out.println("3.    Calculate The Area Of A Triangle");
  168.             System.out.println("4.    Calculate The Area Of A Circle");
  169.             System.out.printf("5.     Quit %n%n Please make your choice:  ");
  170.  
  171.             try 
  172.             { 
  173.                 user_choice = data_input.nextInt(); 
  174.             } 
  175.             catch (InputMismatchException e) 
  176.             { 
  177.                 // Remove invalid data 
  178.                 data_input.next(); 
  179.                 // Make data an invalid value 
  180.                 user_choice = -1; 
  181.             } 
  182.  
  183.             //Get choice from user
  184.             user_choice = data_input.nextInt();
  185.  
  186.             //Linking menu to methods
  187.             switch(user_choice)
  188.             {
  189.             case 1:
  190.                 area_of_square(args);
  191.                 break;
  192.             case 2:
  193.                 area_of_rectangle(args);
  194.                 break;
  195.             case 3:
  196.                 area_of_triangle(args);
  197.                 break;
  198.             case 4:
  199.                 area_of_circle(args);
  200.                 break;
  201.             case 5: 
  202.                 quit = true;
  203.                 break;
  204.             default:
  205.             System.out.printf(" %n Typing error. %n Please Enter A Number Between 1 - 5.");
  206.             }
  207.     if (quit= true)
  208.     {
  209.     System.out.printf(" %n Typing error. %n Please Enter A Number Between 1 - 5.");
  210.     } 
  211.     } while (continue_pref.equalsIgnoreCase("N"));
  212. }
  213. }
  214.  
thanks in advance for any help
Mar 15 '07 #1
2 6587
horace1
1,510 Expert 1GB
you appear to have a ; on the end of
Expand|Select|Wrap|Line Numbers
  1. public static void area_of_square(String area);
  2.  
should it be?
Expand|Select|Wrap|Line Numbers
  1. public static void area_of_square(String area)
  2. {
  3.     // Declare variables 
Mar 15 '07 #2
you appear to have a ; on the end of
Expand|Select|Wrap|Line Numbers
  1. public static void area_of_square(String area);
  2.  
should it be?
Expand|Select|Wrap|Line Numbers
  1. public static void area_of_square(String area)
  2. {
  3.     // Declare variables 

Oh yes . I had missed that semi-colon also. Fter removing it, u may still get an eror about the variable "i" not having been declared. ie: variable i cannot be resolved. on the for loop try

Expand|Select|Wrap|Line Numbers
  1.  for(int i=0; i<bla bla bla){
This shd work
Mar 16 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Grumble | last post by:
Hello everybody, (Disclaimer: I do not understand C++ templates.) I've tried to make a testcase from the original code. GCC 3.3.5 compiles with no warning, while GCC 3.4.3 rejects it. Could...
2
by: Gabrielle A. Grün | last post by:
Hi All, Does anyone know a way around the illegal reference of a non-static member? Thanks. iNHERITANCE HIERACY
134
by: jacob navia | last post by:
Hi Suppose you have somewhere #define BOOL int and somewhere else typedef BOOL int;
6
by: BlueTrin | last post by:
Hello I was adapting a C version of SolvOpt in C++ to use it within a virtual class. However I am stuck with the overriding of evaluation and gradiant functions. cStepCurveEvaluator.cpp...
8
by: LuB | last post by:
Is this somehow illegal? template<typename T> class A { public: private:
1
by: Manish | last post by:
The code is as ... $folderlistfile = $path."xmlfile.xml"; /* <list> <details id="2"> <name>Books</name>
2
by: mole40 | last post by:
Hello! I'm very new to writing java. And I keep getting the "Illegal Start of Type" error. I've tried everything to fix it. can anyone help me? import java.util.*; class ClockTalk { public...
2
by: Lambda | last post by:
The code is simple: // Token.h #ifndef TOKEN_H #define TOKEN_H #include <vector> #include <string> class Token
3
by: MrHenry007 | last post by:
Hello! I'm fairly new to c++ but I have been following tutorials and have created functions before, but not one using a string. I can't work out what the problem is here. The function is supposed...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.