Results 1 to 6 of 6
Thread: Javac error
- 06-03-2010, 08:01 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 5
- Rep Power
- 0
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:
The error I am getting from the command prompt 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(); } } }
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.
- 06-03-2010, 08:24 PM #2
In the method definition statement you need a type for its parameter.
- 06-03-2010, 08:36 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
A formal parameter has a type and a name; your parameter is something else: 'vehicles.table[]'. Shouldn't that be:
Also note the difference in Java's way of specifying an array and the C way of doing this.Java Code:static int[] fee_calculation(vehicles[] table) {
kind regards,
Jos
- 06-03-2010, 08:48 PM #4
Member
- Join Date
- Jun 2010
- Posts
- 5
- Rep Power
- 0
Oh, thank you very much. How stupid of me.
- 06-03-2010, 10:47 PM #5
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
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-
- 06-04-2010, 08:33 AM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Javac error
By Zorobay in forum New To JavaReplies: 14Last Post: 03-03-2010, 12:00 AM -
error while compile code using javac
By suri in forum New To JavaReplies: 3Last Post: 01-20-2010, 09:10 AM -
===javac error===
By solt in forum New To JavaReplies: 21Last Post: 12-06-2009, 09:18 AM -
Error : Invalid path, \bin\javac.exe -classpath
By Ed in forum JCreatorReplies: 3Last Post: 08-14-2009, 12:57 PM -
Error :Invalid path, C:\Program Files\Java\j2re1.4.2_06\bin\javac.exe
By silvia in forum New To JavaReplies: 2Last Post: 07-30-2007, 08:55 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks