Key card system in Java according to the different 4 versions with full source code

The university is going to get a new key-card system and a system designer has come up with a suggestion on how to make the program that is going to operate the system – one abstract class «Card» that need to contain card holers first and last name, PIN code, card number and a boolean variable that checks if the card is working/blocked.

Version 0.1:

  • The class should minimum have following constructor and methods:

  • One constructor that sets all data members (possibly datafields) to desired values. Let the class itself generate unique card numbers (use a static variable that as you use to pick a card number). The variable blockedCard is set to false, which indicates open for a new card.

  • Method String getName() that returns card holders name.

  • Method booleon isBlocked() that returns if the card is blocked or not.

  • One String toString() method that writes out all of the cards data members.

  • One abstract method boolean checkPIN(int pin).


Write the code for the class Card. Additional methods is written as needed. The first version of this card-class is version 0.1. Do a push of this to *school website* as branch v0.1.

Version 0.2:
The program will be further developed, and new suggestions have come in, that you as a developer is responsible for a prototype. Make a branch in GIT and give this the name v0.2


  • There will be a need to distinguish between employees and guests. A guest will be given a card where the cardholder always enter the PIN code 9999, but the card is limited in time by the guest card lasts one week from the date it was made.

  • An employee's card is always valid during office hours, between the hours. 07:00 and 17:00 (7:00 and 5:00 p.m.) on weekdays. Outside office hours must employee enter his PIN code, but the card does not expire in time.

  • Blocked cards shall not provide access either for staff or guests.

  • You should not ask for pin code in checkPin method, this you will be given as a parameter to the method


Based on this information, create two new classes Employee and Guest. Implement the method boolean checkPIN (int pin) which behave as described above. Add any new data members and methods / constructors in classes to get this to work.

This is a test program that tests the class behavior:
public class CardTest {
public static void main(String[] args) {
java.util.ArrayList <card cardArray = new java.util.ArrayList<();
Card c1 = new Employee("Ole Olsen", 1234);
Card c2 = new Guest("Marit Olsen", 9999);
cardArray.add(k1);
cardArray.add(k2);
for (Card card : cardArray) {
System.out.println(card);
System.out.println("Code 1234 is " + (card.checkPIN(1234) ? "valid": "blocked")); System.out.println("Code 9999 is " + (card.checkPIN(9999) ? "valid": "blocked"));}}}

Version 0.3:
Define and interface. Constants with the following methods:


  • setFirstname(String) and String getFirstname() to set and retrieve first name.

  • setLastname(String) and String getLastname() to set and retrieve last name.

  • setFullname(String) and String getFullname() to set and retrieve the persons full name. The argument to set-method should be first and last names separated by spaces. Similarly, the get-method return first and last name separated by a space.

  • double calculateCredit (), credit is calculated as a fixed factor (constant) multiplied by the hourly rate.

  • double calculateBonus (), calculated as a fixed factor (constant) multiplied by the number of years of seniority.


The class Employee shall implement the interface. Add new data members in the Employee class as needed. Create a new branch in GIT named v0.3 and create interface. Make necessary changes to Employee class to implement this, add new data members as needed.
Powered by