Question

In: Computer Science

Find a receipt from any purchase you made, and try to represent it in a Java...

Find a receipt from any purchase you made, and try to represent it in a Java program. Make sure to use the most appropriate data type for each of these items

  • List all items purchased
  • Price of each item
  • Subtotal
  • Total Tax (if any)
  • Total (Subtotal + tax)
  • Any company information at the bottom or top of receipt as well

Solutions

Expert Solution

import java.util.ArrayList;

class Item {
   private String name;
   private double price;
   private double tax;

   public Item(String aName, double aPrice, double aTax) {
       super();
       name = aName;
       price = aPrice;
       tax = aTax;
   }

   public String getName() {
       return name;
   }

   public void setName(String aName) {
       name = aName;
   }

   public double getPrice() {
       return price;
   }

   public void setPrice(double aPrice) {
       price = aPrice;
   }

   public double getTax() {
       return tax;
   }

   public void setTax(double aTax) {
       tax = aTax;
   }

   public String toString() {
       return name + " :" + price;
   }
}

public class Receipt {
   public static void main(String[] args) {
       ArrayList<Item> list = new ArrayList<Item>();
       list.add(new Item("Soap", 10, 0.05));
       list.add(new Item("Brush", 16, 0.05));
       list.add(new Item("Tv", 100, 0.1));
       double total = 0;
       double tax = 0;
       for (Item i : list) {
           total += i.getPrice();
           tax += i.getPrice() * i.getTax();
       }
       System.out.println("No of Items : " + list);
       System.out.println("Sub total : " + total);
       System.out.println("Tax : " + tax);
       System.out.println("Total : " + (tax + total));
   }
}


Related Solutions

Case Customers make purchases from AMT by emailing their purchase orders. On receipt of a customer’s...
Case Customers make purchases from AMT by emailing their purchase orders. On receipt of a customer’s purchase order, a Sales Clerk prepares a Sales Order. In doing so, he accesses an authorised price list to determine the price that is to be charged, and inputs the quantities, product descriptions, product codes and delivery requirements. Sales Orders are prenumbered and in triplicate. The Sales Clerk then performs a credit check by comparing the value of the sale with the customer’s credit...
Consider a major purchase you have made in the last 5 years. On the internet find...
Consider a major purchase you have made in the last 5 years. On the internet find the company’s corporate sustainability report. Read through it and identify and list what values are important to the company and how they do or don’t demonstrate their commitment to social responsibility. Do your findings make a difference to you and how you feel about this company and if you would continue to deal with them.
JAVA FRACTIONS QUESTION: You will create a Fraction class in Java to represent fractions and to...
JAVA FRACTIONS QUESTION: You will create a Fraction class in Java to represent fractions and to do fraction arithmetic. To get you used to the idea of unit testing, this homework does not require a main method. You can create one if you find it useful, however, we will not be grading or even looking at that code. You should be comfortable enough with the accuracy of your test cases that you do not need to use print statements or...
The purchase of treasury stock ________. requires recognition on the income statement of any gain made...
The purchase of treasury stock ________. requires recognition on the income statement of any gain made on the purchase always decreases net income does not require recognition on the income statement of any gain made on the purchase requires recognition on the income statement of any loss incurred on the purchase Buzz Corporation issued $50,000 worth of 10-year, 8% bonds for $48,359.66. The 8% is the ________. stated rate market rate future rate face value The risk associated with debt...
Java:    Find a pattern that will match any string that is --  at least 6 characters...
Java:    Find a pattern that will match any string that is --  at least 6 characters long, -- and begins with a letter or number (\w) -- and contains at least one non-letter and non-number (\W).
Try to get in touch with any person you know( it could be your relative or...
Try to get in touch with any person you know( it could be your relative or friend) who undergone or undergoing a special diet. Describe what it is made of and for what specific condition it is. You may cite specific food items and other details pertinent to the diet.
Java Question here. Need to write a program that will check ANY operating system and find...
Java Question here. Need to write a program that will check ANY operating system and find out OS name and then write that info to a file in the data directory. here is where I am so far: public void writeOSName() { // TODO write the name of the operating system running this code to a file // in the data directory called os.txt // The file has to be written in the data directory of this project // Use...
JAVA: (Find yourself in PI) In this assignment you will find a numeric string (if it...
JAVA: (Find yourself in PI) In this assignment you will find a numeric string (if it exists) within a file containing the first 1 million characters of the decimal expansion of PI. The numeric string in question is a 6 character string representing your birth date. E.g., if your birth date is January 1, 1984, then the string is 010184. The file containing the first 1 million characters of the decimal expansion of PI is named pidigits.txt and is available...
Do you find any of the Victorians significantly different in themes and concerns from the Romantics,...
Do you find any of the Victorians significantly different in themes and concerns from the Romantics, or is all this categorizing by era not working for you?
You are considering the purchase of an apartment complex. The following assumptions are made: • The...
You are considering the purchase of an apartment complex. The following assumptions are made: • The purchase price is $1,150,000. • Potential gross income (PGI) for the first year of operations is projected to be $195,000. • PGI is expected to increase at 4 percent per year. • 3% vacancies are expected. • Operating expenses are estimated at 30 percent of effective gross income. Capital expenditures are estimated at 10 percent of effective gross income. • The market value of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT