Question: Write two programs named Account.java and Problem1.java that work as follows: The Account class is a template class with operations for an online account. TestProblem1.java

Write two programs named Account.java and Problem1.java that work as follows:

The Account class is a template class with operations for an online account. TestProblem1.java is provided as a demonstration of expected methods. The Account class has the following:

Two private instance variables: a password (String) and a login status (boolean). The password is used when attempting to log in. The status variable has a value of true when the user is logged in, and false otherwise.

The constructor receives an initial password.

A login method returns nothing (void) and receives nothing. It prompts the user for a password. If

the text entered is equal to the password, the login status is set to true, and a message is displayed

indicating a successful login.

A logout method returns nothing (void) and receives nothing. It sets the login status to false and

prints a message is indicating a successful logout.

A changePassword method returns nothing (void) and receives nothing. If the login status is true,

the user is prompted for a new password, and the password is changed. It also prints a message indicating a successful password change. If the login status is false, it prints a message indicating that the user is not logged in.

The Problem1 class is an application class that allows the user to repeatedly perform account operations. It does the following in the main() method:

Creates an instance of the Account class with any initial password you wish. Uses a while loop to repeatedly prompt the user for one of 4 possible commands:

o quit terminates the program. o login calls the login method from the Account class. o change calls the changePassword method from the Account class. o logout calls the logout method from the Account class. o Any other text entered as a command leads to a message indicating the command was not

recognized.

The commands above are compared using an efficient, nested if-else structure (do not use multiple, simple if statements).

Below is an example of how your program might work and comments that describe what happens. An infinite number of scenarios are possible. You are allowed to use different prompts, messages, and command names if you wish.

Console (user input in bold):

Enter command: delete

Unrecognized command. Enter command: change Sorry, you are not logged in.

Enter command: login

Enter password: Yippee

Incorrect password. Enter command: login Enter password: Woohoo!

You are logged in! Enter command: change

Enter new password: YippeePassword changed.

Enter command: logout

You are logged out

. Enter command: login

Enter password: Yippee

You are logged in!

Enter command: quit

Comments about what happens when the initial password is Woohoo!:

User enters an invalid command. 
User attempts to change password without having first logged in. User attempts to log in. User enters wrong password. 
User attempts to log in again and is successful. User chooses to change password. 
User logs out. User logs in using new password. 

User quits.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!