Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Assignment2
- {
- public static void main (String[] args)
- {
- usernamecheck ();
- }
- public static void usernamecheck()
- {
- Scanner keyboard = new Scanner(System.in);
- System.out.print("Please enter your username: ");
- String username = keyboard.nextLine();
- if(username.equalsIgnoreCase("Administrator"))
- {
- passwordcheck ();
- }
- else
- {
- System.out.println("Username Incorrect");
- System.out.println("Program terminated");
- System.exit(0);
- }
- }
- public static void passwordcheck()
- {
- Scanner keyboard = new Scanner(System.in);
- System.out.print("Please enter your password: ");
- String password = keyboard.nextLine();
- if(password.equals("ThisIsABadPassword"))
- {
- System.out.print("Welcome back Administrator!");
- System.out.println();
- gasmileage ();
- }
- else
- {
- System.out.println("Password Incorrect");
- System.out.println("Program terminated");
- System.exit(0);
- }
- }
- public static void gasmileage()
- {
- Scanner keyboard = new Scanner(System.in);
- System.out.println();
- System.out.print("How many miles have you travelled since your last fill up? ");
- double miles = keyboard.nextDouble();
- System.out.print("How many gallons did you put in? ");
- double gallons = keyboard.nextDouble();
- calcmileage (miles,gallons);
- }
- public static void calcmileage (double miles,double gallons)
- {
- double mileage = (miles / gallons);
- output (mileage);
- }
- public static void output (double mileage)
- {
- if(mileage > 50)
- {
- System.out.println("Wow that’s crazy!");
- }
- else if (mileage > 30)
- {
- System.out.println("Eh, I Guess That's Pretty Good.");
- }
- else if (mileage > 15)
- {
- System.out.println("Man I really hope gas prices go down.");
- }
- else
- {
- System.out.println("Wow dude, you need to get a new car...");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement