Advertisement
Guest User

Untitled

a guest
Oct 11th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Assignment2
  4. {
  5.  
  6. public static void main (String[] args)
  7. {
  8. usernamecheck ();
  9. }
  10.  
  11.  
  12. public static void usernamecheck()
  13. {
  14. Scanner keyboard = new Scanner(System.in);
  15. System.out.print("Please enter your username: ");
  16. String username = keyboard.nextLine();
  17.  
  18. if(username.equalsIgnoreCase("Administrator"))
  19. {
  20. passwordcheck ();
  21. }
  22. else
  23. {
  24. System.out.println("Username Incorrect");
  25. System.out.println("Program terminated");
  26. System.exit(0);
  27. }
  28. }
  29.  
  30. public static void passwordcheck()
  31. {
  32. Scanner keyboard = new Scanner(System.in);
  33. System.out.print("Please enter your password: ");
  34. String password = keyboard.nextLine();
  35.  
  36. if(password.equals("ThisIsABadPassword"))
  37. {
  38. System.out.print("Welcome back Administrator!");
  39. System.out.println();
  40. gasmileage ();
  41. }
  42. else
  43. {
  44. System.out.println("Password Incorrect");
  45. System.out.println("Program terminated");
  46. System.exit(0);
  47. }
  48. }
  49.  
  50. public static void gasmileage()
  51. {
  52. Scanner keyboard = new Scanner(System.in);
  53. System.out.println();
  54. System.out.print("How many miles have you travelled since your last fill up? ");
  55. double miles = keyboard.nextDouble();
  56. System.out.print("How many gallons did you put in? ");
  57. double gallons = keyboard.nextDouble();
  58. calcmileage (miles,gallons);
  59. }
  60.  
  61. public static void calcmileage (double miles,double gallons)
  62. {
  63. double mileage = (miles / gallons);
  64. output (mileage);
  65. }
  66.  
  67. public static void output (double mileage)
  68. {
  69. if(mileage > 50)
  70. {
  71. System.out.println("Wow that’s crazy!");
  72. }
  73. else if (mileage > 30)
  74. {
  75. System.out.println("Eh, I Guess That's Pretty Good.");
  76. }
  77. else if (mileage > 15)
  78. {
  79. System.out.println("Man I really hope gas prices go down.");
  80. }
  81. else
  82. {
  83. System.out.println("Wow dude, you need to get a new car...");
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement