SlideShare a Scribd company logo
1 of 4
Download to read offline
Part 1: Project Setup, Building the View/UI
In the video below, some initial steps are given to setup the GUI for the project as well as the
main entry point for the application.
Part 2: The IDialLock Interface
Note: All classes and interfaces you develop in Part 2 of the assignment should be placed in the
"model" package.
Develop an interface for a three-digit dial combination lock. The interface should be named
IDialLock and should export the following abstract methods:
void reset() - resets the lock dial back to 0.
void left(int t) - turns the lock left by the specified number of ticks t.
void right(int t) - turns the lock right by the specified number of ticks t.
int currentTick() - returns the tick number the dial is pointing to between 0..maxTicks.
boolean pull() - attempts to pull open the lock; the method returns true if successful false in all
other cases.
The lock opens if one performs the following sequence of turns:
right(..) to the first secret digit,
then left(..) to the second secret digit,
then right(..) to the third secret digit.
The image below is a rough illustration of the sort of dial lock you'll be building:
2.1: A "Helper Class" Representing Dial Turns
Before you implement the interface above, add the following helper class to the model package:
This class represents a single turn of the dial. It encapsulates the direction the dial was turned
(either left or right) along with the digit that the dial stopped on after the turn was completed.
2.2: Developing a "Tracking" Implementation of the IDialLock Interface
Now create another class (in the model package) called: TrLockImpl. This particular
implementation will 'track' the history of turns each time the left(..) or right(..) methods are called
in order to determine whether or not the lock will open (i.e.: when pull(..) is finally called).
To get started, make your class implement the IDialLock interface. The IDE should prompt you
to insert 'default / stub' implementations of the abstract methods in the interface.
Next, add the following fields to the class:
1. int maxTicks - this stores an upper bound on the digits around the lock.
2. int s1, s2, s3 - these are the three secret digits needed to open the lock.
3. int currentTick - the number the lock's dial is currently pointing towards (between
0..maxTicks).
4. List moves - this will store the history of turns made; so each time the left(..) or right(..)
methods are called, this list will increase in length by one.
Be sure to use appropriate access modifiers when defining the above fields.
Now add a constructor that accepts four ints as parameters:
s1, s2, and s3, and mTicks - these represent the three secret digits needed to open the lock, while
mTicks is the upper bound on the number of digits around the lock.
If any of these are negative, then throw a new IllegalArgumentException("secret digits cannot be
negative").
Important note: when initializing the maxTicks field within the constructor, do it this way:
this.maxTicks = mTicks + 1 (this is to account for the fact that the dial starts from index 0 -- and
will generally make some of the logic in the methods more straightforward).
Next, override the toString() method such that your TrLockImpl is rendered in string form like
so:
(where, as usual, the [..] are just placeholders denoting which field to print and where)
Before we get into defining the methods, below is a another example illustrating the tracking
implementation's behavior:
2.3: Tracking Implementation Methods
Here are some hints/pseudocode for the methods of the tracking implementation, these methods
should all be overridden from the IDialLock interface:
reset() - should just set currentTick back to 0 and clear out the moves list.
left(int t):
right(int t):
pull():
This method is more complicated due to the fact that many consecutive right and left turns can
be used to open the lock. In particular, the method needs to verify that:
first: only right turns were made, stopping at s1
- second: only left turns were made, stopping at s2
- and third: only right turns were made, finally stopping at s3
To motivate a strategy for implementing this method, consider the following. THIS IS NOT THE
CODE YOU PUT IN THE PULL METHOD (this just goes in a Tester.java file to see if your
pull method works):
By the time lock.pull() is called on the last line above, the lock object's move list -- if one were
to examine it in the debugger -- would look like this:
(R-2, e.g., is the toString representation of a Turn object and can be read as: "Right turn that
stopped on digit 2")
One possible way of determining whether the lock should be opened (given just the above list of
Turn objects to work with) is to partition the moves list into three separate lists:
Once you've managed to get the turns into these three lists, one could then say:
An additional check should verify that none of the three lists above are empty. If any are, then
return false -- as this would imply that someone skipped a required left or right turn sequence.
Lastly, you'd want to return true from the method only if:
Keep in mind the above is pseudocode.. e.g.: if you want to get the last element of
firstRightTurns, you need to use the list .get(..) method; so you'd say something along the lines:
firstRightTurns.get(INDEX-OF-LAST).stopDigit == s1.
The following is an example of a moves list that should NOT result in true getting returned from
the pull() method:
This will moves list would get partitioned into the three sublists like so:
Notice the length of all these three lists does not sum to the length of this.moves. Moreover, the
last element in each of the three lists above does match the three secret (for the first list, the stop
digit would need to be 3, for the second list, the stop digit would need to be 1, etc).
Part 3: Adding Controller Logic
The controller code you'll need in this assignment is fairly minimal. Each button on the form
developed in the getting started video is a one-to-one match with the various abstract methods
provided by the IDialLock interface. You need to attach "event handling" lambda expressions to
each one (calling the appropriate IDialLock model methods and updating the view accordingly).
For example, here is the event handling logic attached to the "left" button on the form:
Note that we're passing a lambda expression into the addActionListener(..) method.
We can do this because the addActionListener(..) method being called expects something of
interface-type ActionListener to be passed in. The ActionListener is a functional interface that is
a part of swing. I.e.: the interface only exports a single abstract method: actionPerformed(Event
e). So the lambda expression we're passing in is an implementation of the ActionListener's
actionPerformed(..) method.
Each button should will have a separate lambda attached to it that calls methods from the
IDialLock model and updates the various labels based on how the model changes. Below is an
example the UI in action:
Image Description
Some notes on the UI shown above:
you can change the color of the text displayed by some JLabel, exampleLabel, by writing:
exampleLabel.setForeground(Color.RED) -- other colors exist too, like Color.GREEN;
you can make a dialog box get displayed (like the message shown in the picture above on the
left) by writing: JOptionPane.showMessageDialog(view, "MSG GOES HERE") -- you only want
to do this if someone clicks "pull" and the lock fails to open.

More Related Content

Similar to Part 1 Project Setup, Building the ViewUIIn the video belo.pdf

Using CUDA Within Mathematica
Using CUDA Within MathematicaUsing CUDA Within Mathematica
Using CUDA Within Mathematicakrasul
 
Using Cuda Within Mathematica
Using Cuda Within MathematicaUsing Cuda Within Mathematica
Using Cuda Within MathematicaShoaib Burq
 
Foundations and methods of stochastic simulation
Foundations and methods of stochastic simulationFoundations and methods of stochastic simulation
Foundations and methods of stochastic simulationSpringer
 
maXbox Blix the Programmer
maXbox Blix the ProgrammermaXbox Blix the Programmer
maXbox Blix the ProgrammerMax Kleiner
 
How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1Taisuke Oe
 
Toonz code leaves much to be desired
Toonz code leaves much to be desiredToonz code leaves much to be desired
Toonz code leaves much to be desiredPVS-Studio
 
CP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithmsCP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithmsSheba41
 
hello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docxhello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docxIsaac9LjWelchq
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxskilljiolms
 
External Interface to SIMULINK
External Interface to SIMULINKExternal Interface to SIMULINK
External Interface to SIMULINKRobert Edwards
 
CP4151 ADSA unit1 Advanced Data Structures and Algorithms
CP4151 ADSA unit1 Advanced Data Structures and AlgorithmsCP4151 ADSA unit1 Advanced Data Structures and Algorithms
CP4151 ADSA unit1 Advanced Data Structures and AlgorithmsSheba41
 
Didactum SNMP Manual
Didactum SNMP ManualDidactum SNMP Manual
Didactum SNMP ManualDidactum
 

Similar to Part 1 Project Setup, Building the ViewUIIn the video belo.pdf (20)

Using matlab simulink
Using matlab simulinkUsing matlab simulink
Using matlab simulink
 
Using matlab simulink
Using matlab simulinkUsing matlab simulink
Using matlab simulink
 
Using CUDA Within Mathematica
Using CUDA Within MathematicaUsing CUDA Within Mathematica
Using CUDA Within Mathematica
 
Using Cuda Within Mathematica
Using Cuda Within MathematicaUsing Cuda Within Mathematica
Using Cuda Within Mathematica
 
Foundations and methods of stochastic simulation
Foundations and methods of stochastic simulationFoundations and methods of stochastic simulation
Foundations and methods of stochastic simulation
 
maXbox Blix the Programmer
maXbox Blix the ProgrammermaXbox Blix the Programmer
maXbox Blix the Programmer
 
How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1
 
Toonz code leaves much to be desired
Toonz code leaves much to be desiredToonz code leaves much to be desired
Toonz code leaves much to be desired
 
Visual basic bt0082
Visual basic  bt0082Visual basic  bt0082
Visual basic bt0082
 
CP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithmsCP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithms
 
T
TT
T
 
Lecture 2 java.pdf
Lecture 2 java.pdfLecture 2 java.pdf
Lecture 2 java.pdf
 
hello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docxhello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docx
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptx
 
Cc code cards
Cc code cardsCc code cards
Cc code cards
 
External Interface to SIMULINK
External Interface to SIMULINKExternal Interface to SIMULINK
External Interface to SIMULINK
 
ALGO.ppt
ALGO.pptALGO.ppt
ALGO.ppt
 
CP4151 ADSA unit1 Advanced Data Structures and Algorithms
CP4151 ADSA unit1 Advanced Data Structures and AlgorithmsCP4151 ADSA unit1 Advanced Data Structures and Algorithms
CP4151 ADSA unit1 Advanced Data Structures and Algorithms
 
Didactum SNMP Manual
Didactum SNMP ManualDidactum SNMP Manual
Didactum SNMP Manual
 
basic concepts
basic conceptsbasic concepts
basic concepts
 

More from amazing2001

P1 El ni�o _________ aparentemente result� ileso y tranquilo despu�.pdf
P1 El ni�o _________ aparentemente result� ileso y tranquilo despu�.pdfP1 El ni�o _________ aparentemente result� ileso y tranquilo despu�.pdf
P1 El ni�o _________ aparentemente result� ileso y tranquilo despu�.pdfamazing2001
 
P1 Las organizaciones gastan mucho dinero en permitir que los emple.pdf
P1 Las organizaciones gastan mucho dinero en permitir que los emple.pdfP1 Las organizaciones gastan mucho dinero en permitir que los emple.pdf
P1 Las organizaciones gastan mucho dinero en permitir que los emple.pdfamazing2001
 
P(X4t) Which of the following shaded regions corresponds to P(X41) P.pdf
P(X4t) Which of the following shaded regions corresponds to P(X41)  P.pdfP(X4t) Which of the following shaded regions corresponds to P(X41)  P.pdf
P(X4t) Which of the following shaded regions corresponds to P(X41) P.pdfamazing2001
 
P(B)= Ploind te three decimal placet a needet] (a) hiojdint wear beat .pdf
P(B)= Ploind te three decimal placet a needet] (a) hiojdint wear beat .pdfP(B)= Ploind te three decimal placet a needet] (a) hiojdint wear beat .pdf
P(B)= Ploind te three decimal placet a needet] (a) hiojdint wear beat .pdfamazing2001
 
P(1.10x2.64)= Shade the corresponding ares under the standsrd normal c.pdf
P(1.10x2.64)= Shade the corresponding ares under the standsrd normal c.pdfP(1.10x2.64)= Shade the corresponding ares under the standsrd normal c.pdf
P(1.10x2.64)= Shade the corresponding ares under the standsrd normal c.pdfamazing2001
 
P( threatened and in the United States )=.pdf
P( threatened and in the United States )=.pdfP( threatened and in the United States )=.pdf
P( threatened and in the United States )=.pdfamazing2001
 
P( patient has had exactly 3 tests done )=.pdf
P( patient has had exactly 3 tests done )=.pdfP( patient has had exactly 3 tests done )=.pdf
P( patient has had exactly 3 tests done )=.pdfamazing2001
 
P(F1)=d(C3)=P(r3)= What inelleat an y pro uee nuynkal theited niefert.pdf
P(F1)=d(C3)=P(r3)= What inelleat an y pro uee nuynkal theited niefert.pdfP(F1)=d(C3)=P(r3)= What inelleat an y pro uee nuynkal theited niefert.pdf
P(F1)=d(C3)=P(r3)= What inelleat an y pro uee nuynkal theited niefert.pdfamazing2001
 
Our theory of solar system formation emphasizes that hydrogen compou.pdf
Our theory of solar system formation emphasizes that hydrogen compou.pdfOur theory of solar system formation emphasizes that hydrogen compou.pdf
Our theory of solar system formation emphasizes that hydrogen compou.pdfamazing2001
 
Output of executed code should show the followingJanuaryFebruar.pdf
Output of executed code should show the followingJanuaryFebruar.pdfOutput of executed code should show the followingJanuaryFebruar.pdf
Output of executed code should show the followingJanuaryFebruar.pdfamazing2001
 
Ortega and colleagues (2017) discovered that, of ~3,400 Blue-footed .pdf
Ortega and colleagues (2017) discovered that, of ~3,400 Blue-footed .pdfOrtega and colleagues (2017) discovered that, of ~3,400 Blue-footed .pdf
Ortega and colleagues (2017) discovered that, of ~3,400 Blue-footed .pdfamazing2001
 
other question Problem 1. Let UUniform(0,1). Determine the p.d.pdf
other question  Problem 1. Let UUniform(0,1). Determine the p.d.pdfother question  Problem 1. Let UUniform(0,1). Determine the p.d.pdf
other question Problem 1. Let UUniform(0,1). Determine the p.d.pdfamazing2001
 
Our environment is very sensitive to the amount of ozone in the uppe.pdf
Our environment is very sensitive to the amount of ozone in the uppe.pdfOur environment is very sensitive to the amount of ozone in the uppe.pdf
Our environment is very sensitive to the amount of ozone in the uppe.pdfamazing2001
 
Organization - Bapco Bahrain please answer all the points 1. Hig.pdf
Organization - Bapco Bahrain please answer all the points 1. Hig.pdfOrganization - Bapco Bahrain please answer all the points 1. Hig.pdf
Organization - Bapco Bahrain please answer all the points 1. Hig.pdfamazing2001
 
