Question

(10 marks) Question 1 Class Definitions la) (5 marks) Write information on Java class called IdentityCard to represent the th

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//1 a)
class IdentityCard
{
//instance variables
private String name;
private int idenityNumber;
private Image photo;
private boolean status;
//constructor
public IdentityCard(String name,int identityNumber,Image photo,boolean status)
{
this.name=name;
this.identityNumber=identityNumber;
this.photo=photo;
this.status=status;
}
//mutator for setting identity Number
public void setIdentityNumber(int identityNumber)
{
if(identityNumber>0)
this.identityNumber=identityNumber;
}
//accessor for getting identity number
public int getIdentityNumber()
{
return this.identityNumber;
}
}
// 1 b)
class DoorAccess
{
private ArrayList<IdentityCard> idCards;
//constructor
public DoorAccess(ArrayList<IdentityCard> idCards)
{
this.idCards=idCards;
}
//checkCardRemoval
boolean checkCardRemoval(IdentityCard idCard)
{
boolean found=false;
for(int i=0;i<idCards.size();++i)
{
if(idCards.get(i).getIdentityNumber()==idCard.getIdentityNumber())
{
found=true;
break;
}
}
if(found==true)
{
idCards.remove(i);
}
return found;
}
IdentityCard search(int identityNumber)
{
for(int i=0;i<idCards.size();++i)
{
if(idCards.get(i).getIdentityNumber()==identityNumber)
{
return idCards.get(i);
}
}   
return null;
}
}

Add a comment
Know the answer?
Add Answer to:
(10 marks) Question 1 Class Definitions la) (5 marks) Write information on Java class called IdentityCard...
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
  • Design a class called Building. The class should keep the following information in the fields: String...

    Design a class called Building. The class should keep the following information in the fields: String address double property_value create several constructors including copy constructor , create accessor and mutator methods        Part 2 (50 points) Define interface Taxable which has one method getPropertyTax() Design a class called Private_Property that extends Building and implements Taxable It should have the following field : double value_of_improvements Create a constructor for this class to include newly added fields. The tax for the private property...

  • Question 1 (24 Marks] 1. (4 marks) Write an immutable Person class in Java which provides...

    Question 1 (24 Marks] 1. (4 marks) Write an immutable Person class in Java which provides the following. • Two attributes: lastName and first Name of type String. • Appropriate initialization, accessors/mutator methods. 2. (6 marks) Write a Student class that is a subclass of Person class (in the previous question) which provides the following. • Two attributes: A unique student ID of type String and GPA of type float; the student ID is initialized when a Student object gets...

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

    java 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. • speed: The 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. These values...

  • In C++, Step 1: Implement the Student Class and write a simple main() driver program to...

    In C++, Step 1: Implement the Student Class and write a simple main() driver program to instantiate several objects of this class, populate each object, and display the information for each object. The defintion of the student class should be written in an individual header (i.e. student.h) file and the implementation of the methods of the student class should be written in a corresponding source (i.e. student.cpp) file. Student class - The name of the class should be Student. -...

  • JAVA HELP Design a class named Employee. The class should keep the following information in fields:...

    JAVA HELP Design a class named Employee. The class should keep the following information in fields: Employee name Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. Hire date then, Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that extends the Employee class. The ProductionWorker class should have fields to...

  • 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....

  • JAVA 1. Write a class called Rectangle that represents a rectangular two-dimensional region. Your Rectangle objects...

    JAVA 1. Write a class called Rectangle that represents a rectangular two-dimensional region. Your Rectangle objects should have the following fields and methods: int width, int height Where width and height are the dimensions of the rectangle. Write accessor methods (i.e. getWidth(), getHeight()) that retrieve the values stored in the fields above. And mutator methods (i.e. setWidthl), setHeight() ) that change the field's values. Finally create a method called getAreal) that returns the area of the rectangle. Like we did...

  • in java Account that contains: balance: double data field date: Date data field. Use Date class...

    in java Account that contains: balance: double data field date: Date data field. Use Date class from the java.util package accountNumber: long data field. You should generate this value randomly. The account number should be 9 digits long. You can you random method from java Math class. annuallnterestRate: double data field. customer: Customer data field. This is the other class that you will have to design. See description below. The accessor and mutator methods for balance, annuallnterestRate, date, and customer....

  • Room Class....... in JAVA!!!!! Write a class named Room that has the following fields: Length: Double...

    Room Class....... in JAVA!!!!! Write a class named Room that has the following fields: Length: Double variable that holds the rooms length(in feet). Breadth: The double variable that holds the rooms breadth(in feet). Height: Double variable that holds rooms height in feet. Color: String object that holds the color you want the room to be painted with. The class should have a constructor to initialize the fields for a particular instance (or object) of the class as given: All double...

  • Write a java program that creates a class Car. Class Car contains the following private member...

    Write a java program that creates a class Car. Class Car contains the following private member fields: make, model, year, and miles. The class Car has a constructor that takes as arguments the car make, model, and year. In addition, the constructor sets miles to 100 as default. Class Car has accessors and mutators to get and set the make, model, year and miles on the car. The program should complete the following tasks: Ask the user to enter make,...

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