My goal is to write a class called DrivingLicense that is suppose to return ()isSuspended with the tickets exceed 2.
public class DrivingLicense { String name; int numTickets; public DrivingLicense() { name = null; numTickets = 0; } public DrivingLicense (String name, int numTickets){ this.name = name; this.numTickets = numTickets; } public Boolean isSuspended (){ if (numTickets >= 2) return false; return false; } public Boolean addTicket() { numTickets ++; if (numTickets >= 2) return true; return true; //<--can I get addTicket to run through isSuspended with the new value of numTicket or do I need to //redo this? } }
This is the program that calls on my program
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(); //private String name; //public class DrivingLicense (String name){ //citizen = name; //public void set // 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"); } } }