Advertisement
cynthiarez

Print Writer Java Practice

Sep 9th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. IMPORTANT: Always when opening ECLIPSE -> Java Project -> JRE: JavaSE 1.6 (Java environment)
  2.  
  3. package PrintWriter;
  4. import java.io.FileNotFoundException;
  5. import java.io.PrintWriter;
  6. import javax.swing.JOptionPane;
  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.  
  15.  
  16. String name = JOptionPane.showInputDialog("Enter Name");
  17. String ID = JOptionPane.showInputDialog("Enter Student ID");
  18. double tuition = Double.parseDouble (JOptionPane.showInputDialog("Enter tuition"));
  19.  
  20.  
  21. // Below are what inputs the information to the txt file
  22.  
  23. practice.println("Name: " + name);
  24. practice.println("Student ID: " + ID);
  25. practice.printf("Tuition: " + "%.2f", tuition);
  26.  
  27. practice.close();
  28.  
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement