Question

In: Computer Science

Use the UML tool to draw a UML class diagrambased on the descriptions provided below....

Use the UML tool to draw a UML class diagrambased on the descriptions provided below.

  1. The diagram should be drawn with a UML tool

  2. It should include all the classes listed below and use appropriate arrows to identify the class relationships

  3. Each class should include all the described attributes and operations but nothing else

  4. Each constructor and method should include the described parameters and return types - no more and no less

Please do one of the following in Java


Descriptions of a Price
Because of the inherent imprecision of floating-point numbers, we represent the price by storing two values: dollarsand cents. Both are whole numbers.

Both values are needed in order to create a new Price.
Once a Price has been created, it can no longer be changed. However, it provides two getters: one to access the value of dollars, the other to access the value of cents.

Descriptions of a GroceryItem
Grocery items have a name (text) and aprice.  
In order to create a new GroceryItem, both a name and a price need to be provided.
Once a GroceryItem has been created, the name can no longer be changed, but the price can be updated as needed. GroceryItem includes getters for each of the attributes (fields).

Solutions

Expert Solution

Price Class Diagram:

  • Price class having two attributes dollars and cents of int type.
  • Two constructors. One default constructor and another parametrized constructor.
  • createNewPrice method to create price using dollars and cents. It returns the price value of float type.
  • getDollars and getCents methods to access value of dollars and cents.

GroceryItem Class Diagram:

  • Two attributes. name with String type and price of Price type from above Price class.
  • Two constructors. One is default and another parametrized constructor.
  • createNewGroceryItem method with name and price attributes and return name of grocery item as String type.
  • As name should not be changed, no setter method for name.
  • setPrice to update value for price.
  • getPrice to access value of price.
  • getName to access name.

Price and GroceryItem combined class diagram with relation:

  • GroceryItem uses Price. It is depicted using arrow as shown in below diagram.
  • 1 GroceryItem can have single price which is depicted by (1 -> 1) class relation in diagram below.

Price Program in Java:

public class Price {

int dollars;

int cents;

public Price() {

super();

}

public Price(int dollars, int cents) {

super();

this.dollars = dollars;

this.cents = cents;

}

float createNewPrice(int dollars, int cents){

return dollars + cents;

}

public int getDollars() {

return dollars;

}

public int getCents() {

return cents;

}

}

Screenshot:

GroceryItem Program in Java:

public class GroceryItem {

String name;

Price price;

public GroceryItem() {

super();

}

public GroceryItem(String name, Price price) {

super();

this.name = name;

this.price = price;

}

String createNewGroceryItem(String name, Price price){

return name;

}

public void setPrice(Price price) {

this.price = price;

}

public Price getPrice() {

return price;

}

public String getName() {

return name;

}

}

Screenshot:


Related Solutions

Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {...
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {       public int month;    public int day;    public int year;    public Date(int month, int day, int year) {    this.month = month;    this.day = day;    this.year = year;    }       public Date() {    this.month = 0;    this.day = 0;    this.year = 0;    } } //end of Date.java // Name.java public class Name...
Draw a UML diagram that describes a class that will be used to describe a product...
Draw a UML diagram that describes a class that will be used to describe a product for sale on Glamazon.com. The product has a name, a description, a price, ratings by many customers (1 to 5 stars), and a group of customer comments. New products have no ratings or comments by customers, but do have a name, description and price. The price can be changed and more customer ratings and comments can be added. A global average rating of all...
create the UML Diagram to model a Movie/TV viewing site. Draw a complete UML class diagram...
create the UML Diagram to model a Movie/TV viewing site. Draw a complete UML class diagram which shows: Classes (Only the ones listed in bold below) Attributes in classes (remember to indicate privacy level, and type) No need to write methods Relationships between classes (has is, is a, ...) Use a program like Lucid Cart and then upload your diagram. Each movie has: name, description, length, list of actors, list of prequals and sequals Each TV Show has: name, description,...
Java: Translate the Student class from the code provided to UML, e.g., -----------------------------_ | Student |...
Java: Translate the Student class from the code provided to UML, e.g., -----------------------------_ | Student | ------------------------------ | -lastName: String | | -firstName: String | ----------------------------- Java Code: public class Student { private String lName; private String fName; private int age; private double gpa; public Student(String lname, String fname, int age, double gpa);    public String lname();    public String fname();    public int age(); public double gpa(); public String toString()      {          return lName+ " " + fName+...
Exercise: Three UML class diagrams are given below. Class Employee is the superclass and the other...
Exercise: Three UML class diagrams are given below. Class Employee is the superclass and the other two classes, Manager and Programmer, are subclasses of Employee. Employee - name: String # salary: double + Employee( ) + setEmployee( String, double ): void + getName( ): String + getSalary( ): double + print( ): void Manager Programmer - numEmps: int - language: String + Manager( ) + setManager( String, double, int ): void + getNumEmps( ): int + getSalary( ): double +...
1. Use the information provided below to draw a pedigree of the Alex’s family and to...
1. Use the information provided below to draw a pedigree of the Alex’s family and to answer the questions stated below: A) Alex’s family pedigree consists of three generations (I-1: Alex; I-2: Cynthia; II-1: James; II-2: Mary; II-3: Bobby; II-4: Joe; II-5: Linda; II-6: Evelyn; II-7: Kate, II-8: John; III-1: Mike; III-2: Tina; III-3: Gina; III-4: Angel; III-5; Dave. B) Alex and Cynthia are the grandparents of Mike, Tina, Gina, Angel and Dave. C) Mike, Tina and Gina are the...
Below are descriptions of micronutrients not discussed in class. You may use any reference material available...
Below are descriptions of micronutrients not discussed in class. You may use any reference material available to you to identify the names of these compounds. Write the name of the compound in the space below the description. You will receive one point for each nutrient you name correctly. Remember, these were not discussed in class, but you may have heard of them in discussions of nutrition or in nutrition related articles. Good Luck!! This one is usually identified as a...
Please perform reverse engineering to compose a UML class diagram for the provided java code /*...
Please perform reverse engineering to compose a UML class diagram for the provided java code /* Encapsulated family of Algorithms * Interface and its implementations */ public interface IBrakeBehavior { public void brake(); } public class BrakeWithABS implements IBrakeBehavior { public void brake() { System.out.println("Brake with ABS applied"); } } public class Brake implements IBrakeBehavior { public void brake() { System.out.println("Simple Brake applied"); } } /* Client that can use the algorithms above interchangeably */ public abstract class Car {...
Given the following UML class diagram, implement the class as described by the model. Use your...
Given the following UML class diagram, implement the class as described by the model. Use your best judgment when implementing the code inside of each method. +---------------------------------------------------+ | Polygon | +---------------------------------------------------+ | - side_count : int = 3 | | - side_length : double = 1.0 | +---------------------------------------------------+ | + Polygon() | | + Polygon(side_count : int) | | + Polygon(side_count : int, side_length : double) | | + getSides() : int | | + setSides(side_count : int) | |...
Draw UML diagram Define a class named Document that contains a member variable of type string...
Draw UML diagram Define a class named Document that contains a member variable of type string named text that stores any textual content for the document. Create a function named getText that returns the text field and a way to set this value. Next, define a class for Email that is derived from Document and that includes member variables for the sender , recipient , and title of an e-mail message. Implement appropriate accessor and mutator functions. The body of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT