"is-a" relationship between internships class interface extending an interface implementing an interface
Added by Colleen S.
Step 1
Let's think step by-step. Show more…
Show all steps
Your feedback will help us improve your experience
Akash M and 54 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Use these class headers to determine whether each assignment statement is valid or invalid. public interface FinancialAidEligible public abstract class Person public class Student extends Person public class Undergraduate extends Student implements FinancialAidEligible Person p1 = new Person(...); Person p1 = new Student(...); FinancialAidEligible p1 = new Student(...); FinancialAidEligible p1 = new Undergraduate(...); FinancialAidEligible p1 = new FinancialAidEligible (...); Student[] people = new Student[10]; Person[] people = new Person[10]; FinancialAidEligible[] people = new FinancialAidEligible[10];
Akash M.
Assume that you are a professional software developer, working on the next-generation compiler for a programming language. Now, it is summertime, and you are supervising a group of summer interns. You want these interns to implement the following feature using your compiler, but you do not want them to modify or even read your proprietary code that implements the core of the compiler. The new feature is to count the total number of instructions in a program written in the programming language. You have decided to use the Visitor design pattern. You want the summer interns to write as much code as possible. The question is, which of the following code should NOT be left for the summer interns to write? Part A: interface Code { void accept(CodeVisitor visitor); } Part B: interface CodeVisitor { void visit(Program p); void visit(Function f); void visit(Statement s); } Part C: class Program implements Code { public void accept(CodeVisitor v) { v.visit(this); } } class Function implements Code { public void accept(CodeVisitor v) { v.visit(this); } } class Statement implements Code { public void accept(CodeVisitor v) { v.visit(this); } } Part D: class CodeCountingVisitor implements CodeVisitor { public void visit(Program p) { ... } public void visit(Function f) { ... } public void visit(Statement s) { ... } } Part E: public class Main { public static void main(...) { Program p = new Program(); p.accept(new CodeCountingVisitor()); } } Questions: Should "Part A" be left for the summer interns to write? Should "Part B" be left for the summer interns to write? Should "Part C" be left for the summer interns to write? Should "Part D" be left for the summer interns to write? Should "Part E" be left for the summer interns to write?
Supreeta N.
Implement the ArrayQueue class In the 'Queues' lecture, review the 'Introduce next lab' section. See here that we can use a circular array to implement the queue data structure. You must write a class named ArrayQueue that does this. ArrayQueue will be a generic class that implements our generic QueueInterface interface. This demonstrates the Java interface feature, where we have already implemented the queue dynamically, using the LinkedQueue class covered during the lecture. Many classes are given to you. Download and unzip the Circular array project from Canvas, 'Queues' module, Example programs. Open the project in BlueJ and see Tester::main(). This shows the methods you have to implement. You must write your code in the ArrayQueue class, which implements the circular array. In ArrayQueue, you must use only the instance variables given to you; you are not allowed to add more. Other than adding your new methods to ArrayQueue and adding a new QueueOverflowException class, the provided code must not be altered in any way. Hints: - Note that the array implementation does not require our Item class. Instead, the array contains elements of the generic data type T. - The syntax in the ArrayQueue constructor to create an array of the generic data type T is awkward, so it has been given to you. See how the code creates an array of Object, which is then typecast to the data type T. Cool! Also, see here how I've changed the usual initializations of front and rear because I want to force wrapping to happen early. - Queue overflow was not a problem for our previous linked list implementation, but it is obviously a problem for an array implementation. So you will have to add a new QueueOverflowException class. Run the program to test your completed ArrayQueue class. When correct, save the output as an output.txt text file, saved in the BlueJ project folder. Required: Your program must be correct, simple, and clear: - Clear, consistent layout and indentation. - You must Javadoc comment every class, method, and anything that is not simple and clear. ('How to write Javadoc comments' has been added to Course information). - Clear, meaningful variable and method names.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD