Advertisement
cynthiarez

PrintWriter (Study!(incomplete))

Sep 9th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. package PrintWriter;
  2. import java.io.FileNotFoundException;
  3. import java.io.FileReader;
  4. import java.io.PrintWriter;
  5. import javax.swing.JOptionPane;
  6. import java.util.*;
  7.  
  8. public class PrintWriterPrac {
  9.  
  10. public static void main(String[] args) throws FileNotFoundException {
  11.  
  12.  
  13. PrintWriter practice = new PrintWriter ("Stud.txt");
  14. PrintWriter practice2 = new PrintWriter ("Studbal.txt");
  15.  
  16.  
  17. String name = JOptionPane.showInputDialog("Enter Name");
  18. int ID = Integer.parseInt (JOptionPane.showInputDialog("Enter Student ID"));
  19. double tuition = Double.parseDouble (JOptionPane.showInputDialog("Enter tuition"));
  20.  
  21. // Below is what inputs the information to the txt file
  22.  
  23. practice.println(name + " " + ID + " " + tuition);
  24.  
  25. practice.close(); // Important = Close always so it inputs to the text file
  26.  
  27. // Scanner below is to read/Scan the input above (so it can be used to output in JOption/console)
  28.  
  29. Scanner infile = new Scanner (new FileReader("Stud.txt")); // Scanner file name "Stud.txt" is the same as PrintWriter name, this means
  30. //...that the Scanner will read from the PrintWriter's text content
  31. String fname;
  32. int fID;
  33. double ftuition;
  34.  
  35. fname = infile.next();
  36. fID = infile.nextInt();
  37. ftuition = infile.nextDouble();
  38.  
  39. double balance = ftuition - 1750; //b
  40.  
  41. practice2.println(balance);
  42.  
  43. JOptionPane.showMessageDialog(null,"Name: " + fname + "\nStudent ID: " + fID + "\nTuition: " + tuition);
  44.  
  45. practice2.close();
  46.  
  47.  
  48. // PROBLEM
  49.  
  50. // Find out how to change dialog box message
  51.  
  52.  
  53.  
  54. }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement