Question: Hi PLEASE I NEED HELP WITH THIS FILE FROM BOOK Abstraction and Design Using Java 3rd Edition 1.What are the two parts of an ADT?
Hi
PLEASE I NEED HELP WITH THIS FILE FROM BOOK Abstraction and Design Using Java 3rd Edition
1.What are the two parts of an ADT? Which part is accessible to a user and which is not? Explain the relationships between an ADT and a class, between an ADT and an interface, and between an interface and classes that implement the interface.
2. Explain how an interface is like a contract.
3.What are two different uses of the term interface in programming?
4. Explain the effect of each valid statement in the following fragment. Indicate any invalid statements.
Computer c1 = new Computer();
Computer c2 = new Computer("Ace", "AMD", 8.0, 500, 3.5);
Notebook c3 = new Notebook("Ace", "AMD", 4.0, 500, 3.0);
Notebook c4 = new Notebook("Bravo", "Intel", 4.0, 750, 3.0, 15.5, 5.5);
System.out.println(c2.manufacturer + ", " + c4.processor);
System.out.println(c2.getDiskSize() + ", " + c4.getRamSize());
System.out.println(c2.toString() + " " + c4.toString());
Note: for the first four, a single sentence answer is enough. For the last three, simply show the output is generated
5. For the loop body in the following fragment, indicate which method is invoked for each value of i.
What is printed?
Computer comp[] = new Computer[3];
comp[0] = new Computer("Ace", "AMD", 8, 750, 3.5);
comp[1] = new Notebook("Dell", "Intel", 4, 500, 2.2, 15.5, 7.5);
comp[2] = comp[1];
for (int i = 0; i < comp.length; i++) {
System.out.println(comp[i].getRamSize() + " " +
comp[i].toString());
}
6. When does Java determine which toString method to execute for each value of i in the for statement in the preceding question: at compile time or at run time? Explain your answer.
7. What are two important differences between an abstract class and an actual class?
8. What are the similarities? What do abstract methods and interfaces have in common? How do they differ?
9.What is the purpose of the if statement in the loop in Question 3? What would happen if it were omitted?
10. What is default or package visibility?
11. Discuss when abstract classes are used. How do they differ from actual classes and from interfaces?
12.What is the advantage of specifying an ADT as an interface instead of just going ahead and implementing it as a class?
13. Answer Review Question 10 for an ADT Complex that has methods for arithmetic operations on a complex number (a number with a real and an imaginary part). Assume that the same operations (+, , *, /) are supported. Also, provide methods toString, equals, and compareTo for the ADT Complex.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
