Question: Create a Java class hierarchy to represent oil volumes in barrels, gallons and pints using the UML diagrams below. Create abstract class Volume and classes

Create a Java class hierarchy to represent oil volumes in barrels, gallons and pints using the UML diagrams below. Create abstract class Volume and classes Volume1, Volume2.

Create a Java class hierarchy to represent oil volumes in barrels, gallons

  • add and subtract() are invoked as a.add(b) and a.subtract(b). Both add() and subtract() must return Volume1s or Volume2s that have been converted
  • toPints() returns the this object as a measurement in pints
  • convert() converts this into a form where the number of gallons is greater than or equal to 0 and less than 42, number of pints is greater than or equal to 0 and less than 8
  • You can add extra methods if needed or exclude an inherited method that is not overridden.

Volume > Comparable +toPints(): int +convert() +compareTo(other: T): int Volume 1 -barrels: int -gallons: int +Volume1() +Volume1(b: int, 8: int) +Volume1(v: Volume1) +setGallons(g: int): void +setBarrels(b: int): void +getGallons(): int +getBarrels(): int +add(v: Volumel): Volumel +subtract(v: Volumel): Volume 1 +toPints(): int +convert(): void +toString(: String +compareTo(v: Volume1): int Volume 2 -pints: int +Volume2() +Volume 2(b: int, g: int, P: int) +Volume 2 (v: Volume) +setPints(p: int): void +getPints(): int +add(v: Volume 2): Volume 2 +subtract(v: Volume2): Volume 2 +toPints(): int +convert(): void +toString(): String +compareTo(v: Volumel): int

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!