Question

using CSCI300 java Given the following UML Class Diagram Club_Card # card_num : String # name...

using CSCI300 java

Given the following UML Class Diagram

Club_Card
# card_num : String
# name : String
# age: int
# year: int
+ Club_Card (all parameters)
+ Setters & Getters
+ toString() : String
+ equals(x: Object): boolean

[10 pts] Define the class Club_Card, which contains:
1. All arguments constructor which accepts all required arguments from the main and instantiate a
Club_Card object.
2. Set & get method for each data attribute.
3. A toString() method which returns a String containing all attributes of Club_Card object as follows.
Assume the club_card number is AB12S3 was issued in 2018, and the holder name is Nael Moussa
whose age is 25. The toString() method returns the object data as follows:
The card number is AB12S3 was issued in 2018 for Nael Moussa whose age is 35
4. An equals() method which returns true when 2 objects of type Club_Card has exactly the same
contents otherwise it returns false.
[15 pts] Define the Yearly_card class as described in the class diagram.
1. All arguments constructor which accepts all required arguments from the main and instantiate
a Yearly_card object by calling the constructor of Club_Card class.
2. Set & get method for each data attribute.
3. The computePrice method returns the price of Yearly_ Card price as follows:

Yearly_card

- cost: double
- type : int // (1) for old cards or (2) for a new card
+ Yearly_card (all parameters)
+ Setters & Getters
+ toString(): String
+ computePrice : double

Permanent_Card

-charge: double
-Kind: String //Personal or family card
+ Permanent_Card (all parameters)
+ Setters & Getters
+ toString(): String
+ computePrice : double

CSCI300L Test III Spring 2019-2020

2 | P a g e
 A Discount of 10% on the yearly card cost will be deducted for persons with
age less than 40.
 Moreover a fee of $100 is added to the cost of a new issued Yearly_Card
4. A toString() method which returns a String containing the data of Yearly_Card object with the
help of toString() in the Club_Card class, as follows:
A (new) Yearly_Card, the card number is AB12S3 was issued in 2018 for Nael Moussa whose age
is 35, the price = $350
[15 pts] Define the Permanent_Card class as described in the class diagram.
1. All arguments constructor which accepts all required arguments from the main and instantiate
a Permanent_Card object by calling the constructor of Club_Card class.
2. Set & get method for each data attribute.
3. The computePrice method returns the price of Permanent_Card price as follows:
 A fee of $400 is added to the initial charge of a family permanent_card.
 8% discount will be deducted for a Personal Permanent_Card if the person
age is less than 30.

 A toString() method which returns a String containing the data of Permanent_Card object with the
help of toString() in the Club_Card class, as follows:
A (family) Permanent_Card, the card number is CB12F3 was issued in 2019 for Nada Itani
whose age is 25, the price = $620

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

Tested on Java 14. Can't provide output as the question doesn't specify main method.

CSCI300.java

import java.util.Objects;

class Club_Card {

    protected String card_num;

    protected String name;

    protected int age;

    protected int year;

    public Club_Card(String card_num, String name, int age, int year) {

        this.card_num = card_num;

        this.name = name;

        this.age = age;

        this.year = year;

    }

    public String getCard_num() {

        return this.card_num;

    }

    public void setCard_num(String card_num) {

        this.card_num = card_num;

    }

    public String getName() {

        return this.name;

    }

    public void setName(String name) {

        this.name = name;

    }

    public int getAge() {

        return this.age;

    }

    public void setAge(int age) {

        this.age = age;

    }

    public int getYear() {

        return this.year;

    }

    public void setYear(int year) {

        this.year = year;

    }

    @Override

    public String toString() {

        return String.format("The card number is %s was issued in %i for %s whose age is %i", card_num, year, name,

                age);

    }

    @Override

    public boolean equals(Object o) {

        if (o == this)

            return true;

        if (!(o instanceof Club_Card)) {

            return false;

        }

        Club_Card club_Card = (Club_Card) o;

        return Objects.equals(card_num, club_Card.card_num) && Objects.equals(name, club_Card.name)

                && age == club_Card.age && year == club_Card.year;

    }

}

class Yearly_Card extends Club_Card {

    private double cost;

    private int type;

    public Yearly_Card(String card_num, String name, int age, int year, double cost, int type) {

        super(card_num, name, age, year);

        this.cost = cost;

        this.type = type;

    }

    public double getCost() {

        return this.cost;

    }

    public void setCost(double cost) {

        this.cost = cost;

    }

    public int getType() {

        return this.type;

    }

    public void setType(int type) {

        this.type = type;

    }

    public double computePrice() {

        double price = cost;

        if (age < 40)

            // 10% discount on yearly cost

            price *= 0.9;

        // Add $100 issuance charge and return

        return price + 100;

    }

    @Override

    public String toString() {

        return String.format("A (new) Yearly_Card, T%s, the price = $%i", super.toString().substring(1), computePrice());

    }

    @Override

    public boolean equals(Object o) {

        if (o == this)

            return true;

        if (!(o instanceof Yearly_Card)) {

            return false;

        }

        Yearly_Card yearly_Card = (Yearly_Card) o;

        return Objects.equals(card_num, yearly_Card.card_num) && Objects.equals(name, yearly_Card.name) && age == yearly_Card.age && year == yearly_Card.year && cost == yearly_Card.cost && type == yearly_Card.type;

    }

    @Override

