Results 1 to 6 of 6

Thread: Javac error

  1. #1
    Sotsiak is offline Member
    Join Date
    Jun 2010
    Posts
    5
    Rep Power
    0

    Default Javac error

    Hello, so this is my first post here. I am also a new programmer, learning java for some months now. Ok, let me go straight to the issue. I am writing a simple program for university and I stuck at a certain error from the compilation program (javac).

    The program I wrote is this:
    Java Code:
    import java.io.*;
    
    class vehicles{
     private String number;
     private char status;
     private int years;
    
     vehicles(String n, char s, int y){
      number=n;
      status=s;
      years=n;
     }
    
     static int [] fee_calculation(vehicles.table[]){
      int fees[]=new fees[table.length];
      for(int i=0; i<table.length; i++){
       if(status=='1')
        fees[i]=200;
       else if(status=='2')
        fees[i]=2000;
       else 
        fees[i]=1000;
      
      if(years<=5)
       fees[i]+=30;
      else if(years<=10)
       fees[i]+=60;
      else if(years<=15)
       fees[i]+=90;
      else 
       fees[i]+=120;
      }
      return fees;
     }
    
     String get_number(){
      return number;
     }
    }
    
    class vehicles_demo{
     public static void main(String args[]) throws IOException{
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    
      String n;
      char s;
      int y;
    
      System.out.println("How many vehicles you want to give for calculation: ");
      int how_many=Integer.parseInteger(br.readLine());
      System.out.println();
    
      vehicles table=new vehicles[how_many];
    
      for(int i=0; i<table.length; i++){
       System.out.println(i+" vehicle");
       System.out.println("Type the number of the vehicle: ");
       n=br.readLine();
       System.out.println("Type the status of the vehicle (1=legal, 2=illegal, 3=under investigation): ");
       s=(char) System.in.read();
       System.out.println("Type the years the vehicle is being used: ");
       y=Integer.parseInteger(br.readLine());
    
       table[i]=new vehicles(n, s, y);
      }
    
      int fees[]=new int[table.length];
      fees=vehicles.fee_calculation(table);
      
      for(int i=0; i<table.length; i++){
       System.out.println("The vehicle with the number "+table[i].get_number()+" has a fee of "+fees[i]+" euro");
       System.out.println();
      }
     }
    }
    The error I am getting from the command prompt is this:

    vehicles_demo.java:14: <identifier> expected
    static int [] fee_calculation(vehicles.table[]){
    (the pointer shows the last parenthesis)

    What the hell is going on, is it a syntax error, I can't find it. Any help appreciated.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    In the method definition statement you need a type for its parameter.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,785
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Sotsiak View Post
    The error I am getting from the command prompt is this:

    vehicles_demo.java:14: <identifier> expected
    static int [] fee_calculation(vehicles.table[]){
    (the pointer shows the last parenthesis)

    What the hell is going on, is it a syntax error, I can't find it. Any help appreciated.
    A formal parameter has a type and a name; your parameter is something else: 'vehicles.table[]'. Shouldn't that be:

    Java Code:
    static int[] fee_calculation(vehicles[] table) {
    Also note the difference in Java's way of specifying an array and the C way of doing this.

    kind regards,

    Jos

  4. #4
    Sotsiak is offline Member
    Join Date
    Jun 2010
    Posts
    5
    Rep Power
    0

    Default

    Oh, thank you very much. How stupid of me.

  5. #5
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    Since you're just starting out, let me make a couple of style points as well. A better name for your class is Vehicle -- class names should be singular nouns, and should be capitalized so that we can talk about creating a new Vehicle, or creating an array of Vehicles and know exactly what we mean. Similarly, method names should be active verbs, so calculateFees() is a better name than fee_calculation(). Underscores are legal in identifiers, but atypical (for no particular reason, C/C++ developers seem to like them more than Java developers do).

    You may find this interesting:

    Code Conventions for the Java(TM) Programming Language: Contents

    -Gary-

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,785
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by gcalvin View Post
    Underscores are legal in identifiers, but atypical (for no particular reason, C/C++ developers seem to like them more than Java developers do).
    The original C and C++ community uses lowercase all over the place; they detest CamelCase names; glueing word together like that isanunreadablemess,
    so they use_underscores_for_that while the Java community usesCamelCaseNames.

    kind regards,

    Jos

Similar Threads

  1. Javac error
    By Zorobay in forum New To Java
    Replies: 14
    Last Post: 03-03-2010, 01:00 AM
  2. error while compile code using javac
    By suri in forum New To Java
    Replies: 3
    Last Post: 01-20-2010, 10:10 AM
  3. ===javac error===
    By solt in forum New To Java
    Replies: 21
    Last Post: 12-06-2009, 10:18 AM
  4. Replies: 3
    Last Post: 08-14-2009, 01:57 PM
  5. Replies: 2
    Last Post: 07-30-2007, 09:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •