In: Computer Science
Use the UML tool to draw a UML class diagrambased on the descriptions provided below.
The diagram should be drawn with a UML tool
It should include all the classes listed below and use appropriate arrows to identify the class relationships
Each class should include all the described attributes and operations but nothing else
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).
Price Class Diagram:
GroceryItem Class Diagram:
Price and GroceryItem combined class diagram with relation:
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: