Advertisement
cynthiarez

IMPORTANT. DO: Unfinished Lab

Sep 10th, 2019
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. package Java;
  2. import java.io.FileNotFoundException;
  3. import java.io.FileReader;
  4. import java.io.PrintWriter;
  5. import java.util.Scanner;
  6.  
  7. import javax.swing.*;
  8.  
  9.  
  10. public class Lab {
  11.  
  12. public static void main(String[] args) throws FileNotFoundException {
  13.  
  14. PrintWriter waterbill = new PrintWriter("cust.txt");
  15. PrintWriter usage = new PrintWriter("custbill.txt");
  16.  
  17. String lastname = JOptionPane.showInputDialog("Enter last name");
  18. String address = JOptionPane.showInputDialog("Enter Address");
  19.  
  20. int prevusage = Integer.parseInt (JOptionPane.showInputDialog("Enter previous month's usage"));
  21. double currusage = Double.parseDouble (JOptionPane.showInputDialog("Enter current month's usage"));
  22.  
  23.  
  24. waterbill.println(lastname + " " + address + " " + prevusage + " " + currusage);
  25. waterbill.close();
  26.  
  27. Scanner infile = new Scanner (new FileReader("cust.txt"));
  28. String fname, faddress;
  29. int fprevusage;
  30. double fcurrusage;
  31.  
  32. fname = infile.next();
  33. faddress = infile.next();
  34. fprevusage = infile.nextInt();
  35. fcurrusage = infile.nextDouble();
  36.  
  37. double usagecalc = fcurrusage - fprevusage;
  38.  
  39. JOptionPane.showMessageDialog (null, "The total usage is " +usagecalc);
  40.  
  41. if (faddress.equalsIgnoreCase("Maa"))
  42. {
  43. double costperunit = 4.5;
  44.  
  45. }
  46.  
  47. else if (faddress=="Buhangin")
  48. {
  49. double costperunit = 5.00;
  50. }
  51. else if (faddress =="Sasa")
  52. {
  53. double costperunit = 3.50;
  54. }
  55. else {
  56. double costperunit = 2.00;
  57. }
  58.  
  59. usage.println(usagecalc);
  60.  
  61.  
  62. usage.close();
  63.  
  64.  
  65. // Incomplete / DO: if else, determine the cost per unit depending on address and calculate billing (billing = usage * costperunit)
  66.  
  67. // Costperunit value
  68. // Maa = 4.50 / Buhangin = 5.00 / Sasa = 3.50 / any others = 2.00
  69.  
  70. // DO: Using printwriter, write the following to custbill.txt == <lastname> <address> <usage> <billing>
  71.  
  72. }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement