0% found this document useful (0 votes)
314 views1 page

Comp1161 Oop

This document provides code examples and exercises for a tutorial on object-oriented programming concepts. It includes: 1) UML diagrams to represent vehicles and books, then converting those to Java classes. 2) Incomplete code examples for a CableGuide interface and subclass that need errors fixed and implementation completed. 3) An explanation of what will happen when calling toString() on a School object that extends the Institution class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
314 views1 page

Comp1161 Oop

This document provides code examples and exercises for a tutorial on object-oriented programming concepts. It includes: 1) UML diagrams to represent vehicles and books, then converting those to Java classes. 2) Incomplete code examples for a CableGuide interface and subclass that need errors fixed and implementation completed. 3) An explanation of what will happen when calling toString() on a School object that extends the Institution class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

COMP1161 Tutorial Sheet 7

1.

2.

Create the UML representation of the following:


a. All vehicles have a chassis number, engine number and a manufacture date. A truck is a vehicle
with a tipper registration code and a max laden weight. A car is a vehicle which has a cc rating.
b. All books have an author, ISBN, and title. An author has a name, address, and affiliation and
publication license code.
c. Convert the UML from parts (a) and (b) to Java.
d. Explain any differences/similarities in the scenarios that influenced the design for each.
Given the code labeled codeA, and codeB. Correct the errors and complete implementation.

codeA

codeB

public interface CableGuide


{
int[] flow = new int[10];
public CableGuide(){
for(int i=0; i<10; i++)
flow[i] = i+1;
}
public String toString(); // print name of guide
public int changeChannel(int current); //advance
channel by 1
}

public abstract class CableGuide2


{
int[] flow = new int[10];
public CableGuide2(){
for(int i=0; i<10; i++)
flow[i] = i+1;
}
public String toString(){
String str=;
for(int x=0; x<10; x++){
str = str + \n + flow[x];
PLEASE
}
return str;
IGNORE
}
public abstract int changeChannel(int current); //advanced
channel by 1
}
public class Guide2 extends CableGuide2{

public class Guide extends CableGuide{


private String guidName;
public Guide(){
}
}

3. Given
package tutorial7;
public class Institution{
private int instCode;
protected String parish;
public Institution(int c, String p){
instCode = c;
parish = p;
}

a.

package tutorial 7;
public class School extends Institution{
int prinID; int regionNum;
public School(int code, String p){
super(code,p);
}
public String toString(){
return (instCode + "\t"+ parish + "\t" + prinID + "\t" +
regionNum);
}
}

Explain what will happen if a program creates a School called uwi and instantiates it then executes the
following line of code (make adjustments if necessary):
uwi.toString();

You might also like