Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Objectives
• Group statements into blocks
• Compare integers, doubles, strings, and objects
• Program conditions using Boolean operators and variables
The work should include the following:
• CombinationLock.java
• CombinationLockTest.java
Details
Implement a combination lock class.
A combination lock has a dial with 26 positions labeled A..Z. The dial needs to be set three times. If it is set to the correct combination, the lock can be opened. When the lock is closed again, the combination can be entered again. If a user sets the dial more than three times, the last three settings determine whether the lock can be opened.
myPositions myPositions after the call setPosition("A") myPositions after the call setPosition("B") myPositions after the call setPosition("D")
"" "A" "AB" "ABD"
Support the following interface
/*
Constructs a lock with a given combination. The state is initially
closed (false) and the positions is (are?) an empty string ("").
@param combination is a string with three uppercase letters A..Z
*/
public CombinationLock( String combination )

/*
Set the dial to a position. See chart above for an example.
@param position is a string consisting of a single uppercase letter A..Z
*/
public void setPosition(String aPosition)

/*
Try unlocking the lock. If the lock is closed and the length of the
positions is >= 3, test to see if the combination is equal to the
last three positions. If they are equal, open the lock otherwise
leave it unchanged.
*/
public void unlock()

/*
Check whether the lock is unlocked.
@return true if the lock is currently open.
*/
public boolean isOpen()

/*
Close the lock and start over by setting the state and the
positions to the empty string ""
*/
public void startOver()
You will need the following instance fields.
private boolean myState; // myState is true if the lock is open and
// false otherwise
private String myCombination; // A three character string
// representing the combination
private String myPositions; // A string that represents the positions
// set on the dial. This string can
// be any length.
The CombinationLockTest Class
• Instantiate a lock with the combination "ABC".
• Try opening the lock by using the setPosition() method 3 times with the following sequence "A","B", "D".
• Try to unlock the lock using the unlock() method.
• Make sure the lock did not open by printing the result of the isOpen() method.
• If the lock is open starOver() (Conditional statement)
• Try opening the lock by using the setPosition() method 2 times with "A", "B".
• Try to unlock the lock using the unlock() method.
• Make sure the lock did not open by printing the result of the isOpen() method.
• If the lock is open startOver() (Conditional statement)
• Try opening the lock by using the setPosition() method 1 time with "C".
• Use unlock().
• Make sure the lock is open by printing the result of the isOpen() method.
• If the lock is open startOver() (Conditional statement).
• Make sure the lock did not open by printing the result of the isOpen() method.
• Try opening the lock by using the setPosition() method 4 times with the following "A", "A", "B", "C".
• Try to unlock the lock using the unlock() method.
• Make sure the lock is open by printing the result of the isOpen() method

Java, Programming

  • Category:- Java
  • Reference No.:- M91611984
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Java

Assignment - java program using array of objectsobjectives

Assignment - JAVA Program using array of objects Objectives - This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details - For this assignment, you are required to develop a Menu ...

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assignment - method in our madnessthe emphasis for this

Assignment - "Method in our Madness" The emphasis for this assignment is methods with parameters. In preparation for this assignment, create a folder called Assign_3 for the DrJava projects for the assignment. A Cityscap ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As