do the follwing to the code : 1) Document  class. 2) Provide a tester class and test a scenario in which you create a comboLock having the code (25, 36, 19), unlock it successfully, and print the status of the lock after each turn. 3) Put the ComboLock class and the tester class in two distinct packages

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

do the follwing to the code :

1) Document  class.
2) Provide a tester class and test a scenario in which you create a comboLock having the code (25, 36, 19), unlock
it successfully, and print the status of the lock after each turn.
3) Put the ComboLock class and the tester class in two distinct packages

 

code :

public class ComboLock 
{
    private final int key1;
    private final int key2;
    private final int key3;
    private int status;
    private int current;
    public ComboLock(int s1, int s2, int s3) 
    {
        key1 = s1;
        key2 = s2;
        key3 = s3;
        current = 0;
        status = 0;
    }
    public void reset() 
    {
        status = 0;
        current = 0;
        System.out.println("Lock is reset. ");
    }
    public void turnLeft(int ticks) 
    {
        current = current - ticks;
        if (current < 0) 
        {
            current = 39-current;
        }
        System.out.println("Left ticks = [" + ticks + "] and current = " + current);
        if (status == 1 && current == key2) 
        {
            status = 2;
System.out.println("no2");

        } 
        else 
        status = 0;
    }
    public void turnRight(int ticks) 
    {
        current = current + ticks;
        if (current > 39) 
        {
            current = current - 39;
        }
        System.out.println("Right ticks = [" + ticks + "] and current = " + current);
        if (status == 0 && current == key1) 
        {
            status = 1;
System.out.println("yes1");
        } 
        else if (status == 2 && current ==key3) 
        {
            status = 3;
            System.out.println("yes2");
        } 
        else 
        status = 0;
    }

    public boolean getStatus() 
    {
        if (status == 3) 
        {
            System.out.println("Lock is open.");
            return true;
        } 
        else 
        {
            System.out.println("Lock is not open.");
            return false;
        }
    }
    public static void main(String[] args) 
    {
        ComboLock c = new ComboLock(25,36,19);
        c.reset();
        c.turnRight(25);
        c.getStatus();
        c.turnLeft(-11);
        c.getStatus();
        c.turnRight(-17);
        c.getStatus();
    }
}

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Concept of pointer parameter
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY