Programming Problem 1 – High School Locker



Unit 3 Programming Problems WorksheetProgramming Problem 1 – High School LockerA 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.DirectionsYou may only use statements that are discussed in the book through Chapter 10. Console input and output must be used to solve this problem.Grading RubricTaskPointsCombinationLock - attributes1CombinationLock - constructor1CombinationLock - resetDial1CombinationLock - turnLeft1CombinationLock - turnRight1CombinationLock - openLock1Locker - attributes1Locker - constructor1Locker - putBookInLocker1Locker - removeBookFromLocker1Locker - openLocker1Main method2Console output2Total15Screenshots Programming Problem 2 - Cycle[A] Create a class called “Cycle” which has two instance integer variables as properties, “numberOfWheels” and “weight.” ?Create a constructor with two parameters, using the same variable names in the parameter list. ?Assign each variable to numberOfWheels” and “weight” respectively. ?Write a separate application to test the class and display its properties. Note: Do not change the names of the instance variables or the variables listed in the constructor’s parameter list. [B] Edit your class Cycle by adding a default constructor which will assign the default values of 100 to represent the numberOfWheels, and 1000 to represent the weight, by invoking a call to the other constructor. ?Modify your application created in [A] to test the class.Directions[A] Create a class called CycleDeclare integer instance variables numberOfWheels and weight as private.Include a toString() method in the Cycle class. ?No set or get methods are included.Create a constructor with two parameters, using the same variable names numberOfWheels and weight in the parameter list. Complete the constructor as necessary.Create a separate application to test the class.Create an object of the Cycle class.Display the properties of the object.[B] Add a default constructorEdit the default constructor such that the default constructor will invoke the existing constructor with the default values of 100 to represent the numberOfWheels, and 1000 to represent the weight. Invoke the constructor using the “this” reference. Create the second constructor which will receive the two arguments.Create a separate application to test the class.Create an object of the Cycle class.Display the properties of the object.Grading RubricTaskPointsClass created and named2Constructor(s) completed correctly2toString() methods written correctly1Successful invocation (constructor to constructor)2Properties output correctly1Proper documentation / Pseudocode1Program works effectively1Total 10Screenshots Programming Problem 3 - BookA Book has such properties as title, author, and numberOfPages. A Volume will have properties such as volumeName, numberOfBooks, and an array of book objects (Book [ ]). You are required to develop the Book and Volume classes, then write an application (DemoVolume) to test your classes. The directions below will give assistance.Create a class called Book with the following properties using appropriate data types: Title, Author, numberOfPages, Create a second class called Volume with the following properties using appropriate data types: volumeName, numberOfBooks and Book [ ]. The Book [ ] contains an array of book objects.DirectionsCreate a class called Book with the following properties using appropriate data types: Title, Author, numberOfPages, The only methods necessary in the Book class, for this exercise, are the constructor and a toString().Create a second class called Volume with the following properties using appropriate data types: volumeName, numberOfBooks and Book [ ]. Book [ ] will contain an array of book objects. The only methods necessary in the Volume class, for this exercise, are the constructor, toString() and getBookArray(). The getBookArray returns a string of book properties for each book.Create an application called DemoVolume. In the main method, Create an array of book objects to be added to the volume.Create a volume object called volume1.Display the properties of volume1.GradingTaskPointsBook class properties created2Volume class created correctly1Constructors created correctly2"this" reference used effectively1Array of book objects created2Proper documentation / Pseudocode1Program works effectively1Total10Screenshots Programming Problem 4 – BuilderWrite a program which will accept a string from the keyboard, “Java is fun!” Your program must determine the capacity of the string. Then, append a second string, “I love it!” to the first string. At this point you will enter a string “Yes, “ and insert this string so that the output of the entire string will display “Java is fun. Yes, I love it!”DirectionsCreate a class called Builder. Using the StringBuilder class, write a program which will accept a string from the keyboard, “Java is fun!” Your program must determine and display the capacity of the string. Append a second string, “I love it!” to the first string. Require the user to enter a string “Yes, “ Insert the string, “Yes ” at the correct location, such that the output of the entire string will be “Java is fun. Yes, I love it!” Display your output using clear and appropriate messages. GradingTaskPointsClass created and named1String variables declared and initialized2Appropriate use of StringBuilder2Appropriate use of string methods3Appropriate messages displayed1Proper documentation / Pseudocode1Total10Screenshots Programming Problem 5 – CharacterArrayWrite a program which will store the following string into a character array:6901 Sudley Road Manassas VA Your program will display each original character, determine and display whether the character is a digit or a letter, and redisplay the character according to the directions below.DirectionsCreate a class called CharacterArray. The scanner class is not required. Initialize the character array with the given string. Write a program which will accept an alpha numeric string at the keyboard. Store the string, of any length, into a character array, for example: NVCC Manassas Campus 6901 Sudley Road Manassas VA 20109 For each visible character: Display the original characterDetermine and display whether the character is a digit or a letterIf the character is a lower case letter, redisplay the character in upper caseIf the character is a upper case letter, redisplay the character in lower caseIf the character is a digit, display it as an * (asterisk)Display your output using clear and appropriate messages. GradingTaskPointsClass created and named1String variables declared and initialized2Original characters displayed1Appropriate use of string methods2Appropriate condition statements used2Appropriate messages displayed1Proper documentation / Pseudocode1Total10Screenshots ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download