2.18.6 Pool Table

Question: 5.1.4: Square

Answer: function start(){

square(5);

}

function square(x){

var squareX = x * x;

println(squareX);

}

Question: 5.1.5: Triple

Answer: function start(){

triple(5);

}

function triple(x){

var tripleX = 3 * x;

println(tripleX);

}

Question: 5.2.4: Area of Triangle

Answer: function start(){

triangleArea(5, 4);

}

function triangleArea(BASE, HEIGHT){

var result = 1/2

HEIGHT;

println(result);

}

Question: 5.2.5: Height in Meters

Answer: var INCHESTOCM = 2.54;

var CMTOMETERS = 100;

var FEETTOINCHES = 12;

function start(){

convertHeightToMeters(6,4);

}

function convertHeightToMeters(x, y){

var inches = ((x * FEETTOINCHES) + y);

var cm = (inches * INCHESTOCM);

var meters = (cm / CMTOMETERS);

println(meters);

}

Question: 5.3.4: Horizontal Lines

Answer: function start(){

horizontalLine(100, 200);

horizontalLine(200, 100);

horizontalLine(300, 20);

}

function horizontalLine(y,length){

var line = new Line(0,y,length,y);

line.setLineWidth(1);

add(line);

}

Question: 5.3.5: Graphics Stop Light

Answer:

Question: 5.3.6: Pool Table

Answer:

Question: 5.4.4: Square with Return Values

Answer: function start(){

square(5);

}

function square(x){

var squareX = x * x;

return squareX;

}

Question: 5.4.5: Quadruple with Return Value

Answer: function start(){

quadruple(3);

}

function quadruple(x){

var quadrupleX = x * 4;

return quadrupleX;

}

Question: 5.5.4: Is It Even?

Answer: var SENTINEL = 0;

function start(){

while(true){

var input = readInt(“Number: “);

if(input == SENTINEL){

println(“DONE!”);

break;

}

if(isEven(input)){

println(“Even”);

}else{

println(“Odd”);

}

}

}

function isEven(x){

return(x % 2 == 0);

}

Donation Page

Support Our Work

Do you appreciate the value this website provides? If so, please consider donating to help keep it running. Your donation will go a long way in helping us continue to provide the same quality of content and services. Every bit helps, and your support is greatly appreciated. Thank you for your generosity.