
This program uses a class named DrivingLicense to keep track of two driving licenses, including the driver?s name, and the number of speeding tickets they have received. You may not modify the DLTest code, but should write the DrivingLicense class, and test it using the DLTest.java program to ensure that it generates the following output.
Alice does NOT have a suspended license Bob does NOT have a suspended license Bob and Alice are both caught speeding! Alice has a suspended license! Bob does NOT have a suspended license
/* Class: DLTest.java Description:Test program for the DrivingLicense class */ public class DLTest { // main() method public static void main(String[] args) { // declare and create two DrivingLicense objects DrivingLicense d1 = new DrivingLicense(); DrivingLicense d2 = new DrivingLicense();
// initialize the objects with names and speeding tickets
d1.name = "Alice";
d1.numTickets = 2;
d2.name = "Bob";
d2.numTickets = 0;
// check if Alice or Bob have suspended licenses (more than 2 tickets)
if ( d1.isSuspended() )
{
System.out.println(d1.name + " has a suspended license!");
}
else
{
System.out.println(d1.name + " does NOT have a suspended license");
}
if ( d2.isSuspended() )
{
System.out.println(d2.name + " has a suspended license!");
}
else
{
System.out.println(d2.name + " does NOT have a suspended license");
}
// Alice and Bob both get caught speeding, so add another ticket for each of them
System.out.println("Bob and Alice are both caught speeding!");
d1.addTicket();
d2.addTicket();
// check again if Alice or Bob have suspended licenses (more than 2 tickets)
if ( d1.isSuspended() )
{
System.out.println(d1.name + " has a suspended license!");
}
else
{
System.out.println(d1.name + " does NOT have a suspended license");
}
if ( d2.isSuspended() )
{
System.out.println(d2.name + " has a suspended license!");
}
else
{
System.out.println(d2.name + " does NOT have a suspended license");
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.