Advertisement
Guest User

Ass

a guest
Aug 15th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. package input1;
  2.  
  3. import java.io.BufferedWriter;
  4. import java.io.BufferedReader;
  5. import java.io.FileReader;
  6. import java.io.File;
  7. import java.io.FileWriter;
  8. import java.io.IOException;
  9. import java.util.*;
  10.  
  11. public class input1{
  12.  
  13. public static void main(String[] args){
  14. int id1 = 0, count = 0;
  15. String[] user_name = null;
  16. String[] pass_word = null;
  17. double[] amount = null;
  18. Scanner scanner = new Scanner(System.in);
  19. try{
  20. File id = new File("C:/id.txt");
  21. File username = new File("C:/username.txt");
  22. File password = new File("C:/password.txt");
  23. File curr_amount = new File("C:/curr_amount.txt");
  24. if(!id.exists()){
  25. id.createNewFile();
  26. FileWriter fw = new FileWriter(id.getAbsoluteFile());
  27. BufferedWriter bw = new BufferedWriter(fw);
  28. id1 = 1;
  29. bw.write(id1);
  30. bw.close();
  31. }
  32.  
  33. //loop masukkan text to array
  34.  
  35. System.out.println("1. Log in. ");
  36. System.out.println("2. Sign up. ");
  37. count = scanner.nextInt();
  38. if(count==1){
  39.  
  40. }
  41. else if (count == 2){
  42. Scanner count_id = new Scanner(id);
  43. id1 = count_id.nextInt();
  44. count_id.close();
  45. id1 = id1 +1;
  46. System.out.print("Enter name: ");
  47. user_name[id1] = scanner.next();
  48. System.out.print("Enter password: ");
  49. pass_word[id1] = scanner.next();
  50. System.out.print("Enter amount: ");
  51. amount[id1] = scanner.nextDouble();
  52. if(amount[id1]<10){
  53. System.out.println("Your new account must at least have RM 10.00.");
  54. }
  55. Scanner count_username = new Scanner(username);
  56. while(count_username.hasNext()){
  57. count_username.next();
  58. }
  59.  
  60. }
  61. else{
  62. System.out.println("Invalid input. Please enter 1 or 2.");
  63. }
  64. FileWriter fw = new FileWriter(id.getAbsoluteFile());
  65. BufferedWriter bw = new BufferedWriter(fw);
  66. System.out.print("Enter name: ");
  67. String content = scanner.next();
  68. bw.write(content);
  69. bw.close();
  70. FileReader filea = new FileReader("C:/filename.txt");
  71. BufferedReader reader = new BufferedReader(filea);
  72. String text = "";
  73. String line = reader.readLine();
  74. while (line != null){
  75. text += line;
  76. line = reader.readLine();
  77. }
  78. reader.close();
  79. System.out.println(text);
  80.  
  81.  
  82.  
  83.  
  84. }catch(IOException e){
  85. e.printStackTrace();
  86. }
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement