Lect 3.2 Scheme_examples - public class Imperativecfw just...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
public class Imperative { // just a program name static int area = 0 ; // global height=4 static int result = 0 ; public static void calAreaProc(int length, int width) { area = length * width ; length =3 width=2 } public static void sumProc(int val1, int val2) { result = val1 + val2 ; } public static void displayResultProc(String str) { System.out.println(str + result) ; } public static void main(String[] args) { calAreaProc(2,3) ; sumProc(result, area * 2) ; // side effect calAreaProc(4,3) ; sumProc(result area * 2) ; sumProc(result, area 2) ; calAreaProc(4,2) ; sumProc(result, area * 2) ; displayResultProc("The total surface area of cubiod is "); } } 57
Image of page 1

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

View Full Document Right Arrow Icon
public class Cubiod { int length, width, height = 0 ; height=4 public Cubiod (int length, int width, int height) { this.length = length ; this.width = width ; length =3 width=2 this.height = height ; } public int getArea (int l, int b) { return l * b ; } public int getTotalSurfaceArea(){ return 2 * (getArea(length ,width) + getArea(length ,height) + getArea(height ,width)); } public void displaySurfaceArea(){ System.out.println("The surface area of the cubiod with length " + length +
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.