Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package PrintWriter;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.PrintWriter;
- import javax.swing.JOptionPane;
- import java.util.*;
- public class PrintWriterPrac {
- public static void main(String[] args) throws FileNotFoundException {
- PrintWriter practice = new PrintWriter ("Stud.txt");
- PrintWriter practice2 = new PrintWriter ("Studbal.txt");
- String name = JOptionPane.showInputDialog("Enter Name");
- int ID = Integer.parseInt (JOptionPane.showInputDialog("Enter Student ID"));
- double tuition = Double.parseDouble (JOptionPane.showInputDialog("Enter tuition"));
- // Below is what inputs the information to the txt file
- practice.println(name + " " + ID + " " + tuition);
- practice.close(); // Important = Close always so it inputs to the text file
- // Scanner below is to read/Scan the input above (so it can be used to output in JOption/console)
- Scanner infile = new Scanner (new FileReader("Stud.txt")); // Scanner file name "Stud.txt" is the same as PrintWriter name, this means
- //...that the Scanner will read from the PrintWriter's text content
- String fname;
- int fID;
- double ftuition;
- fname = infile.next();
- fID = infile.nextInt();
- ftuition = infile.nextDouble();
- double balance = ftuition - 1750; //b
- practice2.println(balance);
- JOptionPane.showMessageDialog(null,"Name: " + fname + "\nStudent ID: " + fID + "\nTuition: " + tuition);
- practice2.close();
- // PROBLEM
- // Find out how to change dialog box message
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement