CSC 1302 Principles of Computer Science II Assignment 6: Java Inheritance

$30.00

Category: Tags: , , , , , You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (7 votes)

Purpose:
A class in Java can extend another class to become a subclass. When class B extends class A, B
becomes subclass (child) and A becomes superclass (parent). The subclass can reuse all the
features of the parent class. An interface defines a set of specifications that other classes must
implement. Implementing an interface allows a class to become more formal about the behavior
it promises to provide.
In this assignment, we will practice how to extend classes and create corresponding objects. We
will also practice using the interface. The meaning of implementing an interface is not very
different than extending a class but it comes with an additional caveat. When a class implements
an interface, it has to provide an implementation of all methods declared inside interface.
Program #1:
Finish Exercises 5, 6, 7, 8 in the end of Chapter 9 (Page657 and 658). A scanned copy is as the
following.

Program #2:
Given partial codes of the Colored interface and Point class as the following:
//Colored interface
public interface Colored{
public String getColor();
}
//Point class
public class Point {
private int x;
private int y;
public Point() {
this(0, 0);
}
public Point(int x, int y) {
setLocation(x, y);
}
public boolean equals(Object o) {
if (o instanceof Point) {
Point other = (Point) o;
return x == other.x && y == other.y;
} else {
return false;
}
}
public void setLocation(int x, int y) {
this.x = x;
this.y = y;
}
public String toString() {
return “(” + x + “, ” + y + “)”;
}
}
Write ColoredPoint class so that implements the Colored interface and extends Point so that
Points have colors. Override toString method to print out the coordinates and color of the point,
override equals method so that it compares color as well. And write the necessary constructors,
accessors and mutators.
Write a client class and create objects of the ColoredPoint class. Print out the colored point and
compare if they are equal.
Criteria:
1. Upload all of the .java and the .class files to the CSc1302 dropbox on http://
icollege.gsu.edu.
2. Your assignment will be graded based on the following criteria: (a) Are your programs
runnable without errors? (b) Do your programs complete the tasks with specified outputs?
(c) Do you follow the specified rules to define your methods and programs? (d) Do you
provide necessary comments include the programmer information, date, title of the
program and brief description of the program.
3. Make sure that both the .java and .class files are named and uploaded to icollege
correctly. If any special package is used in the program, be sure to upload the package
too. Should you use any other subdirectory (whatsoever) your program would not be
graded, and you will receive a 0 (zero).
4. No copying allowed. If it is found that students copy from each other, all of these
programs will get 0.