I'm new to java so please respect my post(and my ignorance). String drName is ignored, netbeans does not ask for input and automatically proceeds to the next variable for input. Please help me fix this. Here's the code:
package learningjava;
import java.util.Scanner;
/**
*
* @author JayveeDeGuzmanSuyom
*/
class Association {
double carId;
String carName;
Association (double cId, String cName){
this.carId = cId;
this.carName = cName;
}
}
class Driver extends Association {
double driverId;
String driverName;
Driver (double dId, String cName, String dName){
super(dId, cName);
this.driverId = dId;
this.driverName = dName;
}
}
class TransportCompany {
public static void main (String [] args){
Scanner scaninput = new Scanner (System.in);
System.out.print("Enter Driver ID: ");
int drID = scaninput.nextInt();
System.out.print("What's the Driver's Name?: ");
String drName = scaninput.nextLine();
System.out.print("What's the name of the car?: ");
String caName = scaninput.nextLine();
scaninput.close();
Driver obj1 = new Driver(drID, caName, drName);
System.out.println("The new driver is " + obj1.driverName + " with Driver ID " +
obj1.driverId + " driving the " + obj1.carName + " with ID No. " + obj1.carId);
}
}
and here is the output:
run: Enter Driver ID: 170912 What's the Driver's Name?: What's the name of the car?: Nissan Frontier Navarra The new driver is with Driver ID 170912.0 driving the Nissan Frontier Navarra with ID No. 170912.0 BUILD SUCCESSFUL (total time: 18 seconds)
TYIA for the replies.