In: Computer Science
Creation of Program Application (Development Task 1)
This program should create two output files.
You may use .txt files.
Create the following files:
Deposists.txt
Withdrawls.txt
1. The program application should have the following inputs: Amount for Deposits (Only Accept Positive Amounts) Amount for Withdrawals (Only Accept Positive Amounts). The subsequent program will subtract the positive amount.
2. The program application should have the following outputs:
Deposists.txt
Withdrawals.txt
Total of Deposits and Withdrawals back to the console
//create DevelopmentTask1.java class in any editor
import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;
public class DevelopmentTask1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//create two file Deposits.txt and Withdrawls.txt
String input = "";
while (!input.equals("n")) {
try {
System.out.println("1. Deposite\n2.
Withdrawl\n3.Display\n4.Quit");
System.out.print("Enter your option:");
int option = sc.nextInt();
switch (option) {
case 1:
System.out.println("Enter Amount to be deposite(Only greater than
zero)");
double deposite = 0;
while (deposite <= 0) {
System.out.print("Enter Positive Number:");
deposite = sc.nextDouble();
}
FileWriter writer = new FileWriter(new File("Deposite.txt"),
true);
writer.append("" + deposite + "\n");
writer.close();
break;
case 2:
System.out.println("Enter Amount to be withdrawl(Only greater than
zero)");
double withdrawl = 0;
while (withdrawl <= 0) {
System.out.print("Enter Positive Number:");
withdrawl = sc.nextDouble();
}
writer = new FileWriter(new File("Withdrawls.txt"), true);
writer.append("" + withdrawl + "\n");
writer.close();
break;
case 3:
//Total of deposite and withdrawl back to console
Scanner myReader = new Scanner(new File("Deposite.txt"));//read
file object
double total_deposite = 0,
total_withdrawl = 0;
while (myReader.hasNextLine()) {
try {
String data = myReader.nextLine();//read each file line
total_deposite += Double.parseDouble(data);
} catch (Exception e) {
e.printStackTrace();
}
}
myReader = new Scanner(new File("Withdrawls.txt"));//read file
object
while (myReader.hasNextLine()) {
try {
String data = myReader.nextLine();//read each file line
total_withdrawl += Double.parseDouble(data);
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("Total Deposite Value is: " +
total_deposite);
System.out.println("Total Withdrawl Value is: " +
total_withdrawl);
break;
case 4:
input = "n";
break;
}
} catch (Exception ee) {
ee.printStackTrace();
}
}
}
}
----------------------------------------------------------OUTPUT-----------------------------------------------------------------------------------
run:
1. Deposite
2. Withdrawl
3.Display
4.Quit
Enter your option:1
Enter Amount to be deposite(Only greater than zero)
Enter Positive Number:200
1. Deposite
2. Withdrawl
3.Display
4.Quit
Enter your option:2
Enter Amount to be withdrawl(Only greater than zero)
Enter Positive Number:100
1. Deposite
2. Withdrawl
3.Display
4.Quit
Enter your option:3
Total Deposite Value is: 600.0
Total Withdrawl Value is: 100.0
1. Deposite
2. Withdrawl
3.Display
4.Quit
Enter your option:4
BUILD SUCCESSFUL (total time: 17 seconds)