Use this interface definition to solve this problem. 1 public interface QueueADT { 2 /* Set...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Use this interface definition to solve this problem. 1 public interface QueueADT<E> { 2 /* Set the queue to its initial state. */ public void clear(); AWN 3 4 5 /* Add an element to the queue (on rear). */ public boolean enqueue (E it); 6 7 in 8 9 10 11 12 /* Returns the element from front of the queue without removing it. */ 13. 14 public E frontValue(); 15 16 /* Return the number of elements in the queue. */ 17 public int numElements(); 18 19 /* Is the queue empty? */ 20 public boolean isEmpty(); 21 } 25 /* Remove the element from front of the queue and return it. */ public E dequeue (); HH Write a method that removes all non-positive numbers stored in a queue and keeps the rest. Remember that you must remove elements from the queue by using dequeue () and add elements using enqueue (). The general algorithm ought to be: remove an element, and if it is positive add it back to the queue. If it is not, discard it. Repeat this until you have explored all elements in the queue. You must keep track of your progress, do not rely on A numElements () as that number will change as you start eliminating elements from the list, thus making iteration G based on that number unreliable. Your Answer: 1 void removeNonPositive (QueueADT<Integer> queue) H ~ M & in 2 { 3 4} Check my answer! Reset Next exercise Feedback Your feedback will appear here when you check your answer. Your Answer: 1 public int compareTo (Course o) H ~ M tin 2 { 3 4} 5 Check my answer! Reset Next exercise Feedback Your feedback will appear here when you check your answer. X1068: Compare Two Course Numbers You are writing a system to keep track of courses offered by your department. You have to implement a method to compare two Course objects and order them in numeric sequence, ignoring the name of the department. This would allow us to sort a list of courses by their number, ignoring the department (e.g., ITSC). This problem uses the Course definition as shown below: public class Course { private String dept; // ITSC, SPAN, etc. private int num; // 2214, 1212, etc. 4 5 6 String getDept() { return dept; } 7 int getNum () { return num; } 8} Write a compare() method to compare two Course objects. The comparison should order the courses based on their numbers ignoring the department. 1 public class CompareCourseNumbers 2 implements Comparator<Course> { 3 4 5 6} public Course (String d, int n) {...} // you must define int compare (Course o1, Course 02) { .. } This method should return: -1 if 01.getNum () less than 02.getNum () • O if 01.getNum() equals 02.getNum() • otherwise return 1. You are not allowed to use equals() to make the comparison. Your Answer: Feedback X1064: Complete CompareTo(Course) You are writing a system to keep track of courses offered by your department. You have to implement a compare To method as defined in the Comparable () interface. This problem uses the Course class definition as shown below: 1 public class Course implements Comparable<Course> { 2 private String dept; // ITSC, SPAN, etc. 3 private int num; // 2214, 1212, etc. 4 5 public Course(String d, int n) { ... } String getDept () { return dept; } int getNum() { return num; } 67 8 D CO 9 10 11} // you must define public int compareTo (Course o) { - } Write a compare to method for the Course class that compares an object of type Course with the argument o, also of type Course. The method must first compare the department (i.e. ITSC) and then if the department is the same, then compare the number (e.g., 2214). The logic is as follows. • -1 if this.getDept () is less than o.getDept() • 1 if this.getDept() is greater than o.getDept() • if this.getDept() equals o.getDept() o O if this.getNum() equals o.getNum() o -1 if this.getNum () less than o.getNum() o 1 if this.getNum() greater than o.getNum() Attempts remaining: 20 1 public int compare (Course o1, Course 02) HN M&in 2 { 3 4} 5 X1066: Remove At Most n Use this interface definition to solve this problem. 1 public interface QueueADT<E> { 2 public void clear(); 3 public boolean enqueue (E it); 4 public E dequeue (); 5 public E frontValue(); 6 public int numElements(); 7 public boolean isEmpty(); 8} Write a method that removes at most n elements from the queue. If the queue has less than n elements, then just empty the queue by calling clear(). Make sure you use the interface from above. Your Answer: Feedback 1 public void removeAtMost (QueueADT<String> queue, int n) 2|{ 3 4} 5 Your feedback will appear here when you check your answer. Use this interface definition to solve this problem. 1 public interface QueueADT<E> { 2 /* Set the queue to its initial state. */ public void clear(); AWN 3 4 5 /* Add an element to the queue (on rear). */ public boolean enqueue (E it); 6 7 in 8 9 10 11 12 /* Returns the element from front of the queue without removing it. */ 13. 14 public E frontValue(); 15 16 /* Return the number of elements in the queue. */ 17 public int numElements(); 18 19 /* Is the queue empty? */ 20 public boolean isEmpty(); 21 } 25 /* Remove the element from front of the queue and return it. */ public E dequeue (); HH Write a method that removes all non-positive numbers stored in a queue and keeps the rest. Remember that you must remove elements from the queue by using dequeue () and add elements using enqueue (). The general algorithm ought to be: remove an element, and if it is positive add it back to the queue. If it is not, discard it. Repeat this until you have explored all elements in the queue. You must keep track of your progress, do not rely on A numElements () as that number will change as you start eliminating elements from the list, thus making iteration G based on that number unreliable. Your Answer: 1 void removeNonPositive (QueueADT<Integer> queue) H ~ M & in 2 { 3 4} Check my answer! Reset Next exercise Feedback Your feedback will appear here when you check your answer. Your Answer: 1 public int compareTo (Course o) H ~ M tin 2 { 3 4} 5 Check my answer! Reset Next exercise Feedback Your feedback will appear here when you check your answer. X1068: Compare Two Course Numbers You are writing a system to keep track of courses offered by your department. You have to implement a method to compare two Course objects and order them in numeric sequence, ignoring the name of the department. This would allow us to sort a list of courses by their number, ignoring the department (e.g., ITSC). This problem uses the Course definition as shown below: public class Course { private String dept; // ITSC, SPAN, etc. private int num; // 2214, 1212, etc. 4 5 6 String getDept() { return dept; } 7 int getNum () { return num; } 8} Write a compare() method to compare two Course objects. The comparison should order the courses based on their numbers ignoring the department. 1 public class CompareCourseNumbers 2 implements Comparator<Course> { 3 4 5 6} public Course (String d, int n) {...} // you must define int compare (Course o1, Course 02) { .. } This method should return: -1 if 01.getNum () less than 02.getNum () • O if 01.getNum() equals 02.getNum() • otherwise return 1. You are not allowed to use equals() to make the comparison. Your Answer: Feedback X1064: Complete CompareTo(Course) You are writing a system to keep track of courses offered by your department. You have to implement a compare To method as defined in the Comparable () interface. This problem uses the Course class definition as shown below: 1 public class Course implements Comparable<Course> { 2 private String dept; // ITSC, SPAN, etc. 3 private int num; // 2214, 1212, etc. 4 5 public Course(String d, int n) { ... } String getDept () { return dept; } int getNum() { return num; } 67 8 D CO 9 10 11} // you must define public int compareTo (Course o) { - } Write a compare to method for the Course class that compares an object of type Course with the argument o, also of type Course. The method must first compare the department (i.e. ITSC) and then if the department is the same, then compare the number (e.g., 2214). The logic is as follows. • -1 if this.getDept () is less than o.getDept() • 1 if this.getDept() is greater than o.getDept() • if this.getDept() equals o.getDept() o O if this.getNum() equals o.getNum() o -1 if this.getNum () less than o.getNum() o 1 if this.getNum() greater than o.getNum() Attempts remaining: 20 1 public int compare (Course o1, Course 02) HN M&in 2 { 3 4} 5 X1066: Remove At Most n Use this interface definition to solve this problem. 1 public interface QueueADT<E> { 2 public void clear(); 3 public boolean enqueue (E it); 4 public E dequeue (); 5 public E frontValue(); 6 public int numElements(); 7 public boolean isEmpty(); 8} Write a method that removes at most n elements from the queue. If the queue has less than n elements, then just empty the queue by calling clear(). Make sure you use the interface from above. Your Answer: Feedback 1 public void removeAtMost (QueueADT<String> queue, int n) 2|{ 3 4} 5 Your feedback will appear here when you check your answer.
Expert Answer:
Answer rating: 100% (QA)
Method removeNonPositiveQueueADT Integer queue java void removeNonPositiveQueueADT Integer queue Cre... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
*16.1 (Use radio buttons) Write a GUI program as shown in Figure 16.36a. You can use buttons to move the message to the left and right and use the radio buttons to change the color for the message...
-
The Research paper outline on the topic of advertising needs to provide information on the following questions 1). What is your thesis? What key arguments will you be making in the paper? 2). What...
-
If the focal length of a lens is 3 centimeters and the image distance is 5 centimeters from the lens, what is the distance from the object to the lens?
-
On December 31, 2021, Tiny Tims Tech, Inc. a private company who follows ASPE, leased a colour copier from Cory Copy Corporation at a price of $479,079. The lease agreement specifies annual payments...
-
Find all values of k for which 2k2 112
-
What is meant by the term petitioner?
-
Expected value with additional information Refer to the data in Problem 24-7 and assume that based on past experience, the probability of demand per day has been determined as follows: Problem 24-7...
-
On June 1, 2015 Elisha and Ezra (who are equal partners) contribute property to form the Double E Partnership. Elisha contributes cash of $200,000. Ezra contributes a building and land with an...
-
Find the derivative. t4 d [4 U3 du dt 0 a. by evaluating the integral and differentiating the result. b. by differentiating the integral directly. a. Evaluate the definite integral. d d 2+ 10 dt du =...
-
1. The clear majority of compute nodes in modern enterprise environments are networked. Can you think of any circumstances where a compute node would NOT be networked? Describe. 2. Many commercial...
-
Investing $2,000,000 in TQM's Channel Support Systems initiative will at a minimum increase demand for your products 1.7% in this and in all future rounds. (Refer to the TQM Initiative worksheet in th
-
Child abuse laws differ from state to state, but, in most states, persons required to report cases of child abuse are protected. The person reporting abuse does not have to be absolutely certain...
-
Randomly list the 10 examples you identified, keeping the rationale for each hidden. Exchange lists with another group. Each group should discuss the list given to it by the other group and classify...
-
Principles of ethics are universal rules of conduct. Autonomy is the right of a person to make his or her own decisions. Beneficence is the principle of doing good, demonstrating kindness, showing...
-
Determine and discuss the degree of agreement or disagreement among the various groups in the class. Break into small groups of four to five people. Assume your group is the executive committee (that...
-
Abortion is the premature termination of a pregnancy, either spontaneous or induced. Roe v. Wade is the Supreme Courts ruling that, within certain guidelines, women are allowed to make decisions...
-
Bilboa Freightlines, S.A., of Panama, has a small truck that it uses for intracity deliveries. The truck is worn out and must be either overhauled or replaced with a new truck. The company has...
-
What are multinational corporations (MNCs) and what economic roles do they play?
-
Patty Bayan is a single taxpayer living at 543 Space Drive, Houston, TX 77099. Her Social Security number is 466-33-1234. For 2012, Patty has no dependents, and her W-2 from her job at a local...
-
In 2012, Gale and Cathy Alexander hosted an exchange student, Axel Muller, for 9 months. Axel was part of International Student Exchange Programs (a qualified organization). Axel attended tenth grade...
-
During 2012, Tom sold Sears stock for $10,000. The stock was purchased 4 years ago for $13,000. Tom also sold Ford Motor Company bonds for $35,000. The bonds were purchased 2 months ago for $30,000....
-
Karanga Company purchased land containing an estimated 20 million tons of ore for a cost of $6,600,000. The land without the ore is estimated to be worth $1,200,000. The company expects that all the...
-
The airline industry was hit particularly hard after the 9/11 attacks on the World Trade Center in 2001. In 2002, Southwest Airlines, one of the healthier airlines companies, made a decision to...
-
Gent Manufacturing Company purchased a robot for $720,000 at the beginning of year 1. The robot has an estimated useful life of four years and an estimated residual value of $60,000. The robot, which...
Study smarter with the SolutionInn App