GMU Pez Candy Java Programming Questions

User Generated

evev1991

Programming

George Mason University

Description

Unformatted Attachment Preview

*Programming Problem 2: Pez Candy You may like the Pez candies and the wonderful dispensers that can be customized in so many ways. In each plastic container of Pez candy, the candies are of different colors, and they are stored in random order. Assume that you like the red candies only. Take a Pez dispenser, take out all candies one by one, eat the red ones, and put the others in a spare container you have at hand. Return the remaining candies in the initial container. Your Tasks: 1. Create a class PezCandy in which you implement an array-based stack 2. Create a class PezCandyDriver in which you solve the problem as described above 3. Create an algorithm showing how you take out the candies, eat the red ones, and put them back in the container, in the original order. Place the algorithm, as a comment in the top of your PezCandyDriver file 4. Use an initial Pez dispenser with 12 candies, in which the colors of the candies are randomly chosen from: red, yellow, green, pink, blue. Hints Use integer values associated with each color, and randomly generate the integer values. 5. Run the program and capture a snapshot showing the initial content of the Pez container, and the content after you ate all red candies. 6. If you implement all the required methods properly, the driver program should generate outputs similar to the following: *Programming Problem 3: Grading Exams Your instructor organizes tutoring sessions for students getting a score lower than the class average after each exam. The process is as follows: 1. After a paper is graded, it is placed in a stack and the score is added to the average. 2. After all papers are graded and the average score calculated, o o the papers are taken one by one and placed in the “needs tutoring” stack if the score is less than the average. the papers that are higher than the average are placed in the “no tutoring needed” stack. Create an application that helps your instructor organize the tutoring session. Your Tasks: 1. Create a class ExamPaper that has as attributes the student’s name, a String, and the exam score, an integer. Class should have constructor, set and get methods, as well as a toString method. 2. Create a link-based stack class, ExamPaperStack, that has additional methods besides the traditional ones (you may want to use the improved link-based stack class created for one of the guided assignment problems): o String toString()—creates and returns a string that correctly represents the current stack. o int size()—returns a count of how many items are currently on the stack. Do not add any instance variables to the ArrayBoundedStack class in order to implement this method. o T poptop( )—the “classic” pop operation, if the stack is empty it throws StackUnderflowException; otherwise it both removes and returns the top element of the stack. 3. Create a driver class ExamPaperOrganizer, that performs the operations described above: o Create the stack containing all exam papers, while adding the scores together. o Display the content of stack containing all graded exams. o Calculate the average score of the exam. o Display the average score. o Take out the papers from the initial stack and put them in two stacks, one for papers with a score lower than the average and the other for papers with a score equal to or above the average. o Display the content of the two stacks as well as the number of papers in each stack. 4. Run the program with the number of students of your choice, but no less than 5. 5. If you implement all the required methods properly, the driver program should generate outputs similar to the following:
Purchase answer to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

View attached ex...

Related Tags