Organisation Contoso is getting ready to launch a new artificial int.pdf
Organisation Contoso is getting ready to launch a new artificial int.pdfOrganisation Contoso is getting ready to launch a new artificial int.pdf
Organisation Contoso is getting ready to launch a new artificial int.pdfamazing2001
 
Outline a strategy that could be used to ensure participatory arrang.pdf
Outline a strategy that could be used to ensure participatory arrang.pdfOutline a strategy that could be used to ensure participatory arrang.pdf
Outline a strategy that could be used to ensure participatory arrang.pdfamazing2001
 
Orange Inc. ten�a 300.000 acciones ordinarias de valor nominal de $1.pdf
Orange Inc. ten�a 300.000 acciones ordinarias de valor nominal de $1.pdfOrange Inc. ten�a 300.000 acciones ordinarias de valor nominal de $1.pdf
Orange Inc. ten�a 300.000 acciones ordinarias de valor nominal de $1.pdfamazing2001
 
Owen es director de Packaging Company. Como director, los derechos d.pdf
Owen es director de Packaging Company. Como director, los derechos d.pdfOwen es director de Packaging Company. Como director, los derechos d.pdf
Owen es director de Packaging Company. Como director, los derechos d.pdfamazing2001
 

More from amazing2001 (20)

P1 El ni�o _________ aparentemente result� ileso y tranquilo despu�.pdf
P1 El ni�o _________ aparentemente result� ileso y tranquilo despu�.pdfP1 El ni�o _________ aparentemente result� ileso y tranquilo despu�.pdf
P1 El ni�o _________ aparentemente result� ileso y tranquilo despu�.pdf
 
P1 Las organizaciones gastan mucho dinero en permitir que los emple.pdf
P1 Las organizaciones gastan mucho dinero en permitir que los emple.pdfP1 Las organizaciones gastan mucho dinero en permitir que los emple.pdf
P1 Las organizaciones gastan mucho dinero en permitir que los emple.pdf
 
P(X=j).pdf
P(X=j).pdfP(X=j).pdf
P(X=j).pdf
 
P(X4t) Which of the following shaded regions corresponds to P(X41) P.pdf
P(X4t) Which of the following shaded regions corresponds to P(X41)  P.pdfP(X4t) Which of the following shaded regions corresponds to P(X41)  P.pdf
P(X4t) Which of the following shaded regions corresponds to P(X41) P.pdf
 
P(B)= Ploind te three decimal placet a needet] (a) hiojdint wear beat .pdf
P(B)= Ploind te three decimal placet a needet] (a) hiojdint wear beat .pdfP(B)= Ploind te three decimal placet a needet] (a) hiojdint wear beat .pdf
P(B)= Ploind te three decimal placet a needet] (a) hiojdint wear beat .pdf
 
P(1.10x2.64)= Shade the corresponding ares under the standsrd normal c.pdf
P(1.10x2.64)= Shade the corresponding ares under the standsrd normal c.pdfP(1.10x2.64)= Shade the corresponding ares under the standsrd normal c.pdf
P(1.10x2.64)= Shade the corresponding ares under the standsrd normal c.pdf
 
P( threatened and in the United States )=.pdf
P( threatened and in the United States )=.pdfP( threatened and in the United States )=.pdf
P( threatened and in the United States )=.pdf
 
P( patient has had exactly 3 tests done )=.pdf
P( patient has had exactly 3 tests done )=.pdfP( patient has had exactly 3 tests done )=.pdf
P( patient has had exactly 3 tests done )=.pdf
 
P(F1)=d(C3)=P(r3)= What inelleat an y pro uee nuynkal theited niefert.pdf
P(F1)=d(C3)=P(r3)= What inelleat an y pro uee nuynkal theited niefert.pdfP(F1)=d(C3)=P(r3)= What inelleat an y pro uee nuynkal theited niefert.pdf
P(F1)=d(C3)=P(r3)= What inelleat an y pro uee nuynkal theited niefert.pdf
 
P(1.63z2.4).pdf
P(1.63z2.4).pdfP(1.63z2.4).pdf
P(1.63z2.4).pdf
 
Our theory of solar system formation emphasizes that hydrogen compou.pdf
Our theory of solar system formation emphasizes that hydrogen compou.pdfOur theory of solar system formation emphasizes that hydrogen compou.pdf
Our theory of solar system formation emphasizes that hydrogen compou.pdf
 
Output of executed code should show the followingJanuaryFebruar.pdf
Output of executed code should show the followingJanuaryFebruar.pdfOutput of executed code should show the followingJanuaryFebruar.pdf
Output of executed code should show the followingJanuaryFebruar.pdf
 
Ortega and colleagues (2017) discovered that, of ~3,400 Blue-footed .pdf
Ortega and colleagues (2017) discovered that, of ~3,400 Blue-footed .pdfOrtega and colleagues (2017) discovered that, of ~3,400 Blue-footed .pdf
Ortega and colleagues (2017) discovered that, of ~3,400 Blue-footed .pdf
 
other question Problem 1. Let UUniform(0,1). Determine the p.d.pdf
other question  Problem 1. Let UUniform(0,1). Determine the p.d.pdfother question  Problem 1. Let UUniform(0,1). Determine the p.d.pdf
other question Problem 1. Let UUniform(0,1). Determine the p.d.pdf
 
Our environment is very sensitive to the amount of ozone in the uppe.pdf
Our environment is very sensitive to the amount of ozone in the uppe.pdfOur environment is very sensitive to the amount of ozone in the uppe.pdf
Our environment is very sensitive to the amount of ozone in the uppe.pdf
 
Organization - Bapco Bahrain please answer all the points 1. Hig.pdf
Organization - Bapco Bahrain please answer all the points 1. Hig.pdfOrganization - Bapco Bahrain please answer all the points 1. Hig.pdf
Organization - Bapco Bahrain please answer all the points 1. Hig.pdf
 
Organisation Contoso is getting ready to launch a new artificial int.pdf
Organisation Contoso is getting ready to launch a new artificial int.pdfOrganisation Contoso is getting ready to launch a new artificial int.pdf
Organisation Contoso is getting ready to launch a new artificial int.pdf
 
Outline a strategy that could be used to ensure participatory arrang.pdf
Outline a strategy that could be used to ensure participatory arrang.pdfOutline a strategy that could be used to ensure participatory arrang.pdf
Outline a strategy that could be used to ensure participatory arrang.pdf
 
Orange Inc. ten�a 300.000 acciones ordinarias de valor nominal de $1.pdf
Orange Inc. ten�a 300.000 acciones ordinarias de valor nominal de $1.pdfOrange Inc. ten�a 300.000 acciones ordinarias de valor nominal de $1.pdf
Orange Inc. ten�a 300.000 acciones ordinarias de valor nominal de $1.pdf
 
Owen es director de Packaging Company. Como director, los derechos d.pdf
Owen es director de Packaging Company. Como director, los derechos d.pdfOwen es director de Packaging Company. Como director, los derechos d.pdf
Owen es director de Packaging Company. Como director, los derechos d.pdf
 

Recently uploaded

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 

Recently uploaded (20)

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 

