Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package input1;
- import java.io.BufferedWriter;
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.*;
- public class input1{
- public static void main(String[] args){
- int id1 = 0, count = 0;
- String[] user_name = null;
- String[] pass_word = null;
- double[] amount = null;
- Scanner scanner = new Scanner(System.in);
- try{
- File id = new File("C:/id.txt");
- File username = new File("C:/username.txt");
- File password = new File("C:/password.txt");
- File curr_amount = new File("C:/curr_amount.txt");
- if(!id.exists()){
- id.createNewFile();
- FileWriter fw = new FileWriter(id.getAbsoluteFile());
- BufferedWriter bw = new BufferedWriter(fw);
- id1 = 1;
- bw.write(id1);
- bw.close();
- }
- //loop masukkan text to array
- System.out.println("1. Log in. ");
- System.out.println("2. Sign up. ");
- count = scanner.nextInt();
- if(count==1){
- }
- else if (count == 2){
- Scanner count_id = new Scanner(id);
- id1 = count_id.nextInt();
- count_id.close();
- id1 = id1 +1;
- System.out.print("Enter name: ");
- user_name[id1] = scanner.next();
- System.out.print("Enter password: ");
- pass_word[id1] = scanner.next();
- System.out.print("Enter amount: ");
- amount[id1] = scanner.nextDouble();
- if(amount[id1]<10){
- System.out.println("Your new account must at least have RM 10.00.");
- }
- Scanner count_username = new Scanner(username);
- while(count_username.hasNext()){
- count_username.next();
- }
- }
- else{
- System.out.println("Invalid input. Please enter 1 or 2.");
- }
- FileWriter fw = new FileWriter(id.getAbsoluteFile());
- BufferedWriter bw = new BufferedWriter(fw);
- System.out.print("Enter name: ");
- String content = scanner.next();
- bw.write(content);
- bw.close();
- FileReader filea = new FileReader("C:/filename.txt");
- BufferedReader reader = new BufferedReader(filea);
- String text = "";
- String line = reader.readLine();
- while (line != null){
- text += line;
- line = reader.readLine();
- }
- reader.close();
- System.out.println(text);
- }catch(IOException e){
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement