c398s99f

c398s99f - CSc 398 Final Examination Wednesday 12 May 1999...

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

View Full Document Right Arrow Icon
CSc 398 Final Examination Wednesday 12 May 1999 Page 1 !!!!!!!!!!!!!!!!!!!!SUGGESTED ANSWERS!!!!!!!!!!!!!!!!!!!!! 1. (35 points) (I try very hard never to use the same test question twice. The economics professor can use the same question twice, because the answers change. Anyway, I am using one of the questions from the mid-term examination.) Write the Java code for a class Counter. An instance of Counter can only count between some limits which are specified when the instance is instantiated. All Counter errors should be handled with the help of a class CounterException. class Counter{ int min,max,count; private Counter(){} //Don't allow default constructor public Counter(int low,int high) throws CounterException{ if(low>high) throw new CounterException("Bad initial values"); min=low; max=high; count=low; } public void inc() throws CounterException{ if(count>=max) throw new CounterException("Counter Overflow"); count++; } public void dec() throws CounterException{ if(count<=min) throw new CounterException("Counter Underflow");
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.

Page1 / 2

c398s99f - CSc 398 Final Examination Wednesday 12 May 1999...

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