Skip to main content

I need help compiling this java program, I don't know where abouts the error is coming from?

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
5 replies [Last post]
meaganicole
Offline
Joined: 2012-01-19

Hi,

I've just created this program and somehow, it won't let me compile:

import java.util.Scanner;
/* Draw a class diagram and write the Java code to represent a vehicle museum. Vehicles have a licence plate, a year of manufacture, a value, and a colour. The museum has cars, which have a number of doors, seats, engine type (petrol or diesel), and engine size in litres. The museum also has motobikes, which have a bike type (sports, tourer, or trails), and engine size in cubic centimetres (cc). */

/* Add the following features to the program in the form of a menu:

Add new vehicles (bikes or cars);
List all vehicles manufactured in a given year;
List all vehicles of 1 litre or more (1 litre = 1000cc);
List all cars;
List all bikes; */

class Car
{
private String vehicle;
private String licencePlate;
private String colour;
private String engineType;
private int yearOfManufacture;
private int doors;
private int seats;
private int engineSizeLitres;
private int engineSizeCC;
private double carValue;

Car (String v, String lP, String c, String eT, int yOM, int d, int s, int eSL, double cV)
{
vehicle = v;
licencePlate = lP;
colour = c;
engineType = eT;
yearOfManufacture = yOM;
doors = d;
seats = s;
engineSizeLitres = eSL;
carValue = cV;
}

String getVehicle()
{
return vehicle;
}

String getLicencePlate()
{
return licencePlate;
}

String getColour()
{
return colour;
}

String getEngineType()
{
return engineType;
}

int getYearOfManufacture()
{
return yearOfManufacture;
}

int getDoors()
{
return doors;
}

int getSeats()
{
return seats;
}

int getEngineSizeLitres()
{
return engineSizeLitres;
}

double getCarValue()
{
return carValue;
}
}

class Bike
{
private String vehicle;
private String licencePlate;
private String colour;
private String engineType;
private int yearOfManufacture;
private int engineSizeCC;
private double bikeValue;

Bike (String v, String lP, String c, String eT, int yOM, int eSCC, double bV)
{
vehicle = v;
licencePlate = lP;
colour = c;
engineType = eT;
yearOfManufacture = yOM;
engineSizeCC = eSCC;
bikeValue = bV;
}

String getVehicle()
{
return vehicle;
}

String getLicencePlate()
{
return licencePlate;
}

String getColour()
{
return colour;
}

String getEngineType()
{
return engineType;
}

int getYearOfManufacture()
{
return yearOfManufacture;
}

int getEngineSizeCC()
{
return engineSizeCC;
}

double getBikeValue()
{
return bikeValue;
}
}

class museumInventory
{
static final int quit = 0;

public static int getMenuOption()
{
Scanner menuOption = new Scanner(System.in);
int option;

System.out.println("1. Add new car to the list: ");
System.out.println("2. Add new bike to the list: ");
System.out.println("3. List all of the cars that are manufactured in a given year");
System.out.println("4. List all of the bikes that are manufactured in a given year");
System.out.println("5. List all of the cars that engine size are 1 litre or more (1 litre = 1000cc)");
System.out.println("6. List all of the bike that engine size in cubic centimetres");
System.out.println("7. List all of the cars");
System.out.println("8. List all of the bikes");
System.out.println("9. List the value for the cars");
System.out.println("10. List the value for the bikes");
System.out.println(quit + ". Quit");

option = menuOption.nextInt();
return option;
}

public static int addCar(Car carType[], int vehicleTotal)
{
Scanner input = new Scanner(System.in);
String car, licencePlate, colour, engineType;
int yearOfManufacture, doors, seats, engineSizeLitres;
double carValue;

System.out.print("Enter the new car: ");
car = input.next();

System.out.print("Enter the licence plate: ");
licencePlate = input.next();

System.out.print("Enter the colour: ");
colour = input.next();

System.out.print("Enter the engine type (Petrol or Diesel): ");
engineType = input.next();

System.out.print("Enter the year of manufacture: ");
yearOfManufacture = input.nextInt();

System.out.print("Enter the number of doors: ");
doors = input.nextInt();

System.out.print("Enter the number of seats: ");
seats = input.nextInt();

System.out.print("Enter the engine size in litres: ");
engineSizeLitres = input.nextInt();

System.out.print("Enter the car value: ");
carValue = input.nextDouble();

carType[vehicleTotal] = new Car(car, licencePlate, colour, engineType, yearOfManufacture, doors, seats, engineSizeLitres, carValue);

vehicleTotal++;

return vehicleTotal;
}

public static int addBike(Bike bikeType[], int vehicleTotal)
{
Scanner input = new Scanner(System.in);
String bike, licencePlate, colour, engineType;
int yearOfManufacture, engineSizeCC;
double bikeValue;

System.out.print("Enter the new bike: ");
bike = input.next();

System.out.print("Enter the licence plate: ");
licencePlate = input.next();

System.out.print("Enter the colour: ");
colour = input.next();

System.out.print("Enter the engine type (Petrol or Diesel): ");
engineType = input.next();

System.out.print("Enter the year of manufacture: ");
yearOfManufacture = input.nextInt();

System.out.print("Enter the engine size in cubic centimetres: ");
engineSizeCC = input.nextInt();

System.out.print("Enter the bike value: ");
bikeValue = input.nextDouble();

bikeType[vehicleTotal] = new Bike(bike, licencePlate, colour, engineType, yearOfManufacture, engineSizeCC, bikeValue);

vehicleTotal++;

return vehicleTotal;
}

public static void carType(Car carType[], int vehicleTotal)
{
Scanner input = new Scanner(System.in);
String typeOfCar;

System.out.print("Enter the type of car (i.e sports car): ");
typeOfCar = input.next();

for (int count = 0; count < vehicleTotal; count++)
{
if (carType[count].getVehicle() == typeOfCar)
System.out.println(carType[count].getVehicle());
}
}

public static void bikeType(Bike bikeType[], int vehicleTotal)
{
Scanner input = new Scanner(System.in);
String typeOfBike;

System.out.print("Enter the type of bike (i.e sports bike): ");
typeOfBike = input.next();

for (int count = 0; count < vehicleTotal; count++)
{
if (bikeType[count].getVehicle() == typeOfBike)
System.out.println(bikeType[count].getVehicle());
}
}

public static void listAllCarsInAGivenYear(Car carType[], int vehicleTotal)
{
Scanner input = new Scanner(System.in);
int yearOfManufacture;

System.out.print("Enter the year of manufacture of the car: ");
yearOfManufacture = input.nextInt();

for (int count = 0; count < vehicleTotal; count++)
{
if (carType[count].getYearOfManufacture() == yearOfManufacture)
System.out.println(carType[count].getVehicle());
}
}

public static void listAllBikesInAGivenYear(Bike bikeType[], int vehicleTotal)
{
Scanner input = new Scanner(System.in);
int yearOfManufacture;

System.out.print("Enter the year of manufacture for the bike: ");
yearOfManufacture = input.nextInt();

for (int count = 0; count < vehicleTotal; count++)
{
if (bikeType[count].getYearOfManufacture() == yearOfManufacture)
System.out.println(bikeType[count].getVehicle());
}
}

public static void listAllCarsOfOneLitreOrMore(Car carType[], int vehicleTotal)
{
Scanner input = new Scanner(System.in);
int engineSizeLitres;

System.out.print("Enter the engine size in litres for the car: ");
engineSizeLitres = input.nextInt();

for (int count = 0; count < vehicleTotal; count++)
{
if (carType[count].getEngineSizeLitres() == engineSizeLitres)
System.out.println(carType[count].getVehicle());
}
}

public static void listAllBikesThatEngineSizeInCubicCentimetres(Bike bikeType[], int vehicleTotal)
{
Scanner input = new Scanner(System.in);
int engineSizeCC;

System.out.print("Enter the engine size in cubic centimetres for the bike: ");
engineSizeCC = input.nextInt();

for (int count = 0; count < vehicleTotal; count++)
{
if (bikeType[count].getEngineSizeCC() == engineSizeCC)
System.out.println(bikeType[count].getVehicle());
}
}

public static void listAllCars(Car carType[], int vehicleTotal)
{
Scanner input = new Scanner(System.in);
String listAllCars;

System.out.print("List all cars");
listAllCars = input.next();

for (int count = 0; count < vehicleTotal; count++)
{
if (carType[count].getVehicle() == listAllCars)
System.out.println(carType[count].getVehicle());
}
}

public static void listAllBikes(Bike bikeType[], int vehicleTotal)
{
Scanner input = new Scanner(System.in);
String listAllBikes;

System.out.print("List all bikes");
listAllBikes = input.next();

for (int count = 0; count < vehicleTotal; count++)
{
if (bikeType[count].getVehicle() == listAllBikes)
System.out.println(bikeType[count].getVehicle());
}
}

public static void listAllValuesForTheCars(Car carType[], int vehicleTotal)
{
Scanner input = new Scanner(System.in);
double carValue;

System.out.print("Enter the car value: ");
carValue = input.nextDouble();

for (int count = 0; count < vehicleTotal; count++)
{
if (carType[count].getCarValue() == carValue)
System.out.println(carType[count].getVehicle());
}
}

public static void listAllValuesForTheBikes(Bike bikeType[], int vehicleTotal)
{
Scanner input = new Scanner(System.in);
double bikeValue;

System.out.print("Enter the bike value: ");
bikeValue = input.nextDouble();

for (int count = 0; count < vehicleTotal; count++)
{
if (bikeType[count].getBikeValue() == bikeValue)
System.out.println(bikeType[count].getVehicle());
}
}

class museum
{
public static void main(String[] args)
{
Car carType[] = new Car[100];
Bike bikeType[] = new Bike[100];
int vehicleTotal = 0;
int option;

option = getMenuOption();

while (option != quit)
{
if (option == 1)
{
vehicleTotal = addCar(carType, vehicleTotal);
}
else if (option == 2)
{
vehicleTotal = addBike(bikeType, vehicleTotal);
}
else if (option == 3)
{
listAllCarsInAGivenYear(carType, vehicleTotal);
}
else if (option == 4)
{
listAllBikesInAGivenYear(bikeType, vehicleTotal);
}
else if (option == 5)
{
listAllCarsOfOneLitreOrMore(carType, vehicleTotal);
}
else if (option == 6)
{
listAllBikesThatEngineSizeInCubicCentimetres(bikeType, vehicleTotal);
}
else if (option == 7)
{
listAllCars(carType, vehicleTotal);
}
else if (option == 8)
{
listAllBikes(bikeType, vehicleTotal);
}
else if (option == 9)
{
listAllValuesForTheCars(carType, vehicleTotal);
}
else if (option == 10)
{
listAllValuesForTheBikes(bikeType, vehicleTotal);
}
else System.out.println("Invalid input, please try again");

option = getMenuOption();
}
}
}

This is the error that I'm getting:

museum.java:450: error: reached end of file while parsing
}
^
1 error

Please can anyone help me?

Thanks

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
phynx
Offline
Joined: 2012-01-21

your "class museum" appears to be missing its closing brace..

adding it will bring up another error though

rao_555
Offline
Joined: 2012-01-20

It is the problem with missing curly brace. check if all the curly braces you opened are closed properly.

meaganicole
Offline
Joined: 2012-01-19

I've already checked several times with the missing curly brace, there doesn't seem to have any curly braces missing

Yogendratomar
Offline
Joined: 2012-03-18

Add one brace } at the end of class

museum

and make

museum class static.

the correct version is

import

java.util.Scanner;

/* Draw a class diagram and write the Java code to represent a vehicle museum. Vehicles have a licence plate, a year of manufacture, a value, and a colour. The museum has cars, which have a number of doors, seats, engine type (petrol or diesel), and engine size in litres. The museum also has motobikes, which have a bike type (sports, tourer, or trails), and engine size in cubic centimetres (cc). */

/* Add the following features to the program in the form of a menu:

Add new vehicles (bikes or cars);

List all vehicles manufactured in a given year;

List all vehicles of 1 litre or more (1 litre = 1000cc);

List all cars;

List all bikes; */

class

Car(String v, String lP, String c, String eT,

}

String getVehicle() {

}

String getLicencePlate() {

}

String getColour() {

}

String getEngineType() {

}

}

}

}

}

}

}

