Question






Student Created Include private instance variables to store information needed for a ticket. Select the correct data types fo
0 0
Add a comment Improve this question Transcribed image text
Answer #1

EDIT methid header(),ticketType(),calculateFine(), accroding to your Data.....

/**********************Ticket.java***********************/


/*
*
*/
import java.util.Random;

/**
* The Class Ticket.
*/
public class Ticket {

   /** The name. */
   private String name;

   /** The ticket type. */
   private String ticketType;

   /** The speed. */
   private int speed;

   /** The speed limit. */
   private int speedLimit;

   /** The ticket number. */
   private int ticketNumber;

   /** The school zone. */
   private boolean schoolZone;

   /** The work zone. */
   private boolean workZone;

   /**
   * Instantiates a new ticket.
   *
   * @param name the name
   * @param speed the speed
   * @param speedLimit the speed limit
   * @param schoolZone the school zone
   * @param workZone the work zone
   */
   public Ticket(String name, int speed, int speedLimit, boolean schoolZone, boolean workZone) {
       super();
       this.name = name;
       this.speed = speed;
       this.speedLimit = speedLimit;
       this.schoolZone = schoolZone;
       this.workZone = workZone;
   }

   /**
   * Instantiates a new ticket.
   *
   * @param name the name
   * @param ticketType the ticket type
   * @param speed the speed
   * @param speedLimit the speed limit
   */
   public Ticket(String name, String ticketType, int speed, int speedLimit) {
       super();
       this.name = name;
       this.ticketType = ticketType;
       this.speed = speed;
       this.speedLimit = speedLimit;
       this.schoolZone = false;
       this.workZone = false;
   }

   /**
   * Gets the name.
   *
   * @return the name
   */
   public String getName() {
       return name;
   }

   /**
   * Sets the name.
   *
   * @param name the new name
   */
   public void setName(String name) {
       this.name = name;
   }

   /**
   * Gets the ticket type.
   *
   * @return the ticket type
   */
   public String getTicketType() {
       return ticketType;
   }

   /**
   * Sets the ticket type.
   *
   * @param ticketType the new ticket type
   */
   public void setTicketType(String ticketType) {
       this.ticketType = ticketType;
   }

   /**
   * Gets the speed.
   *
   * @return the speed
   */
   public int getSpeed() {
       return speed;
   }

   /**
   * Sets the speed.
   *
   * @param speed the new speed
   */
   public void setSpeed(int speed) {
       this.speed = speed;
   }

   /**
   * Gets the speed limit.
   *
   * @return the speed limit
   */
   public int getSpeedLimit() {
       return speedLimit;
   }

   /**
   * Sets the speed limit.
   *
   * @param speedLimit the new speed limit
   */
   public void setSpeedLimit(int speedLimit) {
       this.speedLimit = speedLimit;
   }

   /**
   * Gets the ticket number.
   *
   * @return the ticket number
   */
   public int getTicketNumber() {
       return ticketNumber;
   }

   /**
   * Sets the ticket number.
   *
   * @param ticketNumber the new ticket number
   */
   public void setTicketNumber(int ticketNumber) {
       this.ticketNumber = ticketNumber;
   }

   /**
   * Checks if is school zone.
   *
   * @return true, if is school zone
   */
   public boolean isSchoolZone() {
       return schoolZone;
   }

   /**
   * Sets the school zone.
   *
   * @param schoolZone the new school zone
   */
   public void setSchoolZone(boolean schoolZone) {
       this.schoolZone = schoolZone;
   }

   /**
   * Checks if is work zone.
   *
   * @return true, if is work zone
   */
   public boolean isWorkZone() {
       return workZone;
   }

   /**
   * Sets the work zone.
   *
   * @param workZone the new work zone
   */
   public void setWorkZone(boolean workZone) {
       this.workZone = workZone;
   }

   /**
   * Calculate fine.
   *
   * @return the double
   */
   public double calculateFine() {

       return 0;
   }

   /**
   * Prints the notice.
   *
   * @return the string
   */
   public String printNotice() {

       return "The person " + name + " has fine of " + calculateFine();
   }

   /**
   * Generate ticket number.
   *
   * @return the int
   */
   private int generateTicketNumber() {

       Random rn = new Random();

       return rn.nextInt(999999) + 100000;
   }

   /**
   * Generate court date.
   *
   * @return the date
   */
   private Date generateCourtDate() {

       Random rn = new Random();
       int day = rn.nextInt(31) + 1;

       return new Date(day, 10, 2019);
   }

   /**
   * Determine ticket type.
   *
   * @return the string
   */
   private String determineTicketType() {

       return "";
   }

   /**
   * Headers.
   *
   * @return the string
   */
   public static String headers() {

       return "";
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Ticket " + generateTicketNumber() + ", " + determineTicketType() + ", " + generateCourtDate();
   }

}
/*********************TestDriver.java***************/