    public int hashCode() {

        return Objects.hash(cost, type);

    }

}

class Permanent_Card extends Club_Card{

    private double charge;

    private String Kind;

    public Permanent_Card(String card_num, String name, int age, int year, double cost, int type, double charge, String Kind) {

        super(card_num, name, age, year);

        this.charge = charge;

        this.Kind = Kind;

    }

    public double getCharge() {

        return this.charge;

    }

    public void setCharge(double charge) {

        this.charge = charge;

    }

    public String getKind() {

        return this.Kind;

    }

    public void setKind(String Kind) {

        this.Kind = Kind;

    }

    public double computePrice() {

        double price = charge;

        if (age < 30)

            // 8% discount on charge

            price *= 0.92;

        // Add $100 issuance charge and return

        return price + 100;

    }

    @Override

    public String toString() {

        return String.format("A (%s) Permanent_Card, T%s, the price = $%i",

            Kind, super.toString().substring(1), computePrice());

    }

    @Override

    public boolean equals(Object o) {

        if (o == this)

            return true;

        if (!(o instanceof Permanent_Card)) {

            return false;

        }

        Permanent_Card permanent_Card = (Permanent_Card) o;

        return Objects.equals(card_num, permanent_Card.card_num) && Objects.equals(name, permanent_Card.name) && age == permanent_Card.age && year == permanent_Card.year && charge == permanent_Card.charge && Objects.equals(Kind, permanent_Card.Kind);

    }

}

Add a comment
Know the answer?
Add Answer to:
using CSCI300 java Given the following UML Class Diagram Club_Card # card_num : String # name...
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
  • Create the class Book which has the following members: 1. private members: 1. title as String...

    Create the class Book which has the following members: 1. private members: 1. title as String 2. isbn as String 3. author as String 4. price as double 2. public members: 1. default constructor which initializes all data members to their default values. 2. non-default constructor which initializes all data members to parameters values. 3. toString which returns a representing String of the Book. 4. add all the setters and getters. Create the class EBook which is a subclass of...

  • C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (Strin...

    C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (String) edition ( int) published year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method// that return sting representation of Book object. 2-Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title...

  • Hi , i have facing problems in both 5 error while i am soloving it can...

    Hi , i have facing problems in both 5 error while i am soloving it can you help me with good solotion for both pleas pleas ??? a- Write a java class to define the new data type Item. The data type Item is defined by the attributed name of type String) and price of type double). Provide the following methods in the class implementation: • Default constructor (that initializes the attribute name to the value “Unknown”, and the attribute...

  • Create a java class for an object called Student which contains the following private attributes: a...

    Create a java class for an object called Student which contains the following private attributes: a given name (String), a surname (family name) (String), a student ID number (an 8 digit number, String or int) which does not begin with 0. There should be a constructor that accepts two name parameters (given and family names) and an overloaded constructor accepting two name parameters and a student number. The constructor taking two parameters should assign a random number of 8 digits....

  • Write a Java class named Employee to meet the requirements described in the UML Class Diagram...

    Write a Java class named Employee to meet the requirements described in the UML Class Diagram below: Note: Code added in the toString cell are not usually included in a regular UML class diagram. This was added so you can understand what I expect from you. If your code compiles cleanly, is defined correctly and functions exactly as required, the expected output of your program will solve the following problem: “An IT company with four departments and a staff strength...

  • Please help me with this code. Thank you Implement the following Java class: Vehicle Class should...

    Please help me with this code. Thank you Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels; Double engineCapacity; Boolean isElectric, String manufacturer; Array of integers productionYears; Supply your class with: Default constructor (which sets all variables to their respective default values) Constructor which accepts all the variables All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle...

  • Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram)

    Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram) Author -name:String -email:String -gender:char +Author(name:String, email:String, gender:char) +getName():String +getEmail):String +setEmail (email:String):void +getGender():char +tostring ):String . Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f'): One constructor to initialize the name, email and gender with the given values . Getters and setters: get Name (), getEmail() and getGender (). There are no setters for name and...

  • Need help to create general class Classes Data Element - Ticket Create an abstract class called...

    Need help to create general class Classes Data Element - Ticket Create an abstract class called Ticket with: two abstract methods called calculateTicketPrice which returns a double and getld0 which returns an int instance variables (one of them is an object of the enumerated type Format) which are common to all the subclasses of Ticket toString method, getters and setters and at least 2 constructors, one of the constructors must be the default (no-arg) constructor. . Data Element - subclasses...

  • JAVA QUESTION 16 Write and submit the java source for the following class specification: The name...

    JAVA QUESTION 16 Write and submit the java source for the following class specification: The name of the class is Question_16 Class Question_16 has 3 instance variables: name of type String, age of type int and height of type double. Class Question_16 has the following methods: print - outputs the data values stored in the instance variables with the appropriate label setName - method to set the name setAge - method to set the age setHeight - method to set...

  • Generics Objectives: OOWorking with a Generic Class 1. Create a class called Node that is Generic...

    java Generics Objectives: OOWorking with a Generic Class 1. Create a class called Node that is Generic. The class has one class attribute that is an element. It will need 2 Constructors, a setter and getter for the class attribute, and a toString method. 2. Write a Lab10Driver that will: Instantiate a Node Integer object with no value. I. Il. Ill. IV. a. Then call the set method to set the value to 5. Instantiate a Node String object with...

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
Active Questions
ADVERTISEMENT