Question

class Parking Permit has seven fields, but only of three of them are required for issuing a parking permit. Implement ways to
0 0
Add a comment Improve this question Transcribed image text
Answer #1

To instantiate any class, we need to ahve constructors. As the question asked, there are 3 mandatory fileds and 4 optional fields for ParkingPermit. and we can not use setters and getters. So the only way we can give values to these fileds is by constructors. So we will instatiate this class by using overloaded constructors. We will have diffrent constructors with diffrent fields. All constructors have three mandatory fileds plus the optional fields. we can use any one of them to instantiate the class and set the values in required fields. Any field that is not given value through constructor parametrs will be set "Not Defined". I have provided 4 constructors or in other words 4 diffrent ways to instantiate the class. below is the class code with all 4 constructors.

public class ParkingPermit {
        String make;
        String model;
        String LicencePlate;
        String year;
        String VIN;
        String color;
        String Owner;
        
        //Constructor with all parameters
        //instantiate by giving all the parameters
        public ParkingPermit(String make, String model, String licencePlate, String year, String vIN, String color,
                        String owner) {
                this.make = make;
                this.model = model;
                LicencePlate = licencePlate;
                this.year = year;
                VIN = vIN;
                this.color = color;
                Owner = owner;
        }

        //constructor with 4 parametrs, 3 mandatory and 1 optional
        //instantiate object by giving 4 parameters
        public ParkingPermit(String make, String model, String licencePlate, String owner) {
                this.make = make;
                this.model = model;
                LicencePlate = licencePlate;
                Owner = owner;
                //setting parameters which are not given in constructor
                color="Not Defined";
                year="Not Defined";
                VIN="Not Defined";
        }
        
        //constructor with 5 parametrs, 3 mandatory and 2 optional
        //instantiate class by giving 5 parameters
        public ParkingPermit(String make, String model, String licencePlate, String color, String owner) {
                this.make = make;
                this.model = model;
                LicencePlate = licencePlate;
                this.color = color;
                Owner = owner;
                //setting parameters which are not given in constructor
                year="Not Defined";
                VIN="Not Defined";
        }
        
        //constructor with 6 parametrs, 3 mandatory and 3 optional
        //instantiate class by giving 6 parameters
        public ParkingPermit(String make, String model, String licencePlate, String color, String year, String owner) {
                this.make = make;
                this.model = model;
                LicencePlate = licencePlate;
                this.color = color;
                this.year = year;
                Owner = owner;
                //setting parameters which are not given in constructor
                VIN="Not Defined";
        }

}

Add a comment
Know the answer?
Add Answer to:
class Parking Permit has seven fields, but only of three of them are required for issuing...
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
  • Language is JAVA. Clarification for the Shape class (highlighted): The following requirements specify what fields you...

    Language is JAVA. Clarification for the Shape class (highlighted): The following requirements specify what fields you are expected to implement in your Shape class; - A private String color that specifies the color of the shape - A private boolean filled that specifies whether the shape is filled - A private date (java.util.date) field dateCreated that specifies the date the shape was created Your Shape class will provide the following constructors; - A two-arg constructor that creates a shape with...

  • Please help me with this exercises in JAVA, Thank you ===================== Parking Ticket Simulator Assignment =====================...

    Please help me with this exercises in JAVA, Thank you ===================== Parking Ticket Simulator Assignment ===================== For this assignment you will create a set of classes from scratch (no provided class files for this assignment) that work together to simulate a police officer issuing a parking ticket. You should design the following classes / functionality within them: ===================== ParkedCar.java: ===================== This class should simulate a parked car. The class's responsibilities are as follows: - To store the car's make, model,...

  • Java Program Write a class named Car that has the following fields: yearModel- The yearModel field...

    Java Program Write a class named Car that has the following fields: yearModel- The yearModel field is an int that holds the car’s year model. make- The make field is a String object that holds the make of the car, such as “Ford”, “Chevrolet”, etc. speed- This speed field is an int that holds the car’s current speed. In addition, the class should have the following methods: Constructor- The constructor should accept the car’s year model and make as arguments....

  • Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance...

    Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance and interface behaviors . The link to the PDF of the diagram is below MotorVehical.pdf Minimize File Preview User Define Object Assignment: Create a Intellij Project. The Intellij project will contain three user defined classes. The project will test two of the User Define Classes by using the invoking each of their methods and printing the results. You are required to create three UML...

  • I need help with this java project and please follow the instruction below. thank Class Project...

    I need help with this java project and please follow the instruction below. thank Class Project - Parking Ticket simulator Design a set of classes that work together to simulate a police officer issuing a parking ticket. Design the following classes: •           The ParkedCar Class: This class should simulate a parked car. The class’s responsibilities are as follows: – To know the car’s make, model, color, license number, and the number of minutes that the car has been parked. •          ...

  • signature 1. Create a new NetBeans Java project. The name of the project has to be...

    signature 1. Create a new NetBeans Java project. The name of the project has to be the first part of the name you write on the test sheet. The name of the package has to be testo You can chose a name for the Main class. (2p) 2. Create a new class named Address in the test Two package. This class has the following attributes: city: String-the name of the city zip: int - the ZIP code of the city...

  • This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to...

    This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to create a Car class and Police Officer class, to create a new simulation. Write a simulation program (refer to the Bank Teller example listed below) that simulates cars entering a parking lot, paying for parking, and leaving the parking lot. The officer will randomly appear to survey the cars in the lot to ensure that no cars are parked...

  • *** FOR A BEGINNER LEVEL JAVA CLASS, PLEASE KEEP CODE SIMPLE, AND WE USE BLUE J...

    *** FOR A BEGINNER LEVEL JAVA CLASS, PLEASE KEEP CODE SIMPLE, AND WE USE BLUE J IN CLASS (IF IT DOESNT MATTER PLEASE COMMENT TELLING WHICH PROGRAM YOU USED TO WRITE THE CODE, PREFERRED IS BLUE J!!)*** ArrayList of Objects and Input File Use BlueJ to write a program that reads a sequence of data for several car objects from an input file. It stores the data in an ArrayList<Car> list . Program should work for input file containing info...

  • Please Implement ParkingLot.cpp below based off the completed Automobile Class and ClaimCheck class down below. Automobile.hpp...

    Please Implement ParkingLot.cpp below based off the completed Automobile Class and ClaimCheck class down below. Automobile.hpp #pragma once #include <iostream> #include <string> class Automobile { friend bool operator==( const Automobile& lhs, const Automobile& rhs ); friend std::ostream & operator<<( std::ostream& stream, const Automobile& vehicle ); private: std::string color_; std::string brand_; std::string model_; std::string plateNumber_; public: Automobile( const std::string & color, const std::string & brand, const std::string & model, const std::string & plateNumber ); }; bool operator!=( const Automobile& lhs, const...

  • Java Time Class Class declarations are one of the ways of defining new types in Java....

    Java Time Class Class declarations are one of the ways of defining new types in Java. we will create two classes that both represent time values for a 24 hours period. The valid operations are as follows. int getHours(): returns the number of hours int getMinutes(): returns the number of minutes int getSeconds(): returns the number of seconds String toString(): returns a String representation boolean equals(Time other): returns true if and only if other designates an object that has the...

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