Part 1 Project Setup, Building the ViewUIIn the video belo.pdf

  • 1. Part 1: Project Setup, Building the View/UI In the video below, some initial steps are given to setup the GUI for the project as well as the main entry point for the application. Part 2: The IDialLock Interface Note: All classes and interfaces you develop in Part 2 of the assignment should be placed in the "model" package. Develop an interface for a three-digit dial combination lock. The interface should be named IDialLock and should export the following abstract methods: void reset() - resets the lock dial back to 0. void left(int t) - turns the lock left by the specified number of ticks t. void right(int t) - turns the lock right by the specified number of ticks t. int currentTick() - returns the tick number the dial is pointing to between 0..maxTicks. boolean pull() - attempts to pull open the lock; the method returns true if successful false in all other cases. The lock opens if one performs the following sequence of turns: right(..) to the first secret digit, then left(..) to the second secret digit, then right(..) to the third secret digit. The image below is a rough illustration of the sort of dial lock you'll be building: 2.1: A "Helper Class" Representing Dial Turns Before you implement the interface above, add the following helper class to the model package: This class represents a single turn of the dial. It encapsulates the direction the dial was turned (either left or right) along with the digit that the dial stopped on after the turn was completed. 2.2: Developing a "Tracking" Implementation of the IDialLock Interface Now create another class (in the model package) called: TrLockImpl. This particular implementation will 'track' the history of turns each time the left(..) or right(..) methods are called in order to determine whether or not the lock will open (i.e.: when pull(..) is finally called). To get started, make your class implement the IDialLock interface. The IDE should prompt you
  • 2. to insert 'default / stub' implementations of the abstract methods in the interface. Next, add the following fields to the class: 1. int maxTicks - this stores an upper bound on the digits around the lock. 2. int s1, s2, s3 - these are the three secret digits needed to open the lock. 3. int currentTick - the number the lock's dial is currently pointing towards (between 0..maxTicks). 4. List moves - this will store the history of turns made; so each time the left(..) or right(..) methods are called, this list will increase in length by one. Be sure to use appropriate access modifiers when defining the above fields. Now add a constructor that accepts four ints as parameters: s1, s2, and s3, and mTicks - these represent the three secret digits needed to open the lock, while mTicks is the upper bound on the number of digits around the lock. If any of these are negative, then throw a new IllegalArgumentException("secret digits cannot be negative"). Important note: when initializing the maxTicks field within the constructor, do it this way: this.maxTicks = mTicks + 1 (this is to account for the fact that the dial starts from index 0 -- and will generally make some of the logic in the methods more straightforward). Next, override the toString() method such that your TrLockImpl is rendered in string form like so: (where, as usual, the [..] are just placeholders denoting which field to print and where) Before we get into defining the methods, below is a another example illustrating the tracking implementation's behavior: 2.3: Tracking Implementation Methods Here are some hints/pseudocode for the methods of the tracking implementation, these methods should all be overridden from the IDialLock interface: reset() - should just set currentTick back to 0 and clear out the moves list. left(int t): right(int t): pull(): This method is more complicated due to the fact that many consecutive right and left turns can be used to open the lock. In particular, the method needs to verify that: first: only right turns were made, stopping at s1 - second: only left turns were made, stopping at s2 - and third: only right turns were made, finally stopping at s3 To motivate a strategy for implementing this method, consider the following. THIS IS NOT THE
  • 3. CODE YOU PUT IN THE PULL METHOD (this just goes in a Tester.java file to see if your pull method works): By the time lock.pull() is called on the last line above, the lock object's move list -- if one were to examine it in the debugger -- would look like this: (R-2, e.g., is the toString representation of a Turn object and can be read as: "Right turn that stopped on digit 2") One possible way of determining whether the lock should be opened (given just the above list of Turn objects to work with) is to partition the moves list into three separate lists: Once you've managed to get the turns into these three lists, one could then say: An additional check should verify that none of the three lists above are empty. If any are, then return false -- as this would imply that someone skipped a required left or right turn sequence. Lastly, you'd want to return true from the method only if: Keep in mind the above is pseudocode.. e.g.: if you want to get the last element of firstRightTurns, you need to use the list .get(..) method; so you'd say something along the lines: firstRightTurns.get(INDEX-OF-LAST).stopDigit == s1. The following is an example of a moves list that should NOT result in true getting returned from the pull() method: This will moves list would get partitioned into the three sublists like so: Notice the length of all these three lists does not sum to the length of this.moves. Moreover, the last element in each of the three lists above does match the three secret (for the first list, the stop digit would need to be 3, for the second list, the stop digit would need to be 1, etc). Part 3: Adding Controller Logic The controller code you'll need in this assignment is fairly minimal. Each button on the form developed in the getting started video is a one-to-one match with the various abstract methods provided by the IDialLock interface. You need to attach "event handling" lambda expressions to each one (calling the appropriate IDialLock model methods and updating the view accordingly). For example, here is the event handling logic attached to the "left" button on the form: Note that we're passing a lambda expression into the addActionListener(..) method. We can do this because the addActionListener(..) method being called expects something of interface-type ActionListener to be passed in. The ActionListener is a functional interface that is a part of swing. I.e.: the interface only exports a single abstract method: actionPerformed(Event e). So the lambda expression we're passing in is an implementation of the ActionListener's actionPerformed(..) method. Each button should will have a separate lambda attached to it that calls methods from the IDialLock model and updates the various labels based on how the model changes. Below is an example the UI in action:
  • 4. Image Description Some notes on the UI shown above: you can change the color of the text displayed by some JLabel, exampleLabel, by writing: exampleLabel.setForeground(Color.RED) -- other colors exist too, like Color.GREEN; you can make a dialog box get displayed (like the message shown in the picture above on the left) by writing: JOptionPane.showMessageDialog(view, "MSG GOES HERE") -- you only want to do this if someone clicks "pull" and the lock fails to open.