C Secure h nwacc-bb9.blackboard.com/bbcswebdav/pid-1277200 dt-content d-5976396
ID: 3785265 • Letter: C
Question
C Secure h nwacc-bb9.blackboard.com/bbcswebdav/pid-1277200 dt-content d-5976396 courses/201702-2 6-PROG-1003-003/ Homework Homework 1.pdf Create a new program called Cart.cpp Following the examples, we wrote in class, create variables to represent an item in a shopping cart: an item name, item type, and item price. Item name should be a string, item type should be a char, and item price should be a double. Allow the user to enter three separate shopping cart items with each item being a name, type, and price. The three valid types are FNX display the types to the user. We will use F for food items, N for normal non-food items, and X for special items. You do not need to worry about checking this you can assume the user will enter valid data. Assume a tax rate of 8.25% Assume the item name will only be one word Calculate a subtotal, tax, and total. Display to the user a list of the items entered along with type and price Display the subtotal, tax amount, and total. Allow the user to enter the amount to pay (assume the amount will be equal to or more than what is due). Display the change due to the user. Assume the user will enter valid data. DO NOT worry about the category at this time, just accept the input and display it. In a few weeks we will use the categories to calculate taxes on the different items. The point of this exercise is to use some of the arithmetic operations, and to start thinking about compound entities like an item in a shopping cart that are represented with multiple values. Also, you might run into problems computing percentages. Consider carefully the data types that you are using and how the operators work with different data types. Required Documentation You will need to include a document for your test cases. You can use the template provided on Blackboard. You must have at least three test cases with screen shots of each test case Submitting your Program You will submit this assignment on blackboard. You are allowed one submission. You will need to submit your Cart.cpp file and your documented test cases in a word (.docx) file, RFT, or Excel (.xslx). 2:02 AM 31/2017 R2Explanation / Answer
public class Cart
{
public static void main(String[] args)
{
ShoppingCart cart = new ShoppingCart();
Product pez = new Product("Cherry PEZ refill (12 pieces)");
cart.addItem(pez, 5);
Product dispenser = new Product("Yoda PEZ dispenser");
cart.addItem(dispenser);
}
}
public class ShoppingCart {
public void addItem(Product item, int quantity)
{
System.out.printf("Adding %d of %s to the cart.%n", quantity, item.getName());
}
public class Product {
private String mName;
public Product(String name)
{
mName = name;
}
public String getName()
{
return mName;
}
}
public void addItem(Product item)
{
addItem(item,1);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.