# Purpose

Λογισμικό & κατασκευή λογ/κού

15 Αυγ 2012 (πριν από 5 χρόνια και 11 μήνες)

219 εμφανίσεις

CSC150 SI Session 13

March 23, 2010

Purpose

The purpose of this lab is to get experience reading and writing decisions. You should be able to read
the given code without the help of Netbeans. You may use Netbeans to help write any code, but you
should be

able to write code without the assistance of Netbeans if asked.

Code Walkthrough

For this section, execute the given program and show the output of the program.

public class Main {

public static void main(String args[]){

int a = 5;

dou
ble b = (1.0/3.0);

int d = 1;

functionOne();

functionOne(a,b,d,closest(a,b,d));

functionTwo();

System.out.println("");

double c = b * 2;

double e = (1.0
-

b);

if(equal(c,e)) System.out.pri
ntln(c + " and " + e + " are equal");

else System.out.println(c + " and " + e + " are not equal");

if(equal(c,e,.000000001)) System.out.println(c + " and " + e + " are within .000000001 of each other");

else System.out.println(c +
" and " + e + " are not within .000000001 of each other");

if(equal((1 / 2),0)) System.out.println((1 / 2) + "(1 / 2) and 0 are equal");

else System.out.println((1 / 2) + "(1 / 2) and 0 are not equal");

System.out.println("");

functionTwo(1);

functionTwo(6);

functionTwo(0);

functionTwo(
-
5);

functionTwo(2);

functionTwo(9);

functionTwo(4);

functionTwo(10);

}

public static void functionOne(){

System.out.
println("functionOne called!");

}

public static void functionOne(double a, double b, double c, double closest){

System.out.println("The smallest difference between " + a + "," + b + ", and " + c + " is " + closest);

}

public stati
c void functionTwo(){

System.out.println("functionTwo called!");

}

public static void functionTwo(int compare){

switch(compare){

case 0:

System.out.println("Case 0");

break;

c
ase 2:

System.out.println("Case 2");

case 1:

System.out.println("Case 1");

break;

case 5:

case 6:

case 9:

System.out.println("Big Case");

break;

case 10:

System.out.println("Case 10");

break;

default:

System.out.println("Default Case");

break;

}

}

public static double closest(do
uble a, double b, double c){

double diffOne = Math.abs(a
-
b);

double diffTwo = Math.abs(a
-
c);

double diffThree = Math.abs(b
-
c);

if(diffOne <= diffTwo){

if(diffOne <= diffThree) return diffOne;

else re
turn diffThree;

}else{

if(diffTwo <= diffThree) return diffTwo;

else return diffThree;

}

}

public static boolean equal(int a, int b){

if(a == b) return true;

else return false;

}

p
ublic static boolean equal(double a, double b){

if(a == b) return true;

else return false;

}

public static boolean equal(double a, double b, double threshold){

if(Math.abs(a
-

b) <= threshold) return true;

else retu
rn false;

}

}

Code Writing

For
this

section write the code to satisfy the given problem. You can assume each problem will be an
individual
method

that will accept any needed values as a parameter. You should also return values

1.

Given a double value for grade, using a switch statement determine the character value for the
letter grade. You should account for values greater than 100 and less than 0.

2.

Write a
method

that reads in a value from the keyboard. If the v
alue is not an integer value,
then return
-
999. You should create a Scanner object within the function to handle user input.

3.

Given a double value for grade
, using
if statements determine a string representation for a letter
er grades is below in interval notation. I will provide one answers

A+ : [96.5,infinity)

A : [93.5,96.5)

A
-

: [89.5,93.5)

B+ : [86.5,89.5)

B : [83.5,86.5)

B
-

: [79.5,83
.5)

C+ : [76.5,79.5)

C : [73.5,76.5)

C
-

: [69.5,73.5)

D+ : [66.5,69.5)

D : [63.5,66.5)

D
-

: [59.5,63.5)

F : (
-
infinity,59.5)