SlideShare a Scribd company logo
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 matlab simulink
Using matlab simulinkUsing matlab simulink
Using matlab simulink
Marilyn Barragán Castañeda
 
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 Programmer
Max 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): Day1
Taisuke 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 desired
PVS-Studio
 
Visual basic bt0082
Visual basic  bt0082Visual basic  bt0082
Visual basic bt0082
Divyam Pateriya
 
CP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithmsCP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithms
Sheba41
 
T
TT
Lecture 2 java.pdf
Lecture 2 java.pdfLecture 2 java.pdf
Lecture 2 java.pdf
SantoshSurwade2
 
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
Isaac9LjWelchq
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptx
skilljiolms
 
Cc code cards
Cc code cardsCc code cards
Cc code cards
ysolanki78
 
External Interface to SIMULINK
External Interface to SIMULINKExternal Interface to SIMULINK
External Interface to SIMULINKRobert Edwards
 
ALGO.ppt
ALGO.pptALGO.ppt
ALGO.ppt
PidoonEsm
 
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
Sheba41
 
Didactum SNMP Manual
Didactum SNMP ManualDidactum SNMP Manual
Didactum SNMP Manual
Didactum
 

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�.pdf
amazing2001
 
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
amazing2001
 
P(X=j).pdf
P(X=j).pdfP(X=j).pdf
P(X=j).pdf
amazing2001
 
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
amazing2001
 
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
amazing2001
 
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
amazing2001
 
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
amazing2001
 
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
amazing2001
 
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
amazing2001
 
P(1.63z2.4).pdf
P(1.63z2.4).pdfP(1.63z2.4).pdf
P(1.63z2.4).pdf
amazing2001
 
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
amazing2001
 
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
amazing2001
 
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
amazing2001
 
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
amazing2001
 
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
amazing2001
 
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
amazing2001
 
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
amazing2001
 
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
amazing2001
 
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
amazing2001
 
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
amazing2001
 

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

Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 

Recently uploaded (20)

Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 

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.