Hi PLEASE I NEED HELP WITH THIS FILE FROM BOOK Abstraction and Design Using Java
ID: 3890840 • Letter: H
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? 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.
Explanation / Answer
Answer:
An ADT consists of data elements and methods that operate on that data. The user can access the operations, but cannot access the internal structure of the data elements. A class provides one way to implement an ADT in Java. A Java interface is a way to specify or describe an ADT. An interface defines a set of methods, and a class that implements an interface must implement these methods and define any necessary data fields.
2)Answer:
An interface specifies methods that a class implementing that interface must provide. For eachmethod specified, the name, return type, and the parameters are specified. For each parameter the typeis specified. A user of a class implementing the interface can be assured that the methods are asspecified and the developer of class must provide the specified methods. Thus, the interface defines acontract between the user of a class and its developer.
3)Answer:
interfaces can:
10)Answer:
Default Visibility. If you do not specify public or private for a variable or a method, then it will have default visibility. Default visibility allows a variable or method to be seen by all methods of a class or other classes that are part of the samepackage. A package is a group of related classes.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.