practicefinal08s

practicefinal08s - CSCI 180 Computer Science II Practice...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CSCI 180 – Computer Science II – Practice exam questions 1. Suppose the mod operator were not provided by Java. Write a recursive method that performs the function n mod m: int mod(int n, int m) examples: mod(5,2) => 1 mod(4,4) => 0 mod(15,6) => 3 2. Consider the following code: public class Bug { private int numLegs; private String location; public Bug(int n, String loc){ numLegs=n; location=loc; } public boolean isInsect(){ boolean result=false; if (numLegs==6) result=true; return result; } public int getNumLegs() { return numLegs; } public String getLocation() { return location; } } a) Write a class Insect that inherits from Bug. Insects have 6 legs. Include a (1) constructor that takes one argument, the location, (2) an isInsect method that returns true if this is an insect and false otherwise , and (3) overload toString so that it returns the number of legs followed by the location. b)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/04/2008 for the course CS 180 taught by Professor Johnson during the Spring '08 term at Xavier.

Page1 / 2

practicefinal08s - CSCI 180 Computer Science II Practice...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online