Enter name: Virat
Ticket Type: Payable
Speed: 50
Speed Limit: 70
Do you want to add another ticket(Y/N): N
Exiting the Ticket Manager
The person Virat has fine of 0.0

2 Console X <terminated> TicketDriver [Java Application] C:\Program Files\Java\jre1.8.0_211\bin\java Enter name: Virat Ticket

Please let me know if you have any doubt or modify the answer, Thanks :)

Add a comment
Know the answer?
Add Answer to:
Student Created Include private instance variables to store information needed for a ticket. Select the correct...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in...

    In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...

  • In one file create an Employee class as per the following specifications: three private instance variables:...

    In one file create an Employee class as per the following specifications: three private instance variables: name (String), startingSalary (int), yearlyIncrement (int) a single constructor with three arguments: the name, the starting salary, and the yearly increment. In the constructor, initialize the instance variables with the provided values. get and set methods for each of the instance variables. A computation method, computeCurrentSalary, that takes the number of years in service as its argument. The method returns the current salary using...

  • public class Car {    /* four private instance variables*/        private String make;   ...

    public class Car {    /* four private instance variables*/        private String make;        private String model;        private int mileage ;        private int year;        //        /* four argument constructor for the instance variables.*/        public Car(String make) {            super();        }        public Car(String make, String model, int year, int mileage) {        super();        this.make = make;        this.model...

  • Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters...

    Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters long encryptedPassword : String key int Must be between 1 and 10(inclusive) accountId - A unique integer that identifies each account nextIDNum – a static int that starts at 1000 and is used to generate the accountID no other instance variables needed. Default constructor – set all instance variables to a default value. Parameterized constructor Takes in clearPassword, key. Calls encrypt method to create...

  • Ticket Hierarchy Ticket Abstract Class Create a static variable called nextTicketId. This is an integer representing...

    Ticket Hierarchy Ticket Abstract Class Create a static variable called nextTicketId. This is an integer representing the next available integer for the ticketId                                 private static int nextTicketId = 1000; getPrice method: Abstract method that returns a double. NOTE: Do not make price an instance variable in Ticket. Noargument constructor: Sets event name to “none”, event location to “none”, and ticket id to 0. Create a constructor that accepts the event name and event location as parameters. Set the ticket Id...

  • public class Pet {    //Declaring instance variables    private String name;    private String species;...

    public class Pet {    //Declaring instance variables    private String name;    private String species;    private String parent;    private String birthday;    //Zero argumented constructor    public Pet() {    }    //Parameterized constructor    public Pet(String name, String species, String parent, String birthday) {        this.name = name;        this.species = species;        this.parent = parent;        this.birthday = birthday;    }    // getters and setters    public String getName() {        return name;   ...

  • Student class: Instance variables name id Constructors: Default constructor Constructor that has id and name passed...

    Student class: Instance variables name id Constructors: Default constructor Constructor that has id and name passed to the constructor Methods: Accessors int getID( ) String getName( ) Class Roster: This class will implement the functionality of all roster for school. Instance Variables a final int MAX_NUM representing the maximum number of students allowed on the roster an ArrayList storing students Constructors a default constructor should initialize the list to empty strings a single parameter constructor that takes an ArrayList<Student> Both...

  • public class Fish { private String species; private int size; private boolean hungry; public Fish() {...

    public class Fish { private String species; private int size; private boolean hungry; public Fish() { } public Fish(String species, int size) { this.species = species; this.size = size; } public String getSpecies() { return species; } public int getSize() { return size; } public boolean isHungry() { return hungry; } public void setHungry(boolean hungry) { this.hungry = hungry; } public String toString() { return "A "+(hungry?"hungry":"full")+" "+size+"cm "+species; } }Define a class called Lake that defines the following private...

  • 1. Assume you have a Car class that declares two private instance variables, make and model....

    1. Assume you have a Car class that declares two private instance variables, make and model. Write Java code that implements a two-parameter constructor that instantiates a Car object and initializes both of its instance variables. 2. Logically, the make and model attributes of each Car object should not change in the life of that object. a. Write Java code that declares constant make and model attributes that cannot be changed after they are initialized by a constructor. Configure your...

  • Read through the code of the class Player, noting it has two instance variables, name and rank, which are of type String and three further instance variables won, drew and lost which are of type int....

    Read through the code of the class Player, noting it has two instance variables, name and rank, which are of type String and three further instance variables won, drew and lost which are of type int. There is also an attribute of the class, points, which does not have a corresponding instance variable. Also note the constructor and methods of the class and what they do. TournamentAdmin class code: public class RankAdmin {    /**     * Constructor for objects of class...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT