Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // PROBLEM: Somewhere after the last input. It does not go through the switch statements to output.
- package Java;
- import java.io.FileReader;
- import java.io.PrintWriter;
- import java.io.FileNotFoundException;
- import java.util.Scanner;
- import javax.swing.*;
- public class lab3 {
- public static void main(String[] args) throws FileNotFoundException {
- PrintWriter balance = new PrintWriter ("cust.txt");
- String name;
- char code;
- double oldbal;
- int amount;
- name = JOptionPane.showInputDialog("Please enter your name");
- amount = Integer.parseInt(JOptionPane.showInputDialog("Enter the amount"));
- oldbal = Double.parseDouble(JOptionPane.showInputDialog("Enter your old balance"));
- code = JOptionPane.showInputDialog("Please enter your transaction code").charAt(0);
- balance.println(name + " " + code + " " + amount);
- balance.close();
- Scanner infile = new Scanner (new FileReader("cust.txt"));
- String fname;
- char fcode;
- int famount;
- fname = infile.next();
- fcode = infile.next().charAt(0);
- famount = infile.nextInt();
- infile.close();
- switch (fcode) {
- case 'D':
- double add = (famount+oldbal);
- JOptionPane.showMessageDialog(null, "full name: " + name + "\n Trx code: " + code + "\n Old balance: " + oldbal + "\n New Balance: " + add);
- break;
- case 'W':
- double deduct = (oldbal-famount);
- JOptionPane.showMessageDialog(null, "full name: " + name + "\n Trx code: " + code + "\n Old balance: " + oldbal + "\n New Balance: " + deduct);
- break;
- case 'C':
- double deposit = (famount+oldbal);
- JOptionPane.showMessageDialog(null, "full name: " + name + "\n Trx code: " + code + "\n Old balance: " + oldbal + "\n New Balance: " + deposit);
- break;
- default:
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement