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
- import java.util.*;
- public class areaCalculation3
- {
- // Set-up data input
- Scanner data_input = new Scanner(System.in);
- public static double valid_data(String input_message)
- {
- Scanner data_input = new Scanner(System.in);
- boolean valid_data = false;
- double data = 0;
- do
- {
- System.out.print(input_message);
- try
- {
- data = data_input.nextDouble();
- valid_data = true;
- }
- catch (InputMismatchException e)
- {
- // Remove invalid data
- data_input.next();
- // Output error message
- System.out.println("Invalid input, please enter a valid number.");
- }
- } while (! valid_data);
- return data;
- }
- //method for the area of the square
- public static void area_of_square(String area);
- // Declare variables
- double Length, Number_of_squares, Increment, Area, value_of_increment, i;
- String area;
- for (i=0;i< Number_of_squares; i++)
- {
- Area = Length * Length;
- System.out.printf("%nLength of square: %f", Length);
- System.out.printf(", Area of square: %f", Area);
- Length = Length + Increment;
- }
- {
- Scanner data_input = new Scanner(System.in);
- // Declare variables
- double Length, Number_of_squares, Increment, Area, i;
- string area;
- Length = valid_data("Please enter the length: ");
- Number_of_squares = valid_data("Please enter the number of triangles");
- Increment = valid_data("Please enter the increment: ");
- for (i=0;i<Number_of_squares;i++)
- {
- Area = Length * Length;
- System.out.printf("%nLength of square: %f", Length);
- System.out.printf(", Area of square: %f", Area);
- Length = Length + Increment;
- }
- }
- //Rectangle area method
- public static void area_of_rectangle(String [] args)
- {
- // Set-up data input
- Scanner data_input = new Scanner(System.in);
- // Declare variables
- double Length, Width, Number_of_rectangles, Increment, Area, i;
- String area;
- Length = valid_data("Plase enter the length: ");
- Width= valid_data("Plase enter the width: ");
- Number_of_rectangles = valid_data("Please enter the number of rectangles");
- Increment = valid_data("Please enter the increment: ");
- for (i=0;i<Number_of_rectangles;i++)
- {
- Area = Length * Width;
- System.out.printf("%nLength of rectangles: %f", Length);
- System.out.printf("%nWidth of rectangles: %f", Width);
- System.out.printf(", Area of rectangles: %f", Area);
- Length = Length + Increment;
- }
- }
- //Area of Triangle method
- public static void area_of_triangle(String [] args)
- {
- // Set-up data input
- Scanner data_input = new Scanner(System.in);
- // Declare variables
- double Base, Height, Number_of_triangles, Increment, Area, i;
- String area;
- Length = valid_data("Plase enter the base: ");
- Height = valid_data("Plase enter the Height: ");
- Number_of_triangles = valid_data("Please enter the number of triangles");
- Increment = valid_data("Please enter the increment: ");
- for (i=0;i<Number_of_triangles;i++)
- {
- Area = Base/2 * Height;
- System.out.printf("%nBaseof triangle: %f", Base);
- System.out.printf(", Area of square: %f", Area);
- Base = Base + Increment;
- Height= Height+Increment;
- }
- }
- //Circle method
- public static void area_of_circle(String [] args)
- {
- // Set-up data input
- Scanner data_input = new Scanner(System.in);
- // Declare variables
- double Radius, Number_of_circles, Increment, Area, i;
- Radius = valid_data("Plase enter the radius: ");
- Number_of_circles = valid_data("Please enter the number circles");
- Increment = valid_data("Enter the increment: ");
- for (i=0;i<Number_of_circles;i++)
- {
- Area = Radius * Radius * 3.1415927;
- System.out.printf("%nRadius of Circle: %f", Radius);
- System.out.printf(", Area of square: %f", Area);
- Radius = Radius + Increment;
- }
- }
- public static void main (String [] args)
- { //Declare variables
- int user_choice;
- boolean quit = false;
- String continue_pref;
- //Menu System
- do
- {
- Scanner data_input = new Scanner(System.in);
- System.out.printf ("%n%nPlease choose one of the following:%n%n");
- System.out.println("1. Calculate The Area Of A Square");
- System.out.println("2. Calculate The Area Of A Rectangle");
- System.out.println("3. Calculate The Area Of A Triangle");
- System.out.println("4. Calculate The Area Of A Circle");
- System.out.printf("5. Quit %n%n Please make your choice: ");
- try
- {
- user_choice = data_input.nextInt();
- }
- catch (InputMismatchException e)
- {
- // Remove invalid data
- data_input.next();
- // Make data an invalid value
- user_choice = -1;
- }
- //Get choice from user
- user_choice = data_input.nextInt();
- //Linking menu to methods
- switch(user_choice)
- {
- case 1:
- area_of_square(args);
- break;
- case 2:
- area_of_rectangle(args);
- break;
- case 3:
- area_of_triangle(args);
- break;
- case 4:
- area_of_circle(args);
- break;
- case 5:
- quit = true;
- break;
- default:
- System.out.printf(" %n Typing error. %n Please Enter A Number Between 1 - 5.");
- }
- if (quit= true)
- {
- System.out.printf(" %n Typing error. %n Please Enter A Number Between 1 - 5.");
- }
- } while (continue_pref.equalsIgnoreCase("N"));
- }
- }