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)
Answer Certainly Heres a method that removes all nonpositive numbers ... 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
-
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...
-
Wire Solutions Company's income statement for the month ended August 31, 2014, reported the following data: Before the financial statements were released, it was discovered that the current net...
-
Find the indicated power using De Moivres Theorem. (1 - 3 i ) 5
-
In 2014, political consulting firm Cambridge Analytica developed an app designed to create digital profiles of individuals via their information. Cambridge Analytica collected the data by inviting...
-
Sara Casper, a recent graduate of Rollings accounting program, evaluated the operating performance of Klumpe Companys six divisions. Sara made the following presentation to the Klumpe board of...
-
Calculate the dividends paid per share of common stock. ( Note: Number of shares shown on balance sheet is not shown in thousands. The number of shares " in thousands" is 2 , 0 0 0 . ) Round...
-
Determine V o in the circuit in Fig. 2.80. 14 2 16 2 25 V Vo 10 V +,
-
1. a) Find a general solution p(x) of y" - 2ay' + ay = 0. b) Find a general solution (x) of y" - 2ay' + (a-82)y = 0 in which e is a positive constant c) Show that, as 0, the solution in b) does not...
-
Credit Cards in Canada :Provide a detailed historical review of the evolution of Credit Cards in Canada including how and when credit cards were first established and who created them.Explain the...
-
Credit Card for Dummies 1. Why is a credit card not a cash card? 2. When should you use the credit card? 3. What are the benefits of using a credit card? 4. What should you do to get a good credit...
-
Ensuring Sustainability for a business 1. Discuss ethical leadership and commitment to improve society, adhering to sustainable development goals. 2. What is the importance ethical leadership and...
-
how to calculate operation cash flow to total liabilities ratio? Explain with Example.
-
You are the CMO for an Australian University, and your Vice - Chancellor (same as CEO) has just come back from an higher education conference and a marketing consultant was taking about customer...
-
WITH THE IMAGES POSTED BELOW CAN YOU GIVE ME A DETAILED ANAYSIS OR EXPLAINATION ON HOW THE COMPANY ARIBNB TREATS OR DEAL WITH INTANGIBLE ASSETS/ AMORITIZATION. I JUST NEED A BREIF EXPLAINATION TO...
-
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....
-
Classify each of the following as either a policy instrument or an intermediary target. Explain your answer. a. Long-term interest rates b. Central bank interest rates c. M2 d. Reserve requirements
-
The New York Fed executes foreign exchange interventions for the Federal Reserve system. Go to https://www.newyorkfed.org/markets/quar_reports.html to see quarterly summaries of the Feds foreign...
-
The New Zealand dollar to U.S. dollar exchange rate is 1.38, and the British pound to U.S. dollar exchange rate is 0.65. If you find that the British pound to New Zealand dollar is trading at 0.5,...
Study smarter with the SolutionInn App