Question

Write a CashRegiste class that can be used with the Retntailtem class that you wrote in the module4. The cashRegister class s

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

Note: To run below program, you need to add RetailItem program and the main structure as written in question made in module 4.

import java.util.Scanner;
import java.text.DecimalFormat;
public class CashRegister
{
private RetailItem item;
private double price;
private double subTotal;
private double salesTax;
private double total;
private final double TAX_RATE=0.06;
private int quantity;
private double retail;public static class retailitem
{
private String description;
private int unitsOnHand;
private double price;
public retailitem()
{

}
public retailitem(String description, int unitsOnHand, double price)
{
this.description = description;
this.unitsOnHand = unitsOnHand;
this.price = price;
}
public String getDescription()
{
return description;
}
public int getUnits()
{
return unitsOnHand;
}
public double getPrice()
{
return price;
}

public retailitem copy()
{
retailitem copy = new retailitem(description,unitsOnHand,price);
return copy;
}

public String toString()
{
return "Item is" + description + "There are"
+ unitsOnHand + " " + "left in the store" +
"It currently is selling for" + " " + price;
}

}
/**
Constructor
@param RetailItem The item to purchase.
@param quantity The number of items.
@param price The price of item.
*/

public CashRegister(RetailItem i, int q)
{
//Create a copy of the object referenced by
//Retail Item.
this.item = new RetailItem(i);
quantity = q;
}
/**
getItem method
@return A copy of the RetailItem object
for the item being purchased.
*/

public RetailItem getRetailItem()
{

//Retun a copy of the object referenced by item
RetailItem myRetailItem = new RetailItem("Designer Jeans", 40, 34.95);
CashRegister myCashRegister = new CashRegister(myRetailItem, 1);
return new RetailItem();
}

/**
The getPrice method rerurns the item's price.
@return The item's price.
*/
public double getPrice()
{
return price;
}

/**
getUnit method
@return The number of items being puchased.
*/

public int getQuantity()
{
return quantity;
}

/**
getsubtotal method
@return The subtotal of the item puchased
*/

public double getSubTotal()
{
subTotal = item.getPrice() * quantity;
return subTotal;
}

/**
getSalesTax method
@return The sales tax of the items puchased
*/

public double getTax()
{
salesTax = this.getSubTotal() * TAX_RATE;
return salesTax;
}

/**
getTotal method
@return The total of the items puchased
*/
public double getTotal()
{
total = this.getSubTotal() + this.getTax();
return total;
}
}

Kindly revert for any queries

Add a comment
Know the answer?
Add Answer to:
Write a CashRegiste class that can be used with the Retntailtem class that you wrote in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in java PART ONE ======================================= Below is the "RetailItem" class definition that we used in Chapter 6. Write a "CashRegister" class that leverages this "Ret...

    in java PART ONE ======================================= Below is the "RetailItem" class definition that we used in Chapter 6. Write a "CashRegister" class that leverages this "RetailItem" class which simulates the sale of a retail item. It should have a constructor that accepts a "RetailItem" object as an argument. The constructor should also accept an integer that represents the quantity of items being purchased. Your class should have these methods: getSubtotal: returns the subtotal of the sale, which is quantity times price....

  • Complete the CashRegister class by implementing the methods and adding the correct attributes (characteristics) as discussed...

    Complete the CashRegister class by implementing the methods and adding the correct attributes (characteristics) as discussed in class. Once complete, test the class using the CashRegisterTester class. Make sure you have 3 total items in the cash register. I have two classes, the first is CashRegisterTester below: public class CashRegisterTester { public static void main(String[] args) { //Initialize all variables //Construct a CashRegister object CashRegister register1 = new CashRegister(); //Invole a non-static method of the object //since it is non-static,...

  • I need help with my homework please. I should write this program in C++ language and...

    I need help with my homework please. I should write this program in C++ language and use Inventory.h file (header file), Inventory.cpp file (implementation file), and main.cpp file (main program). This is the program: Demonstrate the class in a driver program. Input validation, don’t accept negative values for item number, quantity, or cost. 6. Inventory Class Design an Inventory class that can hold information and calculate data for items ma retail store's inventory. The class should have the following private...

  • Use exceptions to correct errors and please don't use stacks 2. Write a class called ShoppingBag...

    Use exceptions to correct errors and please don't use stacks 2. Write a class called ShoppingBag to keep track of items purchased. The ShoppingBag contains a summary of an order. It will implement the Retail interface (given below) and will need some additional methods to place items in the bag and to output the bags current status. ShoppingBag contains the total cost of items purchased (before tax), the total after tax, the number of items in the bag, and the...

  • Develop a program to emulate a purchase transaction at a retail storeThis program will have two...

    Develop a program to emulate a purchase transaction at a retail storeThis program will have two classes, a Lineltem class and a Transaction class. The Lineltem class will represent an individua line item of merchandise that a customer is purchasing. The Transaction class will combine several Lineltem objects and calculate an overall total price for the line item within the transaction. There will also be two test classes, one for the Lineltem class and one for the Transaction class. Design...

  • C++ Retailltem.h, Retailltem.cpp, Store.h, Store.cpp, and Driver.cpp. Description: Write a set of programs that holds data...

    C++ Retailltem.h, Retailltem.cpp, Store.h, Store.cpp, and Driver.cpp. Description: Write a set of programs that holds data about items in a retail store. Your submission should include 5 files, Retailltem.b, Retailltem.cpp, Store, Store.cpp, and Driver.cpp 1. Retailltem class: The class should have three member variables • description (a string, represent the item's name. A name contains space) quantity (an int, represent how many current available) price (a double, item's price) Member Functions Constructor with default argument get Description getQuantity getPrice setDescription...

  • Programming Language: Java Write a class named ColoredRectangle that extends the Rectangle class (given below). The...

    Programming Language: Java Write a class named ColoredRectangle that extends the Rectangle class (given below). The ColoredRectangle class will have an additional private String field named Color. The ColoredRectangle class should have four constructors: a no-arg constructor; a three-arg constructor; a two-arg constructor that accepts a Rectangle object and a color; and a copy constructor. The ColoredRectangle class should have an Equals and toString methods. The ColoredRectangle class should have mutators and accessors for all three fields. public class Rectangle...

  • JAVA Use the class, Invoice, provided to create an array of Invoice objects. Class Invoice includes...

    JAVA Use the class, Invoice, provided to create an array of Invoice objects. Class Invoice includes four instance variables; partNumber (type String), partDescription (type String), quantity of the item being purchased (type int0, and pricePerItem (type double). Perform the following queries on the array of Invoice objects and display the results: Use streams to sort the Invoice objects by partDescription, then display the results. Use streams to sort the Invoice objects by pricePerItem, then display the results. Use streams to...

  • Write the following program in Java using Eclipse. A cash register is used in retail stores...

    Write the following program in Java using Eclipse. A cash register is used in retail stores to help clerks enter a number of items and calculate their subtotal and total. It usually prints a receipt with all the items in some format. Design a Receipt class and Item class. In general, one receipt can contain multiple items. Here is what you should have in the Receipt class: numberOfItems: this variable will keep track of the number of items added to...

  • Java 7 Write a constructor for the MightyByte class so it can accept a String argument...

    Java 7 Write a constructor for the MightyByte class so it can accept a String argument and set the bits field. Complete the for loop in the getDecimalValue method. class Main { public static void main(String[] args) { MightyByte myByte = new MightyByte("00000101"); System.out.println(myByte.getDecimalValue());    } } class MightyByte { private String bits;    // write the constructor here    public int getDecimalValue() { int decimalValue = 0; int intValue; int power = 7; for (int i = 0; i...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT