Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Java;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.PrintWriter;
- import java.util.Scanner;
- import javax.swing.*;
- public class Lab {
- public static void main(String[] args) throws FileNotFoundException {
- PrintWriter waterbill = new PrintWriter("cust.txt");
- PrintWriter usage = new PrintWriter("custbill.txt");
- String lastname = JOptionPane.showInputDialog("Enter last name");
- String address = JOptionPane.showInputDialog("Enter Address");
- int prevusage = Integer.parseInt (JOptionPane.showInputDialog("Enter previous month's usage"));
- double currusage = Double.parseDouble (JOptionPane.showInputDialog("Enter current month's usage"));
- waterbill.println(lastname + " " + address + " " + prevusage + " " + currusage);
- waterbill.close();
- Scanner infile = new Scanner (new FileReader("cust.txt"));
- String fname, faddress;
- int fprevusage;
- double fcurrusage;
- fname = infile.next();
- faddress = infile.next();
- fprevusage = infile.nextInt();
- fcurrusage = infile.nextDouble();
- double usagecalc = fcurrusage - fprevusage;
- JOptionPane.showMessageDialog (null, "The total usage is " +usagecalc);
- if (faddress.equalsIgnoreCase("Maa"))
- {
- double costperunit = 4.5;
- }
- else if (faddress=="Buhangin")
- {
- double costperunit = 5.00;
- }
- else if (faddress =="Sasa")
- {
- double costperunit = 3.50;
- }
- else {
- double costperunit = 2.00;
- }
- usage.println(usagecalc);
- usage.close();
- // Incomplete / DO: if else, determine the cost per unit depending on address and calculate billing (billing = usage * costperunit)
- // Costperunit value
- // Maa = 4.50 / Buhangin = 5.00 / Sasa = 3.50 / any others = 2.00
- // DO: Using printwriter, write the following to custbill.txt == <lastname> <address> <usage> <billing>
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement