Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Only Please ********************PROVIDED CODE********************************** // You will make the change(s) necessary for this class to work correctly with the completed test harness public class

Java Only Please image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

********************PROVIDED CODE**********************************

// You will make the change(s) necessary for this class to work correctly with the completed test harness

public class Beverage extends Produce { private double price; private int count; public Beverage() { super( ); } public Beverage( String type, double price, int count ) { super( type ); setPrice( price ); setCount( count ); } public final void setPrice( double price ) { this.price = price; } public final void setCount( int count ) { this.count = count; } public final double getPrice( ) { return price; } public final int getCount( ) { return count; } public String toString( ) { String taxStatus; if( chkTaxable( ) ) taxStatus = "is"; else taxStatus = "is not"; return String.format( "%s The price is $%.2f each for %d.%nExtended Price: $%.2f.", super.toString( ), getPrice( ), getCount( ), calcExtendedPrice( ) ); } }

*************************************************************************

public class GiftCard implements RingOut { private String provider; private double amount; public GiftCard() { } public GiftCard( String provider, double amount ) { setProvider( provider ); setAmount( amount ); } public final void setProvider( String provider ) { this.provider = provider; } public final void setAmount( double amount ) { this.amount = amount; } public final String getProvider( ) { return provider; } public final double getAmount( ) { return amount; } public String toString( ) { String taxStatus; if( chkTaxable( ) ) taxStatus = "is"; else taxStatus = "is not"; return String.format( "%nThe %s to %s has a value of $%.2f. The total cost is $%.2f, including tax.", getClass( ).toString( ).substring( getClass( ).toString( ).indexOf( " " ) + 1 ), getProvider( ), getAmount( ), calcExtendedPrice( ) ); } }

*********************************************************************************

// You will make the change(s) necessary for this class to work correctly with the completed test harness

public class Meat extends Produce { private double price; private double weight; public Meat() { super( ); } public Meat( String type, double price, double weight ) { super( type ); setPrice( price ); setWeight( weight ); } public final void setPrice( double price ) { this.price = price; } public final void setWeight( double weight ) { this.weight = weight; } public final double getPrice( ) { return price; } public final double getWeight( ) { return weight; } public String toString( ) { String taxStatus; if( chkTaxable( ) ) taxStatus = "is"; else taxStatus = "is not"; return String.format( "%s The price is $%.2f per pound and the amount is %.2f pounds.%nExtended Price: $%.2f.", super.toString( ), getPrice( ), getWeight( ), calcExtendedPrice( ) ); } }

**************************************************************************

// You will make the change(s) necessary for this class to work correctly with the completed test harness

public abstract class Produce { private String product; public Produce( ) { } public Produce( String type ) { setProduct( type ); } public final void setProduct( String type ) { product = type; } public final String getProduct( ) { return product; } public String toString( ) { return String.format( "%nThe %s item is %s.", getClass( ).toString( ).substring( getClass( ).toString( ).indexOf( " " ) + 1 ), getProduct( ) ); } }

***************************************************************

public interface RingOut { double taxRate = .0825; default public boolean chkTaxable( ) { String sprClassStr = getClass( ).getSuperclass( ).toString( ); int location = sprClassStr.indexOf( " " ); String classStr = sprClassStr.substring( location + 1 ); if( classStr.matches( "Produce" ) ) { return false; } else { return true; } } public double calcExtendedPrice( ); }

*********************************************************

// You will make the change(s) necessary for this class to work correctly with the completed test harness

public class TestRingOut { // Declare an array to hold objects for testing // The array must be declared as 'private static' in order to work properly private static ....... ; public static void main(String[] args) { loadArray( ); // Write the statement for the enhanced for loop here // Do not change the body of the loop for ............ /* * Make NO CHANGES to code below this block comment! */ { determineTaxStatus( oneItem ); System.out.printf( "%s", oneItem.toString( ) ); } } // end main private static void loadArray( ) { shoppingCart[0] = new Meat( "Beef", 6.24, 2.41 ); shoppingCart[1] = new Beverage( "Water", 1.17, 2 ); shoppingCart[2] = new GiftCard( "Walmart", 120.00 ); shoppingCart[3] = new Meat( "Pork", 4.14, 4.68 ); shoppingCart[4] = new Beverage( "Apple Juice", 2.76, 3 ); shoppingCart[5] = new GiftCard( "H-E-B", 150.00 ); } // end loadArray private static void determineTaxStatus( RingOut item ) { if( item.chkTaxable( ) ) System.out.printf( "%n%nThe next item is taxable at a rate of %.4f%%.", item.taxRate ); else System.out.printf( "%n%nThe next item is not taxable." ); } } // end TestRingOut

**********************************************************************

END CODE

Thanks!

General Information This lab will require you to make code changes to support implementing an interface. Review the material in the text regarding interfaces before beginning Background Your users have asked you to begin building a shopping cart system for a grocery store. Right now, there aren't many classes to be included in the application, but these few classes (in unrelated hierarchies) must all be able to calclae an extended price and must allhave access to the local sales tax rate. You will need to make changes in classes Produce, Meat, Beverage, and GiftCard to support the interface RingOut (provided to you). You will also need to add two lines of code to the test harness (TestRingout) Given UML describing the classes and interface Complete code for the RingOut interface Code for the following classes Produce Meat Beverage GiftCard Code for the test harness: TestRingOut Expected output from the test harness Task: Make the necessary modifications Requirements RingOut The complete interface code has been provided to you. This interface includes one attribute, taxRate which will be available to all objects implementing the interface. It also includes a default method chkTaxable, with a concrete definition provided. The availability of default methods in interfaces is an enhancement new to SE8 of Java. You will make no changes to the interface code Produce The Produce class must be modified to use the interface RingOut. No interface methods need to be defined in this class. Meat You will need to provide code for a method to support the RingOut interface. Make no other changes in the class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Antipatterns Avoiding The Pitfalls Of Database Programming

Authors: Bill Karwin

1st Edition

1680508989, 978-1680508987

More Books

Students also viewed these Databases questions

Question

Discuss the disadvantages of activity-based costing.

Answered: 1 week ago

Question

b. Why were these values considered important?

Answered: 1 week ago