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

Info icon This 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)
Image of page 1

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern