Question

In: Computer Science

This is Java programming question Basic sales tax is applicable at a rate of 10% on...

This is Java programming question

Basic sales tax is applicable at a rate of 10% on all goods, except books, food, and medical products that are exempt. Import duty is an additional sales tax applicable on all imported goods at a rate of 5%, with no exemptions.

When I purchase items I receive a receipt which lists the name of all the items and their price (including tax), finishing with the total cost of the items, and the total amounts of sales taxes paid. The rounding rules for sales tax are that for a tax rate of n%, a shelf price of p contains (np/100 rounded up to the nearest 0.05) amount of sales tax.

Write an application that prints out the receipt details for these shopping baskets...

Input:

Input 1:

1 book at 12.49

1 music CD at 14.99

1 chocolate bar at 0.85

Input 2:

1 imported box of chocolates at 10.00

1 imported bottle of perfume at 47.50

Input 3:

1 imported bottle of perfume at 27.99

1 bottle of perfume at 18.99

1 packet of headache pills at 9.75

1 box of imported chocolates at 11.25

Output:

Output 1:

1 book : 12.49

1 music CD: 16.49

1 chocolate bar: 0.85

Sales Taxes: 1.50

Total: 29.83

Output 2:

1 imported box of chocolates: 10.50

1 imported bottle of perfume: 54.65

Sales Taxes: 7.65

Total: 65.15

Output 3:

1 imported bottle of perfume: 32.19

1 bottle of perfume: 20.89

1 packet of headache pills: 9.75

1 imported box of chocolates: 11.85

Sales Taxes: 6.70

Total: 74.68

Solutions

Expert Solution

import java.util.Scanner;

public class Print_Reciept {
  
   static double total = 0;
   static double ttax = 0;
  
   //to get the name split the string across whitespace
   public static String getItemName(String s) {
       String[] arr = s.split(" ");
       String itemName = "";
      
       //if item is imported than name begins from the 3rd else 2nd element of array
       int i = isImported(s)? 2 : 1;
      
       //till the character "at" we can get the name of item
       while(!arr[i].equals("at")) {
           itemName += " " + arr[i];
           i++;
       }
      
       return itemName;
   }
  
   //to get the item price
   public static double getItemPrice(String s) {
       //split the give string across " at " not "at" otherwise "at" in "chocolate" will cause n error
       String[] arr = s.split(" at ");
       return Double.valueOf(arr[1].trim());
   }
  
   public static int getItemNumber(String s) {
       String[] arr = s.split(" ");
       return Integer.valueOf(arr[0].trim());
   }
  
   public static boolean isImported(String s) {
       return s.contains("imported");
   }
  
   public static boolean isExempted(String s) {
       return s.contains("book") || s.contains("pills") || s.contains("chocolate");
   }
  
   public static double calulateItemTax(String s) {
       double tax = 0.0;
      
       tax += !isExempted(s)?getItemPrice(s)*0.1 : 0.0;
      
       tax += isImported(s)?getItemPrice(s)*0.05 : 0.0;
      
       return tax;
   }
  
  
   public static void main(String[] args) {
       Scanner scanner = new Scanner(System.in);
       while(scanner.hasNextLine()) {
       String s = scanner.nextLine();
       if(s.isEmpty()) continue;
      
       double itemPrice = getItemPrice(s) + calulateItemTax(s);
      
       total += itemPrice;
       ttax += calulateItemTax(s);
      
       String itemName = getItemName(s);
       int itemCount = getItemNumber(s);
         
       System.out.println(itemCount+" "+(isImported(s)?"imported":"")+" "+itemName+" at "+itemPrice);
       System.out.flush();
       }
       scanner.close();
      
       System.out.println("Sales Tax : "+ttax);
       System.out.println("Total : "+total);
      
      
   }
  
  

}


Related Solutions

During the month of September, the following transactions occurred. The applicable sales tax rate is 6%.
During the month of September, the following transactions occurred. The applicable sales tax rate is 6%. Sept.   2   Sold merchandise on account to Sam Larson, $1,400, plus sales tax.     7   Sold merchandise on account to David Mitchell, $1,900, plus sales tax.    12   Issued credit memorandum to Sam Larson for $689, including sales tax of $39.    22   Sold merchandise on account to Matt Feustal, $500, plus sales tax.   28   Sold merchandise...
Porpoise acquires 100% of Sunfish in a tax-free business combination. The applicable income tax rate is...
Porpoise acquires 100% of Sunfish in a tax-free business combination. The applicable income tax rate is 30%. Based on the following information about the assets and liabilities of Sunfish, what amount should Porpoise record as a deferred tax balance for this acquisition for purposes of consolidation on the date of acquisition? Enter a minus sign to denote a credit (e.g.-200). Old book basis Old tax basis Fair value Cash $200,000 $200,000 $200,000 Equipment, net of depreciation 1,000,000 500,000 750,000 Patents...
Question 11. Companies Heidee and Leaudy have the same sales, tax rate, interest rate on their...
Question 11. Companies Heidee and Leaudy have the same sales, tax rate, interest rate on their debt, total assets, and basic earning power. Both companies have positive net incomes. Company Heidee has a higher debt ratio and, therefore, a higher interest expense. Which of the following statements is CORRECT? Rationalize your selection. a. Company Heidee has more net income. b. Company Heidee pays less in taxes. c. Company Heidee has a lower equity multiplier. d. Company Heidee has a higher...
Thomson Trucking has $10 billion in assets, and its tax rate is 30%. Its basic earning...
Thomson Trucking has $10 billion in assets, and its tax rate is 30%. Its basic earning power (BEP) ratio is 20%, and its return on assets (ROA) is 5%. What is its times-interest-earned (TIE) ratio? Round your answer to two decimal places.
windows forms Application using Visual Basic use visual basic 2012 Part 1: Programming – Income Tax...
windows forms Application using Visual Basic use visual basic 2012 Part 1: Programming – Income Tax Application 1.1 Problem Statement Due to upcoming end of financial year, you are being called in to write a program which will read in a file and produce reports as outlined. Inputs: The input file called IncomeRecord.txt contains a list of Annual income records of employees in a firm. Each record is on a single line and the fields are separated by spaces. The...
A question in relation of capital budgeting for a 10 year project. Say the tax rate...
A question in relation of capital budgeting for a 10 year project. Say the tax rate for below question is 35%. The buildings cost $200 000 have an estimated life of 20 years at which time their salvage value would be zero. They are to be depreciated on a straight line (prime cost) basis for tax purposes based on this life. The salvage value of the buildings after 10 years is expected to be $50,000. The equipment cost $400 000...
Consider tax rate = 10%. 2018 2019 Sales $ 5,223 $ 5,606 Depreciation $ 750 $...
Consider tax rate = 10%. 2018 2019 Sales $ 5,223 $ 5,606 Depreciation $ 750 $ 751 Cost of goods sold $ 1,797 $ 2,040 Other operational expenses $ 426 $ 356 Interest $ 350 $ 402 Cash $ 2,739 $ 2,802 Accounts receivable $ 3,626 $ 4,085 Short-term notes payable $ 529 $ 497 Long-term debt $ 9,173 $ 10,702 Net fixed assets $ 22,970 $ 23,518 Accounts payable $ 2,877 $ 2,790 Inventory $ 6,447 $ 6,625 Dividends...
Consider tax rate = 10%. 2018 2019 Sales $ 5,223 $ 5,606 Depreciation $ 750 $...
Consider tax rate = 10%. 2018 2019 Sales $ 5,223 $ 5,606 Depreciation $ 750 $ 751 Cost of goods sold $ 1,797 $ 2,040 Other operational expenses $ 426 $ 356 Interest $ 350 $ 402 Cash $ 2,739 $ 2,802 Accounts receivable $ 3,626 $ 4,085 Short-term notes payable $ 529 $ 497 Long-term debt $ 9,173 $ 10,702 Net fixed assets $ 22,970 $ 23,518 Accounts payable $ 2,877 $ 2,790 Inventory $ 6,447 $ 6,625 Dividends...
Use the following information for ABC Inc. the answer the following questions (the applicable tax rate...
Use the following information for ABC Inc. the answer the following questions (the applicable tax rate is 34%): 2017 2018 Sales 23,146,000 25,872,000 Depreciation 3,322,000 3,472,000 Cost of Goods Sold 7,958,000 9,414,000 Other Expenses 1,892,000 1,648,000 Interest 1,552,000 1,852,000 Cash 12,134,000 12,932,000 Accounts Receivable 16,068,000 18,854,000 Short-term Notes Payable 3,422,000 2,294,000 Long-term Debt 40,640,000 49,392,000 Net Fixed Assets 101,776,000 108,546,000 Accounts Payable 8,768,000 9,288,000 Inventory 28,566,000 30,576,000 Dividends 2,822,000 3,236,000 Draw up a statement of comprehensive income and statement of...
Case One (22 pts) Ferengi, Inc. is subject to an applicable corporate tax rate of 21...
Case One (22 pts) Ferengi, Inc. is subject to an applicable corporate tax rate of 21 percent, and the weighted average cost of capital (WACC) of 12.5 percent. There is no specific time constraint on investment project payback requirements. Q1: Ferengi is currently contemplating two capital investment plans. Plan A: the upgrade of an information system with an installed cost of $2,400,000. The upgrade system will be depreciated straight-line to zero over the project’s five-year life, at the end of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT