Section3Problems 1

# Section3Problems 1 - CSE143 Section Now, examine the code...

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE143 Section Now, examine the code that implements #3 Problems Number: (handout #2) public class Number { private int myValue; private booLean isPrime; private boolean isPrimefsValid; public statj-c int DEFAULT_VALUE : 0, a Number // constructs public Number O { this ( DEFAULT_VALUE) t ) a Number // constructs public Number(int value) setValue (value); I { / / sets the vaLue public void setValue (int int myValue : val-ue; ) / / gets the value public getValue int return myValue; ) value) { O { method should return whether / / this the / / is prime or not pubJ.ic boolean isPrime O { (!isPrimeIsValid) if { : calculatelsPrime isPrime O; : truei isPrimelsValid ) return isPrime; ) / / uses / / some private for Number a super efficient trick to caLculate primes really really fast boolean calculatelsPrime O{ (int i : 2, i < myValue; i++) { (myValue t i :: if 0) { return false; ) truei ) return ) a string // returns public String toString O t rr r + m y V a l u e ; return ) l { Would you change any of your test cases? you know how Number is implemented? that Can you find al-l the bugs in Number? What new test cases would you add now (hint: Number? there Which are four) would you change? What What do you think would you change of the conunents in them to? ones ...
View Full Document

## This note was uploaded on 11/03/2009 for the course CSE 143 taught by Professor Sr during the Spring '08 term at University of Washington.

Ask a homework question - tutors are online