1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kykrilka [37]
3 years ago
13

The cash register program will have items. For each item, the name and cost are saved. For a transaction, it will accept any num

ber of items (not known in advance) and any number of payments of different payment types (not known in advance). For each transaction, it calculates the total including a 7% sales tax and keeps prompting for a payment until the total has been paid. It also determines if any change is required. Thus, a transaction is responsible for calculating the amount of money that needs to be paid, accepting money, and generating a receipt. A receipt holds information about a transaction so that it can display how much each item cost, how the transaction was paid for, etc. (see example outputbelow).Payment type includes CASH, DEBIT_CARD, CREDIT_CARDandCHECK. Each payment consists of an amount and payment type
Hints
1. All fields should be private.
2. The PaymentType class should be an enum class with values: CASH, DEBIT_CARD, CREDIT_CARD, CHECK
3. Payment type information should not print the enum directly
4. Use final to store the transaction for each receipt.
5. Output:
A. The values for subtotal, tax, total, and payment information are all aligned. You can achieve this by using the tab character '\t' in your Strings. The item lines do not need to be aligned.
B. Do not worry about only using 2 decimal places. Let Java decide how many decimal places to use.
6. Create a main class to house the main method. In the main method, create some items, a transaction, and display the receipt.
A. Example outputs
Example: Pay everything with one payment
Transaction listing the items and asking for payment:
Item 1: apple: 0.5
Item 2: pear: 0.75
Item 3: pineapple: 0.75
Total: 2.14
Please enter payment type.
1. Cash
2. Debit card
3. Credit card
4. Check
2
Enter the amount to pay with this type.
2.14
Total after payment: 0.0
Receipt printed:
apple: 0.5
pear: 0.75
pineapple: 0.75
----------------------------------------------------------
Subtotal:
Tax:
Total:
Debit:
Change: 2.0 0.14 2.14 2.14 0.0
Example: Paying with multiple payments and payment type
Item 1: refrigerator: 800.71
Total: 856.7597000000001
Please enter payment type.
1. Cash
2. Debit card
3. Credit card
4. Check
1
Enter the amount to pay with this type.
400
Total after payment: 456.75970000000007
Please enter payment type.
1. Cash
2. Debit card
3. Credit card
4. Check
2
Enter the amount to pay with this type.
475
Total after payment: -18.240299999999934
refrigerator: 800.71
3
Subtotal: 800.71
Tax: 56.04970000000001
Total: 856.7597000000001
Cash: 400.0
Debit: 475.0
Change: 18.240299999999934
Example: Using the same payment type multiple times
Item 1: apple: 0.5
Item 2: pear: 0.75
Item 3: pineapple: 0.75
Total: 2.14
Please enter payment type.
1. Cash
2. Debit card
3. Credit card
4. Check
1
Enter the amount to pay with this type.
1.25
Total after payment: 0.8900000000000001
Please enter payment type.
1. Cash
2. Debit card
3. Credit card
4. Check
1
Enter the amount to pay with this type.
10.50
Total after payment: -9.61
apple: 0.5
pear: 0.75
pineapple: 0.75
Subtotal: 2.0
Tax : 0.14
Total: 2.14
Cash: 1.25
Cash: 110.5
Change: 9.61
Computers and Technology
1 answer:
harkovskaia [24]3 years ago
7 0

Answer:

Explanation:

package sample;

import java.util.Scanner;

public class Main extends newOrder{

   public static void main(String[] args) {

       newOrder order = new newOrder();

       order.newOrder("apple", 0.5);

       order.newOrder("pear", 0.75);

       order.newOrder("pineapple", 0.75);

       double newTotal = order.getTotal();

       order.printItems();

       order.printTotal();

       while (newTotal != 0) {

           Scanner in = new Scanner(System.in);

           System.out.println("Please enter payment type.\n" + "Cash \nDebit card \nCredit card \nCheck");

           String paymentType = in.nextLine();

           System.out.println("Enter the amount to pay with this type: ");

           double amount = in.nextDouble();

           newTotal -= amount;

           System.out.println("Total after payment: " + newTotal);

       }

       System.out.println("Receipt Printed:");

       order.printItems();

       order.printSubtotal();

       System.out.println("Tax: 7%");

       order.printTotal();

   }

}

------------------------------------------------------------------------------------------------------------

package sample;

public enum PaymentType {

   CASH, DEBIT_CARD, CREDIT_CARD, CHECK

}

-----------------------------------------------------------------------------------------------------------

package sample;

import java.util.HashMap;

class newOrder {

   private String name;

   private double cost;

   private double total;

   private double subtotal;

   HashMap<String, Double> itemList = new HashMap<>();

   public void newOrder(String name, double cost) {

       this.name = name;

       this.cost = cost;

       this.total += cost;

   }

   

   public void printItems() {

       for (String i: itemList.keySet()) {

           System.out.println( i + ": \t" + itemList.get(i));

       }

   }

   public double getTotal() {

       return (total * 1.07);

   }

   public void printSubtotal() {

       for (double i : itemList.values()) {

           subtotal += i;

       }

       System.out.println("Subtotal: " + subtotal);

   }

   

   public void printTotal() {

       double total = subtotal * 1.07;

       System.out.println("Total: " + total);

   }

}

You might be interested in
Create a flowchart that assigns a counselor to a student.
Nataly [62]
Please Help! Unit 6: Lesson 1 - Coding Activity 2
Instructions: Hemachandra numbers (more commonly known as Fibonacci numbers) are found by starting with two numbers then finding the next number by adding the previous two numbers together. The most common starting numbers are 0 and 1 giving the numbers 0, 1, 1, 2, 3, 5...
The main method from this class contains code which is intended to fill an array of length 10 with these Hemachandra numbers, then print the value of the number in the array at the index entered by the user. For example if the user inputs 3 then the program should output 2, while if the user inputs 6 then the program should output 8. Debug this code so it works as intended.

The Code Given:

import java.util.Scanner;

public class U6_L1_Activity_Two{
public static void main(String[] args){
int[h] = new int[10];
0 = h[0];
1 = h[1];
h[2] = h[0] + h[1];
h[3] = h[1] + h[2];
h[4] = h[2] + h[3];
h[5] = h[3] + h[4];
h[6] = h[4] + h[5];
h[7] = h[5] + h[6];
h[8] = h[6] + h[7]
h[9] = h[7] + h[8];
h[10] = h[8] + h[9];
Scanner scan = new Scanner(System.in);
int i = scan.nextInt();
if (i >= 0 && i < 10)
System.out.println(h(i));
}
}
4 0
3 years ago
Read 2 more answers
Write a c program to count the total number of commented characters and words in a c file taking both types of c file comments (
Tanzania [10]

#include<stdio.h>

#include<stdlib.h>

int comment1(FILE *fp)

{

   char ch;

   int count=0;

   while(fscanf(fp,"%c",&ch)!=EOF)

   {

       if(ch=='\n')

       {

           return count;

       }

       count++;

   }

   return count;

}

int comment2(FILE *fp)

{

   char ch;

   int count=0;

   while(fscanf(fp,"%c",&ch)!=EOF)

   {

       if(ch=='*')

       {

           fscanf(fp,"%c",&ch);

           if(ch=='/')

           {

               return count;

           }

           count++;

       }

       count++;

   }

   return 0;

}

int main()

{

   printf("Enter the file name:");

   char s[1000],ch,ch1;

   scanf("%s",s);

   FILE*fp;

   fp = fopen(s,"r");

   int count=0;

   while(fscanf(fp,"%c",&ch)!=EOF)

   {

       if(ch=='\"')

       {

           while(fscanf(fp,"%c",&ch)!=EOF)

           {

               if(ch=='\"')

               {

                   break;

               }

               if(ch=='\\')

               {

                   fscanf(fp,"%c",&ch);

               }

           }

       }

       else if(ch=='/')

       {

           fscanf(fp,"%c",&ch);

           if(ch=='/')

           {

               count += comment1(fp);

           }

           else if(ch=='*')

           {

               count += comment2(fp);

           }

       }

   }

   printf("%d\n",count);

   return 0;    

}

3 0
3 years ago
Read 2 more answers
What is the process called when programmers look for and fix errors in code?
AveGali [126]

Answer:

d

Explanation:

7 0
3 years ago
Read 2 more answers
What is DNS and how does it work?​
sertanlavr [38]
Dns stands for : domain name system
It works because people translate domain names to IP addresses so browsers can load internet resources.
6 0
3 years ago
Which of the following is NOT a cost typically associated with owning a car?
Arturiano [62]
A. fuel ; when you but a car you aren't buying the gas to go in it 
3 0
4 years ago
Other questions:
  • It is either snoming or below freezing
    10·1 answer
  • . Write a statement that throws an IllgalArgumentException with the error message Argument cannot be negative.
    11·1 answer
  • What is a propriety database
    10·1 answer
  • Write the header for a function addOne that accepts a single integer reference parameter and returns nothing. Name the parameter
    5·1 answer
  • What is an audit trial
    8·1 answer
  • Which of the following is a way to prevent wastes from contaminating the environment? A) Use absorbent pads to collect floor was
    11·2 answers
  • Which of the following is NOT a valid declaration for a character string?
    8·1 answer
  • Match each of the following network types to its definition: I. HAN II. MAN III. LAN IV. PAN V. WAN A. confined to a small geogr
    10·1 answer
  • Can you plz type down a word.
    11·2 answers
  • State two skills to be used to access information from the internet in order to avoid unwanted materials.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!