Cashregister class that can be used with the retailitem clas

Assignment Help C/C++ Programming
Reference no: EM13161795

Write a CashRegister class that can be used with the RetailItem class that you wrote in Part 1. The CashRegister class should simulate 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. In addition, the class should have the following methods:
• The getSubtotal method should return the subtotal of the sale, which is the quantity multiplied by the price. This method must get the price from the RetailItem object that was passed as an argument to the constructor.
• The getTax method should return the amount of sales tax on the purchase. The sales tax rate is 6 percent of a retail sale.
• The getTotal method should return the total of the sale, which is the subtotal plus the sales tax.

Demonstrate the class in a program that asks the user for the quantity of items being purchased and then displays the sale's subtotal, amount of sales tax and total.


And here is my RetailItem Class I wrote....
import java.io.*;
import java.util.Scanner; //Needed for Scanner Class


public class RetailItem {

private String description; // Name of item
private int units; // Amount of units
private double price; // Price of each unit
public RetailItem()
{

}
// Counstructor with arguements
public RetailItem(String des, int u, double p)
{
description = des;
units = u;
price = p;
}
/**
*This setDescription Method sets the item description
*@param des The String stored in the description field.
*/

public void setDescription (String des)
{
description=des;

}
/**
*This setPrice Method sets the price of the item.
*@param p The value stored in the price field.
*/
public void setPrice (double p)
{
price=p;
}
/**
*This setUnits Method is the number of units of a
*specific item.
*@param u The value stored in the units field.
*/
void setUnits(int u)
{
units = u;
}
/**
*The getUnits method returns the number of units.
*@return The Value in the Units field.
*/
public int getUnits()
{
return units;
}
/**
*The getDescription method returns the description of
*the item.
*@return The despription in the description field.
*/
public String getDescription()
{
return description;
}
/**
*The getPrice method returns the items price.
*@return The value in the price field.
*/
public double getPrice()
{
return price;
}

}
/**
*This program demostrates the RetailItem Class
*/
class RetailTest
{
public static void main (String [] args)
{
String str ="Shirt";
//Creates new RetailItem objects.
RetailItem r1=new RetailItem ("Jacket", 12, 59.95);
RetailItem r2=new RetailItem ("Designer Jeans", 40, 34.95);
RetailItem r3 =new RetailItem ();

//function call to set values
r3.setDescription(str);
r3.setUnits(20);
r3.setPrice(24.95);

//Output of data
System.out.println("\tDescription\t\tUnits on Hand\t\tPrice");
System.out.println("Item#1\t"+r1.getDescription()+ " \t\t\t "+r1.getUnits()
+ " \t\t\t " + r1.getPrice());
System.out.println("Item#2\t"+r2.getDescription()+ " \t "+r2.getUnits()
+ "\t\t\t\t" + r2.getPrice());
System.out.println("Item#3\t"+r3.getDescription()+ " \t\t\t "+r3.getUnits() +
" \t\t\t " + r3.getPrice());

//Exit program
System.exit(0);
}

Reference no: EM13161795

Questions Cloud

Design your application according to the considerations : Design your application according to the considerations described above.  For example, you must use functions that have the specified signatures, and arrays that have the specified declarations. They are
Write a program that asks a user for a file name and prints : Write a program that asks a user for a file name and prints the number of characters, words, and lines in that file.
The rpn calculator program : The RPN calculator program should read the RPN expression as an entire line from stdin.Input will consist of a single line. After completing the evaluation of the expression, the program should print the contents of the entire stack, starting with th..
Function which correctly sorts three : Write an x8086 HLA Assembly language program that implements a function which correctly sorts three parameters and returns a boolean value in AL which should be set to true if any swaps were performed to sort the sequence in increasing order.
Cashregister class that can be used with the retailitem clas : Write a CashRegister class that can be used with the RetailItem class that you wrote in Part 1. The CashRegister class should simulate the sale of a retail item. It should have a constructor that accepts a RetailItem object as an argument.
Shows the users name and program name : Java program, the program has a page that shows the users name and program name. a second jpanel that shows 4 buttons (circle square rectangle and oval) the problem i am having is that my program is not dropping where i click and the shapes are not s..
The program should not accept quantities : Input Validation: The program should not accept quantities, or wholesale or retail costs, less than 0. The program should not accept dates that the programmer deter- mines are unreasonable.
Perform an insertion sort on the file pointed : Using only the local data already supplied in FileSort, perform an insertion sort on the file pointed to by fd. Use lseeks for this; do not try to create any sort of array or list. An array-based version of insertion is supplied for your reference.
Using matlab and for loops : Using MATLAB and for loops, provide an animation that follows the below steps: Start with a square at the origin with each side being 5 units long. Imagine someone kicked the box and animate it moving on a projectile motion trajectory. Hint: look at ..

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Function that returns the height of a binary tree

Write a function called getHeight() that returns the height of a given binary tree - CptS 122 Write a function called countSmallerThan() that returns the number of nodes whose values are smaller than the supplied input paramter

  A series of one-digit non-negative numbers

Write a program that asks the user to enter a series of one-digit non-negative numbers

  Write c program to add two integers and prints out average

Write a C program that prompts for a variable number of integers, adds them up, and prints out the average. The user will enter either an integer to be averaged.

  Draws a single level for a "rogue­like" computer game

You will write a program that draws a single level for a "Rogue­like" computer game. The program will parse a line of input text from an input file (room.txt), use the parsed text to determine the shape of the room and its contents and then draw the ..

  Definitions of the class circularlinkedlist

Write the definitions of the class circularLinkedList and its member functions. (You may assume that the elements of the circular linked list are in ascending order.)

  Pros and cons of choosing two servers

Classify the two alternatives in terms of what type of application architecture they use. b. Outline the pros and cons of the two alternatives and make a recommendation to Fred about which is better.

  Write a function that takes an integer array

1. Write a function that takes an integer array and the array's size as parameters. The function will check if the array is sorted. If it is, it will return a 1. If it is not sorted it will return 0. The function should not  sort the array.

  Two types of sporting teams

Select two types of sporting teams and de?ne subclasses for them. These classes shouldinherit from a base team class such as that created in Exercise 1. Include uniquecharacteristics about the sport.

  What constructors do and when they are executed

Explain what constructors do and when they are executed. Explain the two types of constructors. Provide an example class that includes both types of constructor functions and demonstrate how an object would be instantiated using both types of constru..

  Compute a program that calculates three resistance inputs

C language, compute a program that calculates three RESISTANCE inputs, and gives you the total resistance in OHMS. Like this, the total resistance is _____ ohms. These are three parallel circuits so the formula would be (1/R1 + 1/ R 2 +  1/ R 3 )  -1

  Illustrate example from ansi c programming language

Illustrate example from ANSI C programming language, without using nested procedures, to show the fact that "assignment-by-sharing in conjunction with quasi-dynamic object binding

  Principle ofsuperposition to determine that system is linear

Apply the principle of superposition to determine whether the following systems are linear. Sketch what the plot of the function looks like.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd