🔒 Closed Java Programming patulong

Status
Not open for further replies.

Spaghetto

Honorary Poster
Guys patulong po ako uhm paano po iisahin yung Total at subtotal, yung sa total may price na po sha sa db at may formula para sa total gusto ko po sana i connect yung subtotal para di na po mag lagay ang user ng input patulong po baguhan lang po ako sa java language






Code:
package htc.quiz;

import java.text.NumberFormat;
import java.util.Scanner;


public class LineItemApp {
    public static void main(String[] args) {
        System.out.println("Welcome to the Line Item Calculator");
        System.out.println();
        String customerType=null;
                Scanner sc = new Scanner(System.in);
                double subtotal;
                double discountAmount;
                final double SALES_TAX_PCT = .05;
                String choice = "y";
                while (choice.equalsIgnoreCase("y")) {
                   
                String productCode = Console.getString("Enter product code: ");
            Product p = ProductDB.getProduct(productCode);
                        int quantity = Console.getInt("Enter quantity: ", 0, 1000);
            double vat = Console.getDouble("Enter Vat rate: ");
                       
                    System.out.print("Enter Costumer Type: ");
                    customerType=sc.next();
                    System.out.print("Enter Subtotal: ");
                    subtotal= sc.nextDouble();


                    double discountPercent=0;
                    switch (customerType) {
                    case "r":
                    case "R":
                    if (subtotal < 100) {
                            discountPercent = 0.0;
                    }else if(subtotal >= 100 && subtotal < 250){
                            discountPercent = .1;
                    }else if(subtotal >= 250) {
                            discountPercent = .2;
                    }
                    break;
                    case "c":
                    case "C":
                    if(subtotal < 250) {
                            discountPercent = .2;
                    }else if(subtotal >= 250) {
                            discountPercent = .3;
                    }
                    break;
                    default:
                            discountPercent = .1;
                            break;
                    }
       
           
            discountAmount = subtotal*discountPercent;
                        double totalBeforeTax = subtotal-discountAmount;
                        double salesTax = totalBeforeTax*SALES_TAX_PCT;
                        double total = totalBeforeTax + salesTax;
                       
            LineItem lineItem = new LineItem(p, quantity, vat);
                       
                        NumberFormat currency = NumberFormat.getCurrencyInstance();
                        NumberFormat percent = NumberFormat.getPercentInstance();
                       
            System.out.println();
            System.out.println("LINE ITEM");
            System.out.println("Code: " + p.getCode());
            System.out.println("Description: " + p.getDescription());
            System.out.println("Price: " + p.getFormattedPrice());
            System.out.println("Quantity: " + lineItem.getQuantity());
                        System.out.println("Vat: " + lineItem.getVat());
            System.out.println("Total: " + lineItem.getTotalFormatted() + "\n");
                        System.out.println("Subtotal: "+currency.format(subtotal));
                        System.out.println("Discount Percent: "+percent.format(discountPercent));
                        System.out.println("Discount Amount: "+currency.format(discountAmount));
                        System.out.println("Total Before Tax: "+currency.format(totalBeforeTax));
                        System.out.println("Sales Tax: "+currency.format(salesTax));
                        System.out.println("Total: "+currency.format(total));
            choice = Console.getString("Continue? (y/n): ");
            System.out.println();

                        }
                }
        }
}

1631022269523.png
 
Status
Not open for further replies.

About this Thread

  • 0
    Replies
  • 537
    Views
  • 1
    Participants
Last reply from:
Spaghetto

Trending Topics

Online now

Members online
371
Guests online
2,498
Total visitors
2,869

Forum statistics

Threads
2,308,033
Posts
29,182,688
Members
1,192,757
Latest member
johnmeyer67
Back
Top