Prev | Current Page 508 | Next

Carl Reynolds and Paul Tymann

"Schaum's Outline of Principles of Computer Science"

This is the code snippet that decides how to create the
Vehicles and then creates them:
if( args.length == 0 ) {
//There is no file name on the command line, so
// make up some vehicles with hard coding
vehicles[0] = new Vehicle( "Ford", "Mustang",
2, "red" );
vehicles[1] = new Vehicle( "BMW", "328i",
4, "silver" );
vehicles[2] = new Vehicle( "Chrysler", "PT Cruiser",
4, "gold" );
System.out.println( "There are "
+ Vehicle.vehicleCount + " vehicles." );
System.out.println( "Make of vehicles[0]: "
+ vehicles[0].getMake() );
System.out.println( "Model of vehicles[1] (328i): "
+ vehicles[1].getModel() );
System.out.println( "Color of vehicles[2] (gold): "
+ vehicles[2].getColor() );
System.out.println( "Max occupants of vehicles[0]: "
+ vehicles[0].getMaxOccupants() );
}
198 ANSWERS TO REVIEW QUESTIONS
else {//There is a file name on the command line, so
// read from a file using Scanner.
Scanner sc = null;
try {
sc = new Scanner(
new File(args[0]) );
}
catch(Exception e) {
System.out.println( e.getMessage() );
}
int index = 0;
while( sc.hasNext() ) { //read line in file
vehicle = sc.next();
color = sc.next();
make = sc.next();
model = sc.next();
maxOccupants = sc.nextInt();
if( vehicle.


Pages:
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
wróżby miłosne cukiernia-stykowscy.pl salon kosmetyczny kraków pompy ciepła Kalkulator kredytowy