Concept explainers
Design a class to represent a credit card. Think about the attributes of a credit card; that is, what data is on the card? What behaviors might be reasonable for a credit card? Use the answer to these questions to write a UML class diagram for a credit card class. Then give three examples or instances of this class.
Unified Modeling Language (UML)
Unified Modeling Language (UML) is a modeling language in software engineering, which is used to visualize the design of the proposing system.
- In software development life cycle, it comes under the “documenting the program” phase.
- UML is used to document the developing system; this documentation helps the end user to understand the whole project.
- It visualizes all the components used in the developed object-oriented software; it shows all the elements and its relation.
Class diagram:
Class diagram is a static model which represents the system’s static structure and its relationship using attributes, relationships, objects, and operations.
- The relationship between the classes in the class diagram is called association.
- It is represented by drawing a line called association path between classes and placing the labels in between the association path.
- The instance of one class can be associated with more than one instance of another class and it is referred as multiplicity.
Steps to create class diagram:
- Identify objects
- Identify the attributes and behaviors
- Draw association between the classes.
Representing the class diagram:
- Every class in the class diagram is represented using a rectangle.
- The rectangle is divided into three parts,
- The first part contains the name of the class
- The middle part contains the attributes and derived attributes
- The last part contains the methods.
Class name |
-Attribute name |
+Operation name() |
Explanation of Solution
Attributes:
- Initially, identify the reasonable attributes for “CreditCard” class.
- The “CreditCard” contains the card number, card name, expiry date for card, and so on.
- So, let us take the followings are the attributes for “CreditCard” class.
- “cardNo”
- “name”
- “cardExpiryDate”
Explanation of Solution
Behaviors:
- Initially, identify the reasonable behaviors for “CreditCard” class.
- The “CreditCard” contains the “getCredit”, “getPurchase” and so on.
- So, let us take the followings are the behaviors for “CreditCard” class.
- “getCredit()”
- “getPurchase()”
Explanation of Solution
The UML class diagram for credit card is shown below:
The “CreditCard” class is shown in the following class diagram:
Explanation:
In the above diagram,
- The class name is “CreditCard”.
- The “cardNo”, “name”, and “cardExpiryDate” are attributes of “CreditCard” class.
- The “getCredit()” and “getPurchase()” are methods or operation name of “CreditCard” class.
- “getCredit()” method is used to gets the credit card amount from bank.
- “getPurchase()” is used to purchase the products by using the credit card.
Examples of objects of this “CreditCard”class:
First object:
The first object is “customer1” for this “CreditCard” class is shown below:
Explanation:
In the above diagram,
- The “customer1” object for “CreditCard” class.
- Assign the “cardNo” as “123456”, “name” as “XXXX” and “cardExpiryDate” as “03/02/2001” are the attributes of the “CreditCard” class.
Second object:
The second object is “customer2” for this “CreditCard” class is shown below:
Explanation:
In the above diagram,
- The “customer2” object for “CreditCard” class.
- Assign the “cardNo” as “234578”, “name” as “YYYY” and “cardExpiryDate” as “12/11/2022” are the attributes of the “CreditCard” class.
Third object:
The third object is “customer3” for this “CreditCard” class is shown below:
Explanation:
In the above diagram,
- The “customer3” object for “CreditCard” class.
- Assign the “cardNo” as “341579”, “name” as “ZZZZ” and “cardExpiryDate” as “01/02/2010” are the attributes of the “CreditCard” class.
Want to see more full solutions like this?
Chapter 5 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Additional Engineering Textbook Solutions
C How to Program (8th Edition)
C++ How to Program (10th Edition)
Concepts of Programming Languages (11th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
- This is the question: Design and implement a class called Bug, which represents a bug moving along a horizontal wire. The bug can only move for one unit of distance at a time, in the direction it is facing. The bug can also turn to reverse direction. For your design, create a UML Class diagram similar to Figure 5.5 on page 180 of the textbook. Note that you need to include the constructor in the methods section if you code a constructor. Bug will require a toString method to return the current position and which direction the bug is facing to the driver so it can be output.Hint: Remember that a horizontal line has a zero position in the middle with positive to the right and negative to theleft. Consider that a bug will land on the wire at some point before starting along the wire.Write an interactive test driver that instantiates a Bug, then allows the user to manipulate it with simple commands like Output (to see the position and direction), Move, Turn, Exit ... single letters work…arrow_forwardNow we are going to use the design pattern for collecting objects. We are going to create two classes, a class AmazonOrder that models Amazon orders and a class Item that models items in Amazon orders. An item has a name and a price, and the name is unique. The Item class has a constructor that takes name and price, in that order. The class also has getters and setters for the instance variables. This is the design pattern for managing properties of objects. The setName() method should do nothing if the parameter is the empty string, and the setPrice() method should do nothing if the parameter is not positive. The class also has a toString() method that returns a string representation for the item in the format “Item[Name:iPad,Price:399.99]”. For simplicity, we assume an Amazon order can have at most 5 items, and class AmazonOrder has two instance variables, an array of Item with a length of 5 and an integer numOfItems to keep track of the number of items in the…arrow_forwardYour assignment for this course is to implement a beginner level Book Management System (BMS) in Java language. BMS contains 2 classes: Bookand BookList. The Book class has the following attributes: code: a String object, that hold the book’s code. title: a String object, that hold the book’s title. qua: int variable, that hold the number of books with the same code in the library. price: a double variable, that hold the book’s price. The BookList class contains only one data member: ArrayList<Book> t. When running the program display the menu as below:1. Input & add book(s) to the end.2. Display all books.3. Search a book for given code.4. Update the book’s price for given code.5. Find the (first) max price value.6. Sort the list ascendingly by code.7. Remove the book having given code.8. Load data from file.0. Exit.Notes:(1) The book’s code must be unique in the list.(2) Display all books in format (code, title, quantity, price).(5)…arrow_forward
- Design and implement a class called Bug, which represents a bug moving along a horizontal wire. The bug can only move for one unit of distance at a time, in the direction it is facing. The bug can also turn to reverse direction. For your design, create a UML Class diagram . Note that you need to include the constructor in the methods section if you code a constructor. Bug will require a toString method to return the current position and which direction the bug is facing to the driver so it can be output Write an interactive test driver that instantiates a Bug, then allows the user to manipulate it with simple commands like Output (to see the position and direction), Move, Turn, Exit ... single letters work just fine. All output should be via the driver not methods within Bug. You should use this driver to create screenshot exhibits for a number of scenarios (e.g., output original position, move a few times, output, move a few more times, output, turn, output, move, output, etc.).…arrow_forwardIt is a Programming logic and design based questionarrow_forwardAnswer the given question with a proper explanation and step-by-step solution. please help! using the class diagram (which is provided below) you need to provide a detailed design using pseudcode representation. thank youarrow_forward
- Explain through each question about Classes and Objects in Java. What is encapsulations and why is it useful? What is an instance method and how does it differ from the static methods we learned previously? What is a mutator method? What is an accessor method? What is a constructor in a Java class? What is an implicit parameter? Please provide an entire coding example to illustrate the answer.arrow_forwardI am having trouble determining how to tackle this question: Design and implement a class called Card that represents a standard playing card. Each card has a suit and face value. For your design, create a UML Class diagram similar to Figure 5.5 on page 180 of the textbook. Note that you need to include the two constructors in the methods section (i.e., they must be coded). Hints: Represent the faces/ranks of Ace through King as 1 through 13 and the suits as 1 through 4. You need two constructors: one that receives a face/rank value and suit value as parameters, plus the default constructor where these values are randomly generated. The face/rank and suit must both have appropriate get_ and set_ methods for the numeric values plus a get_ method for the textual equivalent (e.g., getFace() might return 13 while getFaceText() would return “King”). Your toString method should return a nice representation of the values like “Ace of Spades” or “Nine of Hearts.”Write a test driver…arrow_forwardDraw the UML diagram for the classes and implement them. Write a test program that creates a Person, Student, Employee, Faculty, and Staff, and invokes their toString() methods.arrow_forward
- For this project, you will implement an email client-server simulator using the object-oriented design diagramed below. The class diagram above shows class attributes (members) and methods (operations). Operations are denoted with a plus. The diamonds indicate an aggregation relationship between the connected classes. For example, a mailbox list can have one or many mailboxes. A Mailbox can have one or many messages. You will therefore need data structures container objects (lists) to contain these types of objects, as we have seen in previous exercises. All class attributes are private unless denoted otherwise and therefore must be accessed with constructors. getters, ord setters. Constructors are a preferred way to set class attributes. Constructors, setters, getters, and toString methods can be generated by IntelliJ. Check the IntelliJ documentation for how to use the Generate feature. Messages are simultaneously sent and received. Therefore, a Message is…arrow_forwardWrite the Movie class. The UML diagram of the class is represented below: 1. Implement the class strictly according to its UML one-to-one (do not include anythingextra, and do not miss any data fields or methods). 2. Implement a MovieTest class to test the class Movie you just created.• Create two Movie objects: one using the no-args constructor and one from theconstructor with all fields.• Print the contents of both objects. Please submit a screenshot. Hint: toString()method.arrow_forwardImplement all the classes using Java programming language from the given UML Class diagram. Note: This problem requires you to submit just two classes: Person.java, User.java, Coach.java. Do NOT include "public static void main()" method inside all of these classes.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education