Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Help with computer program

807601Dec 7 2007 — edited Dec 7 2007
Hi, I am very new this and could sue some help..

import java.util.*;

public class CarSort
{
public static void main(String[] args)
{

final int ARR_SIZE = 30;

final boolean DEBUG = true;

final String SENT_DBASE = "EndDatabase";

final String SENT_SEARCH = "EndSearchKeys";

Car[] carArr = new Car[ARR_SIZE];

Car car1;

Scanner scan = new Scanner(System.in);

String
make;

int
year,
numCars,
pos;

double price;


numCars = 0;
make = scan.next();

if(DEBUG)
System.out.println("\nDB make = " + make);

while(!make.equals(SENT_DBASE))
{


if(!scan.hasNextInt())
{
System.out.println("ERROR1: no nextInt.\nStop!");
System.exit(0);
}
year = scan.nextInt();

if(DEBUG)
System.out.println("DB year = " + year);

if(!scan.hasNextDouble())
{
System.out.println("ERROR2: no nextDouble.\nStop!");
System.exit(0);
}
price = scan.nextDouble();

if(DEBUG)
System.out.println("DB price = " + Car.twoDecPl.format(price));



car1 = new Car(make, year, price);
numCars++;
carArr[numCars - 1] = car1;

make = scan.next();

if(DEBUG)
System.out.println("DB make = " + make);

}

private static void selectionSort(double[] dA, int n)
{
double temp;

int posMax;

for(int i = n - 1; i > 0; i--)
{
posMax = 0;
for(int j = 1; j <= i; j++)
if(dA[j] > dA[posMax])
posMax = j;

temp = dA[posMax];
dA[posMax] = dA;
dA[i] = temp;

}

}

printData(carArr, numCars);

make = scan.next();

if(DEBUG)
System.out.println("\nSearch, make = " + make);

while(!make.equals(SENT_SEARCH))
{
if(!scan.hasNextInt())
{
System.out.println("ERROR3: no nextInt #2.\nStop!");
System.exit(0);
}
year = scan.nextInt();

if(DEBUG)
System.out.println("Search, year = " + year);

if(!scan.hasNextDouble())
{
System.out.println("ERROR4: no nextDouble.\nStop!");
System.exit(0);
}
price = scan.nextDouble();

if(DEBUG)
System.out.println("Search, price = " +
Car.twoDecPl.format(price));



car1 = new Car(make, year, price);
System.out.println("\nSearch key =" + car1);


pos = seqSearch(carArr, numCars, car1);

if(pos >= 0)
System.out.println("This vehicle was found at index = " + pos);
else
System.out.println("This vehicle was not found in the database.");

make = scan.next();

if(DEBUG)
System.out.println("\nSearch, make = " + make);

}


}


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

private static void printData(Car[] carArr, int numCars)
{

System.out.println("\nPrint out the database.");

for(int j = 0; j < numCars; j++)
System.out.println(carArr[j]);
}


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

private static int seqSearch(Car[] carArr, int numCars, Car key)
{
for(int j = 0; j < numCars; j++)
if(carArr[j].equals(key))
return j;

return -1;

}


}

This code is giving an illegal start error on private static void selectionSort(double[] dA, int n), So can someone tell me (and also explain why) how to fix this?

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jan 4 2008
Added on Dec 7 2007
2 comments
48 views