Advertisement
Guest User

java

a guest
Sep 21st, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.Scanner;
  3.  
  4. public class ProfileSystem {
  5.  
  6. public static void main(String[] args)throws IOException {
  7. Scanner input = new Scanner(System.in);
  8. int counter = 0;
  9. String fileName = "ProfileInfo.txt";
  10. FileReader fr = new FileReader(fileName);
  11. BufferedReader br = new BufferedReader(fr);
  12. String credentials [][] = new String[10][2];
  13. for(int k = 0;k < 10 ; k++){
  14. String Line = br.readLine();
  15. String split[] = Line.split(",");
  16. credentials [k][0] = split [0];
  17. credentials [k][1] = split [1];
  18. }
  19. System.out.println("\rSign-up/Log-in");
  20. String answer = input.nextLine();
  21. do{
  22. switch(answer){
  23.  
  24. case"Sign-up":
  25. counter = 0;
  26. System.out.println("\rPlease input your new username >");
  27. String name = input.nextLine();
  28. try {
  29. FileWriter fw = new FileWriter(fileName, true);
  30. fw.write(name);
  31. fw.close();
  32. }
  33. catch(FileNotFoundException ex) {
  34. System.out.println("Unable to save account details " + fileName);}
  35. catch(IOException ex) {
  36. System.out.println("Error reading " + fileName);}
  37. System.out.println("\rInput new password >");
  38. String pw = input.nextLine();
  39. try {
  40. FileWriter fw1 = new FileWriter(fileName, true);
  41. fw1.write(","+pw);
  42. fw1.close();
  43. }
  44. catch(FileNotFoundException ex) {
  45. System.out.println("Unable to save account details " + fileName);}
  46. catch(IOException ex) {
  47. System.out.println("Error reading " + fileName);}
  48. System.out.println("What is your favourite genre of film?");
  49. String genre = input.nextLine();
  50. if(genre.equals("Comedy")){System.out.println("Here are some film recommendations: The Mask, Megamind, The Hangover, Shaun of the Dead and Ted. ");}
  51. if(genre.equals("Horror")){System.out.println("Here are some film recommendations: .");}
  52. if(genre.equals("Thriller")){System.out.println("Here are some film recommendations: . ");}
  53. if(genre.equals("Drama")){System.out.println("Here are some film recommendations: . ");}
  54. if(genre.equals("War")){System.out.println("Here are some film recommendations: Dunkirk, . ");}
  55.  
  56.  
  57. case"Log-in":
  58. counter = 3;
  59. boolean loginsuccess = false;
  60. boolean pwsuccess = false;
  61. System.out.println("Input your username >");
  62. String user = input.nextLine();
  63. System.out.println("Input your password >");
  64. String pass = input.nextLine();
  65. for (int i = 0; i < 10;i++){
  66. if(credentials[i][0].equals(user)){
  67. loginsuccess = true;
  68. if(credentials[i][1].equals(pw)){
  69. loginsuccess = true;}
  70. input.close();}}}}}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement