// Declare data fields: a String named customerName, // an int named numItems, and // a double named totalCost. // Your code here... // Implement the default contructor. // Set the value of customerName to "no name" // and use zero for the other data fields. // Your code here... // Implement the overloaded constructor that // passes new values to all data fields. // Your code here... // Implement method getTotalCost to return the totalCost. // Your code here... // Implement method buyItem. // // Adds itemCost to the total cost and increments // (adds 1 to) the number of items in the cart. // // Parameter: a double itemCost indicating the cost of the item. public void buyItem(double itemCost) { // Your code here... } // Implement method applyCoupon. // // Apply a coupon to the total cost of the cart. // - Normal coupon: the unit discount is subtracted ONCE // from the total cost. // - Bonus coupon: the unit discount is subtracted TWICE // from the total cost. // - HOWEVER, a bonus coupon only applies if the total cost // in the cart is at least $100. (If the total cost is // less than $100, then the unit discount is subtracted // only ONCE from the total cost.) // - Consider the case when the type is neither 'n' nor 'b' // and output a message, "Invalid coupon." // // Parameters: // - a char to indicate the type of coupon // ('n' for normal, 'b' for bonus) // - a double that indicates the unit discount amount. // // Does not return a value. public void applyCoupon(char type, double unitDiscount) { // Your code here... } // Implement method applySalesTax. // // Parameter: a double (in the range 0.0 to 100.0) to // indicate a percentage. For example, 25% will be passed // as 25.0, NOT 0.25. // // Adds sales tax, based on the percentage passed, // to the total cost. // // Example: If the shopping cart currently contains $150.00 // and the percentage is 10, then the resulting amount // will go up to $165.00 (since 10% of $150 is $15, // so $150 + $15 = $165. // // Does not return a value. public void applySalesTax(double percentage) { // Your code here... // Implement method printInfo. // // Prints out the customer name, the number of // items, and the total cost. // // The total cost is formatted with 2 decimal places. // Output is formatted on one line separated by dashes // in the format: name - items - $totalCost // // Does not return a value. public void printInfo() { // Your code here... public class Z_RunSC { public static void main( String args[] ) { // FAMILY 1 (John and Luke): // John and Luke live in Nevada where there // is NO sales tax. // John has a normal coupon for $12 // Luke has a normal coupon for $20 // // 1. Declare two ShoppingCart objects (john and luke) // and initialize their name to "John" and "Luke', // number of items to 0, and cost to 0.... // 2a. Use method buyItem to buy 4 items for John // costing: $120, $55, $92, and $77.... // (Hint: You will have to call the method more than once.) // 2b. Use method buyItem to buy 2 items for Luke // costing: $44 and $18.50 // (Same hint as 2a.) // 3. Use method applyCoupon to apply John's $12 coupon // to his cart and apply Luke's $20 coupon to his cart.... // 4. Print out the information for both John and Luke // using the printInfo method.... // 5. Calculate and output the total amount spent by // FAMILY 1. (Output the total amount to two decimal // places.) Hint: Use the get method to get the final // cost for both John and Luke and sum them up.... System.out.println(); // Use the following information to complete #6-#10. // // FAMILY 2 (Peter, Paul, and Mary): // Peter, Paul, and Mary have finished shopping: // Peter bought 3 items costing $88.00 total // Paul bought 5 items costing $100.00 total // Mary bought 4 items costing $50.00 total // Peter and Paul live in California where the sales tax is 8% // Mary lives in Texas where the sales tax is 5% // Paul has a bonus coupon with unit discount $11.25 // Mary has a bonus coupon with unit discount $15.75 // Peter does not have any coupons. // // 6. Declare and initialize three objects (peter, // paul, and mary). Make sure each shopping cart // reflects what they have already bought.... // 7. Apply coupons for Paul and Mary // 8. Apply sales tax for Peter, Paul, and Mary // 9. Print out the information for all three of them.... // 10. Calculate and output the total amount spent by // the whole family (to 2 decimal places)....

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question


// Declare data fields: a String named customerName,
// an int named numItems, and
// a double named totalCost.
// Your code here...

// Implement the default contructor.
// Set the value of customerName to "no name"
// and use zero for the other data fields.
// Your code here...


// Implement the overloaded constructor that
// passes new values to all data fields.
// Your code here...

// Implement method getTotalCost to return the totalCost.
// Your code here...

// Implement method buyItem.
//
// Adds itemCost to the total cost and increments
// (adds 1 to) the number of items in the cart.
//
// Parameter: a double itemCost indicating the cost of the item.
public void buyItem(double itemCost)
{
// Your code here...

}

// Implement method applyCoupon.
//
// Apply a coupon to the total cost of the cart.
// - Normal coupon: the unit discount is subtracted ONCE
// from the total cost.
// - Bonus coupon: the unit discount is subtracted TWICE
// from the total cost.
// - HOWEVER, a bonus coupon only applies if the total cost
// in the cart is at least $100. (If the total cost is
// less than $100, then the unit discount is subtracted
// only ONCE from the total cost.)
// - Consider the case when the type is neither 'n' nor 'b'
// and output a message, "Invalid coupon."
//
// Parameters:
// - a char to indicate the type of coupon
// ('n' for normal, 'b' for bonus)
// - a double that indicates the unit discount amount.
//
// Does not return a value.
public void applyCoupon(char type, double unitDiscount)
{
// Your code here...

}

// Implement method applySalesTax.
//
// Parameter: a double (in the range 0.0 to 100.0) to
// indicate a percentage. For example, 25% will be passed
// as 25.0, NOT 0.25.
//
// Adds sales tax, based on the percentage passed,
// to the total cost.
//
// Example: If the shopping cart currently contains $150.00
// and the percentage is 10, then the resulting amount
// will go up to $165.00 (since 10% of $150 is $15,
// so $150 + $15 = $165.
//
// Does not return a value.
public void applySalesTax(double percentage)
{
// Your code here...


// Implement method printInfo.
//
// Prints out the customer name, the number of
// items, and the total cost.
//
// The total cost is formatted with 2 decimal places.
// Output is formatted on one line separated by dashes
// in the format: name - items - $totalCost
//
// Does not return a value.
public void printInfo()
{
// Your code here...

public class Z_RunSC
{
public static void main( String args[] )
{
// FAMILY 1 (John and Luke):
// John and Luke live in Nevada where there
// is NO sales tax.
// John has a normal coupon for $12
// Luke has a normal coupon for $20
//
// 1. Declare two ShoppingCart objects (john and luke)
// and initialize their name to "John" and "Luke',
// number of items to 0, and cost to 0....

// 2a. Use method buyItem to buy 4 items for John
// costing: $120, $55, $92, and $77....
// (Hint: You will have to call the method more than once.)

// 2b. Use method buyItem to buy 2 items for Luke
// costing: $44 and $18.50
// (Same hint as 2a.)

// 3. Use method applyCoupon to apply John's $12 coupon
// to his cart and apply Luke's $20 coupon to his cart....

// 4. Print out the information for both John and Luke
// using the printInfo method....

// 5. Calculate and output the total amount spent by
// FAMILY 1. (Output the total amount to two decimal
// places.) Hint: Use the get method to get the final
// cost for both John and Luke and sum them up....

System.out.println();

// Use the following information to complete #6-#10.
//
// FAMILY 2 (Peter, Paul, and Mary):
// Peter, Paul, and Mary have finished shopping:
// Peter bought 3 items costing $88.00 total
// Paul bought 5 items costing $100.00 total
// Mary bought 4 items costing $50.00 total
// Peter and Paul live in California where the sales tax is 8%
// Mary lives in Texas where the sales tax is 5%
// Paul has a bonus coupon with unit discount $11.25
// Mary has a bonus coupon with unit discount $15.75
// Peter does not have any coupons.
//
// 6. Declare and initialize three objects (peter,
// paul, and mary). Make sure each shopping cart
// reflects what they have already bought....

// 7. Apply coupons for Paul and Mary

// 8. Apply sales tax for Peter, Paul, and Mary

// 9. Print out the information for all three of them....

// 10. Calculate and output the total amount spent by
// the whole family (to 2 decimal places)....

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
User Defined DataType
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage