Section3Key 1 - CSEI-43 Section A fixed version of Number,...

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

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

Unformatted text preview: CSEI-43 Section A fixed version of Number, comprete #3 Solutions with appropriate comments number operations / / R class capable of performing some basic public class Number { private int myValue; private boolean isprime; private boolean isprimelsValid; public static final int DEFAULT_VALUE = 0; default value (O) / / constructs a Number of public Number O { this ( DEFAULT_VALUE) ; ) / / constructs a Number with public Number (int value) { setValue (vaLue); ) the given value / / sets the value of this Number to public void setValue (int value) { myValue = valuel = falsei i-sPrimeIsVaIid the given value / / returns public int return ) the value of this getValue O { myValue; Number // returns true if the current value is pri-me, false otherwise. the resurt / / stores of the previous callr so subsequent carls / / with the same val-ue are ef f ici-ent public boolean isPrime ( ) t (!isPrimeIsVa1id) if { isPrime : calculatelsPrime O; = true; isPrimelsValid ) return isPrime; ) true if the current / / returns varue is prime, private boolean calculatelsprime O{ (int for L : 2; i < myVal-ue; i++; { (myValue t i := 0) { if return false; ) ) return myValue ) the current / / returns value public String toString Ot r rt t + m yvalue; return ) as a String fal-se otherwise ...
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