1 Attachment(s)
i need help with java source code
Scenario
A local company “Aaron Technology Sdn Bhd” has encounters a problem on providing their customer
with a proper receipt for the purchase item. This is because all the information is store in the text file
called customer.txt which is hardly understand by their customer. The sample file is shown below:
Text file format: <Receipt No.> <Payment Term> <Customer Name> <Item No.> <Item Name> <Quantity> <Price>
Therefore, your task is to generate the customer receipt in the form of formatted text file and save it as
receipts.txt. The output of the file is shown below:
Develop java program that can be use to extract the data from “customer.txt” file and transform it to
become a readable receipt format as shown above
sample output: on attachment
Re: i need help with java source code
Please post the code here that you are having problems with and the questions you have about the problems.
Please post all information about the problem on the forum. No attachments.
Re: i need help with java source code
Code java:
import java.util.*;
import java.io.*;
import java.text.*;
public class Beta
{
public static void main(String[] args) throws FileNotFoundException
{
String Customer, ItemNo, ItemName;
int Quantity, ReceiptNo;
double Total, GST, Price, Price2;
String CASH = "";
String CREDIT = "";
String Payment = "";
String Payment;
Date d = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("d/MMM/yyyy");
Scanner readFile = new Scanner (new FileReader("E:\\New folder (2)\\customer.txt"));
PrintWriter writeFile = new PrintWriter("E:\\New folder (2)\\Receiptmizan1.txt");
while(readFile.hasNext())
{
Payment = "CREDIT";
ReceiptNo = readFile.nextInt();
Payment = readFile.next();
Customer = readFile.next();
ItemNo = readFile.next();
ItemName = readFile.next();
Quantity = readFile.nextInt();
Price = readFile.nextDouble();
System.out.println(Payment2);
System.out.println(Payment);
if (Payment.equals(Payment2))
{
System.out.println("The strings are equal");
} else
{
System.out.println("The strings are unequal");
}
DecimalFormat f = new DecimalFormat("#.00");
System.out.println(f.format(Price));
Price2 = Price;
if (Payment.equals(Payment2))
{
Price = Price * 90/100;
}
writeFile.println();
writeFile.println();
writeFile.println(" Aaron Technology Sdn Bhd ");
writeFile.println();
writeFile.println(" Bangunan Aziz dan Anak-anak ");
writeFile.println(" Block 'A' Tingkat 1, No.4 ");
writeFile.println(" Jalan Adam, Simpang 234 ");
writeFile.println(" AST-Beyonf, Kuala Hawa ");
writeFile.println(" Brunei CH134 ");
writeFile.println();
writeFile.println();
writeFile.println();
writeFile.println(" RECEIPT 00" + ReceiptNo + "" );
writeFile.println(" ==================================== ");
writeFile.printf(" Customer Name: %s %n" ,Customer );
writeFile.println(" Date : " + dateFormat.format(d));
writeFile.println(" Payment term : " +Payment);
if (Payment.equals(Payment))
{
writeFile.println(" Discount rate = 10%");
}
writeFile.println(" Item No. : " + ItemNo );
writeFile.println(" ===================================== ");
writeFile.println(" " + ItemName );
Total = Price Quantity;
writeFile.println(" " + Quantity + " x " + f.format(Price2) + " $" + f.format(Total) + "");
writeFile.println(" Total Amount");
GST = Total * 105/100;
writeFile.println(" Total include GST of 5% : " + f.format(GST) + "");
writeFile.println();
writeFile.println("---------------CUT HERE---------------");
}
writeFile.println();
writeFile.println("Receipt.txt is successfully created");
readFile.close();
writeFile.close();
}
}
--- Update ---
fail to compile and print the output txt file need help plzz.....
here are the customer txt file:
001 CASH Ahmad PD80512 Pendrive-8GB 2 65
002 CASH Raymond CP71112 Desktop-i7 1 1765
003 CREDIT Syukri PD40112 Pendrive-4GB 10 20
004 CASH Halimah PD40112 Pendrive-4GB 10 20
005 CREDIT Osman OMW0511 Optical-Mouse(Wireless) 2 38.50
006 CREDIT Huzaimi MWS0211 Monitor-27"inch(LED) 1 260
007 CASH Maya KBW0610 Keyboard(Wireless) 5 35.70
008 CASH Chen MSU0309 Mini-Speaker(USB) 1 10.60
009 CREDIT Krishnan IPM1112 Ipad-Mini(WIFI) 2 680
010 CREDIT Nuraqmal SGN1212 Galaxy-Note(10.1) 1 799.90
1 Attachment(s)
Re: i need help with java source code
Attachment 1688from the question... and how to make the txt output print.. in middle as in the picture
Re: i need help with java source code
Please post your questions about the code.
If you are getting errors, copy the full text of the error messages and post them.
Re: i need help with java source code
Hi Daruga , i found the mistakes
wrong: 1
String Payment = "";
String Payment
in the main method don't declare two variables with same name and should be initialize before using. like
pls change:
String Payment="";
String Payment1="";
wrong: 2
Total = Price Quantity;
pls change :
Total =Price * Quality;
modified code:
------------------
>>>>>>>>>>> Code removed
Re: i need help with java source code