AVA Programming Problem 1 – High School Locker A locker for a high school student has a locker number, a student name assigned to it, a number of books stored inside the locker, and also a combination lock. The lock is constructed with a combination that has 3 numbers between 0 and 39. The lock is opened if the user turns the lock to the right to the first combination number, and then left to the second combination number, and then right to third combination number. When the dial is reset it will then be pointing to 0. Create a class to represent the locker and another class to represent the combination lock. The Locker class will include an attribute that is of type CombinationLock. Each class must include a constructor with no input argument and also a constructor that requires input arguments for all attributes. Each class must include the appropriate set and get methods. Each class must include a method to print out all attributes. The CombinationLock class must include the following problem specific methods: A method named resetDial that resets the dial to position 0. A method named turnLeft that will turn the dial to the left a certain number of ticks from the current position. The number of ticks to turn will be passed as an input argument to this method. A method named turnRight that will turn the dial to the right a certain number of ticks from the current position. The number of ticks to turn will be passed as an input argument to this method. A method named openLock that will try to open the lock with a combination. The combination that is tried will be passed as three input arguments to this method. This method will return true if the lock opens successfully and will return false if the lock is not opened successfully. The Locker class must include the following problem specific methods: A method named putBookInLocker that puts one additional book into the locker. This method does not take any input arguments and does not return a value. A method named removeBookFromLocker that tries to remove one book from the locker. This method does not take an input argument, but does return a value. The book returns true if the book is removed successfully and returns false if the book is not removed successfully. A method named openLocker that will try to open the locker. This method will prompt the user to input the three numbers in the combination to try. This method will print out the success or failure of opening the locker. The main method will be in a separate class from the Locker and the CombinationLock classes. This main method must complete the following: Creates locker number 100 for Mickey Mouse. The combination for this locker is 28, 17, 39. This locker will include 3 books. Create locker number 275 for Donald Duck. The combination for this locker is 35, 16, 27. This locker will include 0 books. Try to open the locker for Mickey Mouse using 15, 18, 18. Add three books to Mickey Mouse’s locker. Remove one book from Donald Duck’s locker. After all of these actions have been completed, print out the current state of both lockers to the console. Directions You may only use statements that are discussed in the book through Chapter 10. Console input and output must be used to solve this problem.
Max Function
Statistical function is of many categories. One of them is a MAX function. The MAX function returns the largest value from the list of arguments passed to it. MAX function always ignores the empty cells when performing the calculation.
Power Function
A power function is a type of single-term function. Its definition states that it is a variable containing a base value raised to a constant value acting as an exponent. This variable may also have a coefficient. For instance, the area of a circle can be given as:
JAVA Programming Problem 1 – High School Locker
A locker for a high school student has a locker number, a student name assigned to it, a number of books stored inside the locker, and also a combination lock. The lock is constructed with a combination that has 3 numbers between 0 and 39. The lock is opened if the user turns the lock to the right to the first combination number, and then left to the second combination number, and then right to third combination number. When the dial is reset it will then be pointing to 0.
Create a class to represent the locker and another class to represent the combination lock. The Locker class will include an attribute that is of type CombinationLock. Each class must include a constructor with no input argument and also a constructor that requires input arguments for all attributes. Each class must include the appropriate set and get methods. Each class must include a method to print out all attributes.
The CombinationLock class must include the following problem specific methods:
- A method named resetDial that resets the dial to position 0.
- A method named turnLeft that will turn the dial to the left a certain number of ticks from the current position. The number of ticks to turn will be passed as an input argument to this method.
- A method named turnRight that will turn the dial to the right a certain number of ticks from the current position. The number of ticks to turn will be passed as an input argument to this method.
- A method named openLock that will try to open the lock with a combination. The combination that is tried will be passed as three input arguments to this method. This method will return true if the lock opens successfully and will return false if the lock is not opened successfully.
The Locker class must include the following problem specific methods:
- A method named putBookInLocker that puts one additional book into the locker. This method does not take any input arguments and does not return a value.
- A method named removeBookFromLocker that tries to remove one book from the locker. This method does not take an input argument, but does return a value. The book returns true if the book is removed successfully and returns false if the book is not removed successfully.
- A method named openLocker that will try to open the locker. This method will prompt the user to input the three numbers in the combination to try. This method will print out the success or failure of opening the locker.
The main method will be in a separate class from the Locker and the CombinationLock classes. This main method must complete the following:
- Creates locker number 100 for Mickey Mouse. The combination for this locker is 28, 17, 39. This locker will include 3 books.
- Create locker number 275 for Donald Duck. The combination for this locker is 35, 16, 27. This locker will include 0 books.
- Try to open the locker for Mickey Mouse using 15, 18, 18.
- Add three books to Mickey Mouse’s locker.
- Remove one book from Donald Duck’s locker.
- After all of these actions have been completed, print out the current state of both lockers to the console.
Directions
- You may only use statements that are discussed in the book through Chapter 10.
- Console input and output must be used to solve this problem.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images