Constructs a lock with a given combination.

Assignment Help JAVA Programming
Reference no: EM13941111

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

Reference no: EM13941111

Questions Cloud

What are some real or potential applications : What are some real or potential applications of these concepts?
Why do bond values go down when interest rates : We also looked at expected returns. Why do bond values go down when interest rates go up? Is this true in the opposite direction?
What is the reserve requirement in regard to commercial bank : What is the maturity date of a bond? What is the reserve requirement in regard to commercial banks?
Categorize different scheduling procedures for various types : Categorize different scheduling procedures for various types of service operations, such as restaurants, hospitals, and airlines.
Constructs a lock with a given combination. : 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.
Calculate smiths preadjustment balance in account receivable : Calculate Smith's preadjustment balance in accounts receivable on December 31, 2010. Calculate Smith's preadjustment balance in allowance for doubtful accounts on December 31, 2010.
Complete the following table by filling in the blanks : Complete the following table by filling in the blanks.
Describe business models of two ecommerce websites : Select two eCommerce websites (one Australian and one international) with totally different business models, and describe their business models.
What are the relevant laws that govern privacy in workplace : What are the relevant laws that govern privacy in the workplace? How can workers take advantage of the protections that these laws provide?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Define private instance variable to hold boolean value

Write a Java Enumeration "LetterGrade" that represents letter grades A through F including plus and minus grades. Define a private instance variable to hold a boolean value.

  Write a class and client class that stores hotels ratings

Write a class and client class that stores hotels ratings over the years. The number of stars represents hotel ratings. Use a two dimensional integer array to represent the years and hotels

  Function searches all files specified on the command line

Write a program Find that searches all files specified on the command line and prints out all lines containing a reserved word. For example, if you call java Find ring report.txt address.txt Homework.java, then the program might print:

  100 chairs arranged in a circle

At some point in time, the person in chair #1 will be told to leave the room. The person in chair #2 will be skipped, and the person in chair #3 will be told to leave. Next to go is person in chair #6. In other words, 1 person will be skipped initial..

  What character you should use to create your output figure

The char will be a single character and indicate what character you should use to create your output figure. You will write a program that reads from one file, interprets what it reads and writes to a second fine.

  Concept of java socket programming

Designed to asses learning outcomes and write programs that would communicate with another program running in the network

  Make a fourth button called special

Make a fourth button called "special" that does something else notdescribed in the assignment, such as change the background color.

  Declares three arraylist objects referenced by the objects

Write a program called ThreeArrayLists.java that declares three ArrayList objects referenced by the objects named priceList, quantityList, and amountList

  Write down the business needs for a computer program and

write the business requirements for a computer program and identify which entities are to be modeled using object

  Create file lab7.java with a main method.

Create file Lab7.java with a main method. Inside your main method, write a segment of code which instantiates an object of the Student class (This class has been created for you in the  Student.java  file that is provided as part of this lab).

  Give an implementation of the queue adt using an array

Give an implementation of the Deque ADT using an array, so that each of the update methods run in O(1) time. Program has to be written in Java.

  Small computer system interface-standard computer disk

How many primary drive partitions are supported on computers that still conform to the standard established by MS-DOS? How many total partitions can a standard computer disk [Intergrated Drive Electronics (IDE)/Serial Advanced Technology Attachment (..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd