0% found this document useful (0 votes)
5 views4 pages

GH

The Java program reads product information from a file and allows users to input product IDs and quantities to calculate the total cost, including VAT and discounts based on user selection. It handles user interactions for purchasing products, displaying the purchase summary, and calculating the final amount due after applying any discounts. The program continues to prompt for additional purchases until the user decides to terminate it.

Uploaded by

andrewpogi950
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

GH

The Java program reads product information from a file and allows users to input product IDs and quantities to calculate the total cost, including VAT and discounts based on user selection. It handles user interactions for purchasing products, displaying the purchase summary, and calculating the final amount due after applying any discounts. The program continues to prompt for additional purchases until the user decides to terminate it.

Uploaded by

andrewpogi950
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

import java.util.

*;
import java.io.*;
import java.text.*;
public class fileread{
public static void main(String []args)throws IOException{

Scanner scnr = new Scanner(System.in);


DecimalFormat dcfm = new DecimalFormat("###,###.00");
Date date = new Date();
String DATE_FORMAT = "MM/dd/yyyy";
SimpleDateFormat sidf = new
SimpleDateFormat(DATE_FORMAT);
String strDateFormat = "HH:mm:ss";
SimpleDateFormat sdf = new
SimpleDateFormat(strDateFormat);

//>>Variables
String productID = "";
String data="";
String answer="";
String product[];
int check=0;

String str="",Discount="";
String strQuanTT="";
int QuanTT=0;
int counter=0;
double VAT=0, less=0;
double amount=0;
double Dproduct=0;
double PWD=0;
double PWD15=0;
double Senior=0, Suki=0,Senior20=0, Suki10=0;
double payment=0;
double amountDue=0;
double change=0;

FileInputStream fis = new FileInputStream


("Productinfo_.txt");
DataInputStream dis = new DataInputStream(fis);
BufferedReader br = new BufferedReader
(new InputStreamReader(dis));

System.out.println
("********************************************");

while(true){
System.out.print("Enter Product ID : ");
productID = scnr.next();

while((data = br.readLine())!=null){
product = data.split(", ");
if(productID.equals(product[0])){
System.out.println("Product name: " + product[1]);
System.out.println("Unit price: " + product[2]);

check = 1;

System.out.print("Enter quantity: ");


strQuanTT = scnr.next();
QuanTT = Integer.parseInt(strQuanTT);

Dproduct = Double.parseDouble(product[2]);

amount = amount + (Dproduct*QuanTT);


counter = counter + QuanTT;

str = str +product[1]+"\t\t"+product[2]+"\t\t"+QuanTT+ "\t\


t"+dcfm.format(amount)+"\n";

}
}

if(check == 0){
System.out.println("Records Not Found!!!");}
check = 0;

fis.getChannel().position(0);
System.out.print
("Do yuo want to buy another Product? [ Yes/No ]: ");
answer = scnr.next();

if(answer.equalsIgnoreCase("No")){
System.out.println("The Program Will Terminate\n");

System.out.println
("********************************************");

System.out.print("\nDate : " + sidf.format(date)+"\t\t\t");


System.out.println("Time : " + sdf.format(date));

System.out.println("Description");
System.out. println
("_________________________________________");
System.out.println("Prodoct"+"\t\t"+"Price"+"\t\t"+
"Quantity"+"\t"+"Total cost");

System.out.println(str);

System.out. println
("_________________________________________");

System.out.print("products bought: "+counter+"\n");


System.out.print("\n°°°[ 1 ]None \n°°°[ 2 ] Senior Sitizen \n°°°[ 2 ] PWD \
n°°°[ 1 ] Suki card\n");
System.out.print("\nSelect Type of Discount: ");
Discount = scnr.next();

VAT = amount*0.12;
less = amount-VAT;

System.out.println("VAT: "+dcfm.format(VAT)
+"\t\t\t\t\t\t"+"["+dcfm.format(amount)+"]");
System.out.println("Less Vat: "+dcfm.format(less));

//--->> Discount
if (Discount.equalsIgnoreCase ("1")){
System.out.println
("Type of Discount: None ");}
else if (Discount.equalsIgnoreCase ("2")){
System.out.println
("Type of Discount: Senior Sitizen");}
else if (Discount.equalsIgnoreCase ("3")){
System.out.println
("Type of Discount: PWD");}
else {
System.out.println
("Type of Discoun:t Suki card: ");}

if (Discount.equalsIgnoreCase ("1")){
System.out.println
("Discount amount: ");}
else if (Discount.equalsIgnoreCase ("2")){
Senior = amount+VAT;
Senior20 = Senior*0.20;
System.out.println
("Discount amount: "+dcfm.format(Senior20));}
else if (Discount.equalsIgnoreCase ("3")){
PWD = amount+VAT;
PWD15 = PWD*0.15;
System.out.println
("Discount amount: "+dcfm.format(PWD15));}
else {
Suki = amount+VAT;
Suki10 = Suki*0.10;
System.out.println
("Discount amount: "+dcfm.format(Suki10));}

System.out.print("\n");

//--->> Amount Due


if (Discount.equalsIgnoreCase ("1")){
amountDue = amount+VAT;
System.out.println
("Amount due: "+dcfm.format(amountDue));}
else if (Discount.equalsIgnoreCase ("2")){
amountDue = Senior-Senior20;
System.out.println
("Amount due: "+dcfm.format(amountDue));}
else if (Discount.equalsIgnoreCase ("3")){
amountDue = PWD-PWD15;
System.out.println
("Amount due: "+dcfm.format(amountDue));}
else {
amountDue = Suki-Suki10;
System.out.println
("Amount due: "+dcfm.format(amountDue));}

do {
System.out.print("Payment: Php ");
payment = scnr.nextDouble();
if (payment < amountDue){
System.out.println("your payment is insufficient 💸 🚫");}
} while(payment< amountDue);

{
{
change = (payment-amountDue);
if (Discount.equalsIgnoreCase ("1")){
System.out.print("Change: Php "+dcfm.format(change));}
else if (Discount.equalsIgnoreCase ("2")){
System.out.print("Change: Php "+dcfm.format(change));}
else if (Discount.equalsIgnoreCase ("3")){
System.out.print("Change: Php "+dcfm.format(change));}
else {
System.out.print("Change: Php "+dcfm.format(change));}

System.exit(0);

}
}
}
}
}
}

You might also like