Car {private String vehicle;private String licencePlate;private String colour;private String engineType;private int yearOfManufacture;private int doors;private int seats;private int engineSizeLitres;private int engineSizeCC;private double carValue;int yOM, int d, int s,int eSL, double cV) {vehicle = v;licencePlate = lP;colour = c;engineType = eT;yearOfManufacture = yOM;doors = d;seats = s;engineSizeLitres = eSL;carValue = cV;return vehicle;return licencePlate;return colour;return engineType;int getYearOfManufacture() {return yearOfManufacture;int getDoors() {return doors;int getSeats() {return seats;int getEngineSizeLitres() {return engineSizeLitres;double getCarValue() {return carValue;

class

Bike(String v, String lP, String c, String eT,

}

String getVehicle() {

}

String getLicencePlate() {

}

String getColour() {

}

String getEngineType() {

}

}

}

}

}

Bike {private String vehicle;private String licencePlate;private String colour;private String engineType;private int yearOfManufacture;private int engineSizeCC;private double bikeValue;int yOM, int eSCC, double bV) {vehicle = v;licencePlate = lP;colour = c;engineType = eT;yearOfManufacture = yOM;engineSizeCC = eSCC;bikeValue = bV;return vehicle;return licencePlate;return colour;return engineType;int getYearOfManufacture() {return yearOfManufacture;int getEngineSizeCC() {return engineSizeCC;double getBikeValue() {return bikeValue;

class

Scanner menuOption =

System.

System.

System.

museumInventory {static final int quit = 0;public static int getMenuOption() {new Scanner(System.in);int option;out.println("1. Add new car to the list: ");out.println("2. Add new bike to the list: ");out

.println(

System.

"3. List all of the cars that are manufactured in a given year");out

.println(

System.

"4. List all of the bikes that are manufactured in a given year");out

.println(

System.

"5. List all of the cars that engine size are 1 litre or more (1 litre = 1000cc)");out

.println(

System.

System.

System.

System.

System.

option = menuOption.nextInt();

}

Scanner input =

String car, licencePlate, colour, engineType;

System.

car = input.next();

System.

licencePlate = input.next();

System.

colour = input.next();

System.

engineType = input.next();

System.

yearOfManufacture = input.nextInt();

System.

doors = input.nextInt();

System.

seats = input.nextInt();

System.

engineSizeLitres = input.nextInt();

System.

carValue = input.nextDouble();

carType[vehicleTotal] =

yearOfManufacture, doors, seats, engineSizeLitres, carValue);

vehicleTotal++;

}

Scanner input =

String bike, licencePlate, colour, engineType;

System.

bike = input.next();

System.

licencePlate = input.next();

System.

colour = input.next();

System.

engineType = input.next();

System.

yearOfManufacture = input.nextInt();

System.

engineSizeCC = input.nextInt();

System.

bikeValue = input.nextDouble();

bikeType[vehicleTotal] =

engineType, yearOfManufacture, engineSizeCC, bikeValue);

vehicleTotal++;

}

Scanner input =

String typeOfCar;

System.

typeOfCar = input.next();

System.

}

}

Scanner input =

String typeOfBike;

System.

typeOfBike = input.next();

System.

}

}

Scanner input =

System.

yearOfManufacture = input.nextInt();

System.

}

}

Scanner input =

System.

yearOfManufacture = input.nextInt();

System.

}

}

Scanner input =

System.

engineSizeLitres = input.nextInt();

System.

}

}

Bike bikeType[],

Scanner input =

System.

"6. List all of the bike that engine size in cubic centimetres");out.println("7. List all of the cars");out.println("8. List all of the bikes");out.println("9. List the value for the cars");out.println("10. List the value for the bikes");out.println(quit + ". Quit");return option;public static int addCar(Car carType[], int vehicleTotal) {new Scanner(System.in);int yearOfManufacture, doors, seats, engineSizeLitres;double carValue;out.print("Enter the new car: ");out.print("Enter the licence plate: ");out.print("Enter the colour: ");out.print("Enter the engine type (Petrol or Diesel): ");out.print("Enter the year of manufacture: ");out.print("Enter the number of doors: ");out.print("Enter the number of seats: ");out.print("Enter the engine size in litres: ");out.print("Enter the car value: ");new Car(car, licencePlate, colour, engineType,return vehicleTotal;public static int addBike(Bike bikeType[], int vehicleTotal) {new Scanner(System.in);int yearOfManufacture, engineSizeCC;double bikeValue;out.print("Enter the new bike: ");out.print("Enter the licence plate: ");out.print("Enter the colour: ");out.print("Enter the engine type (Petrol or Diesel): ");out.print("Enter the year of manufacture: ");out.print("Enter the engine size in cubic centimetres: ");out.print("Enter the bike value: ");new Bike(bike, licencePlate, colour,return vehicleTotal;public static void carType(Car carType[], int vehicleTotal) {new Scanner(System.in);out.print("Enter the type of car (i.e sports car): ");for (int count = 0; count < vehicleTotal; count++) {if (carType[count].getVehicle() == typeOfCar)out.println(carType[count].getVehicle());public static void bikeType(Bike bikeType[], int vehicleTotal) {new Scanner(System.in);out.print("Enter the type of bike (i.e sports bike): ");for (int count = 0; count < vehicleTotal; count++) {if (bikeType[count].getVehicle() == typeOfBike)out.println(bikeType[count].getVehicle());public static void listAllCarsInAGivenYear(Car carType[], int vehicleTotal) {new Scanner(System.in);int yearOfManufacture;out.print("Enter the year of manufacture of the car: ");for (int count = 0; count < vehicleTotal; count++) {if (carType[count].getYearOfManufacture() == yearOfManufacture)out.println(carType[count].getVehicle());public static void listAllBikesInAGivenYear(Bike bikeType[],int vehicleTotal) {new Scanner(System.in);int yearOfManufacture;out.print("Enter the year of manufacture for the bike: ");for (int count = 0; count < vehicleTotal; count++) {if (bikeType[count].getYearOfManufacture() == yearOfManufacture)out.println(bikeType[count].getVehicle());public static void listAllCarsOfOneLitreOrMore(Car carType[],int vehicleTotal) {new Scanner(System.in);int engineSizeLitres;out.print("Enter the engine size in litres for the car: ");for (int count = 0; count < vehicleTotal; count++) {if (carType[count].getEngineSizeLitres() == engineSizeLitres)out.println(carType[count].getVehicle());public static void listAllBikesThatEngineSizeInCubicCentimetres(int vehicleTotal) {new Scanner(System.in);int engineSizeCC;out

.print(

engineSizeCC = input.nextInt();

System.

}

}

Scanner input =

String listAllCars;

System.

listAllCars = input.next();

System.

}

}

Scanner input =

String listAllBikes;

System.

listAllBikes = input.next();

System.

}

}

Scanner input =

System.

carValue = input.nextDouble();

System.

}

}

Scanner input =

System.

bikeValue = input.nextDouble();

System.

}

}

Car carType[] =

Bike bikeType[] =

option = getMenuOption();

vehicleTotal = addCar(carType, vehicleTotal);

}

vehicleTotal = addBike(bikeType, vehicleTotal);

}

listAllCarsInAGivenYear(carType, vehicleTotal);

}

listAllBikesInAGivenYear(bikeType, vehicleTotal);

}

listAllCarsOfOneLitreOrMore(carType, vehicleTotal);

}

listAllBikesThatEngineSizeInCubicCentimetres(bikeType,

vehicleTotal);

}

listAllCars(carType, vehicleTotal);

}

listAllBikes(bikeType, vehicleTotal);

}

listAllValuesForTheCars(carType, vehicleTotal);

}

listAllValuesForTheBikes(bikeType, vehicleTotal);

}

"Enter the engine size in cubic centimetres for the bike: ");for (int count = 0; count < vehicleTotal; count++) {if (bikeType[count].getEngineSizeCC() == engineSizeCC)out.println(bikeType[count].getVehicle());public static void listAllCars(Car carType[], int vehicleTotal) {new Scanner(System.in);out.print("List all cars");for (int count = 0; count < vehicleTotal; count++) {if (carType[count].getVehicle() == listAllCars)out.println(carType[count].getVehicle());public static void listAllBikes(Bike bikeType[], int vehicleTotal) {new Scanner(System.in);out.print("List all bikes");for (int count = 0; count < vehicleTotal; count++) {if (bikeType[count].getVehicle() == listAllBikes)out.println(bikeType[count].getVehicle());public static void listAllValuesForTheCars(Car carType[], int vehicleTotal) {new Scanner(System.in);double carValue;out.print("Enter the car value: ");for (int count = 0; count < vehicleTotal; count++) {if (carType[count].getCarValue() == carValue)out.println(carType[count].getVehicle());public static void listAllValuesForTheBikes(Bike bikeType[],int vehicleTotal) {new Scanner(System.in);double bikeValue;out.print("Enter the bike value: ");for (int count = 0; count < vehicleTotal; count++) {if (bikeType[count].getBikeValue() == bikeValue)out.println(bikeType[count].getVehicle());static class museum {public static void main(String[] args) {new Car[100];new Bike[100];int vehicleTotal = 0;int option;while (option != quit) {if (option == 1) {else if (option == 2) {else if (option == 3) {else if (option == 4) {else if (option == 5) {else if (option == 6) {else if (option == 7) {else if (option == 8) {else if (option == 9) {else if (option == 10) {else

System.

option = getMenuOption();

}

}

}

}

out.println("Invalid input, please try again");

and the output is

1. Add new car to the list:

2. Add new bike to the list:

3. List all of the cars that are manufactured in a given year

4. List all of the bikes that are manufactured in a given year

5. List all of the cars that engine size are 1 litre or more (1 litre = 1000cc)

6. List all of the bike that engine size in cubic centimetres

7. List all of the cars

8. List all of the bikes

9. List the value for the cars

10. List the value for the bikes

0. Quit

trendycollections
Offline
Joined: 2012-03-21

Hi friend,

I know that the Java is an object oriented language . It is used to develop a software wiht more security. I know that if you using the any environment like NetBeans, Eclipse, Jcreator etc , then the error box, compilation button, run button etc are being in that environment . You can only use it .

Suppose if you using the notepad then to compile and run the program , you use the 'command promt' and all the information are seeing in the command prompt only.

IF You useing the web application then the apache(web server if uses) will generate the error in the own folder named as 'log'' folder.

Thanking you.