






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Professor: Tanner; Class: Introduction-Computer Science; Subject: Computer Science; University: West Virginia University; Term: Unknown 2009;
Typology: Study notes
1 / 10
This page cannot be seen from the preview
Don't miss anything!







x = -5 power = 1024 maxPower=1024 y=7 item =1.
minItem = -999.9 momOrDad = ‘m’ num=999 sentinel =
x <=
power > maxPow
item > minItem
x >= y
momOrDad == ‘M’
num != sentinel
salary < minSalary || numDependants > 5
dewPoint > 68 && humidity > 82 score >=80 && score <
winningRecord && !onProbation
! –
< > <= >= == != && || =
x+a < y+b Î (x+a) < (y+b)
min<= x && y <=max Î (min <=x) && ( y <= max)
flag || leapYear && switch Î flag || (leapYear && switch)
x= 3.0 y = 4.0 z = 2.0 flag = false
!flag
x+y/7 <+ 3.
(!flag) || (y+z) >= (x-z)
String s; s = new String (“CS 110”);
Memory address Variable Data 100 s 116 104 q 112 108 112 CS 101 116 CS 110
String S= “CS”; String T = “CpE”; String Q = “Dual”;
String Z = “CS”; String R = new String (Z); String X = R;
CpE Dual
String s1 = new String (“Happy”); String s2 = “Happy”;
s s
Consider String s2 =”Happy”; String s1 = new “Happy”;
s s
Happy
Happy Happy
Evaluate the condition Æ if true execute 1st^ block, if false execute the else block
if (hours <=40) pay = ratePerHour * hours; else pay = ratePerHour * 40 + ratePerHour 1.5(hours -40);
Write a method that returns the larger of two values passed as parameters
public static int max (int x, int y) { int maxValue;
if (x>y) maxValue = x; else maxValue =y;
return maxValue; }
Sample Programs: Piglatin2.java, Roulette.java, Pyth3.java, Division.java, Ckbook.java
Homework set 4: Write the JAVA statements to accomplish the following
a). If item is non-zero, multiply product by item and save the result in product ; otherwise, skip the multiplication. Either way, display the value of product.
b). Store the absolute difference of x and y in y , where the absolute difference is (x-y) or (y-x) whichever is positive.
c). If x is 0, add 1 to zeroCount. If x is negative add x to minusSum. If x is greater than 0 add x to plusSum.
d). Write a method sameSign() that, given two double parameters return true if they are of the same sign and false if they have difference signs.
e). Rewrite sameSign() which returns the actual sign ‘+’ or ‘-‘ if they are the same sign and a blank if they are different signs.
Membership dues set on a sliding salary scale if (salary <=10000) dues= .05 * salary; else if (salary <= 30000) dues = .08 * salary; else if ( salary <= 50000) dues = .1 * salary; else if (salary <= 70000) dues = .15 * salary; else dues = .2 * salary
o Comparison of using separate if’s o 0 + - if (x ==0) stmt if (x<0) stmt if(x>0) stmt
each is tested when if one is true the others are not true and should not be tested – else construct does not retest o Membership dues if (salary < 10000) dues = if (salary >=10000 && salary < 30000) dues = if (salary >=30000 & salary < 500000) dues = if (salary >=50000 & salary <700000) dues = if (salary >=70000) dues
switch (n) { case 1: case 2:System.out.print (“Buckle my Shoe”); break; case 3: case4: System.out.print(“Shut the Door”); break; case 5: case 6: System.out.print (“Pick up Sticks”); break; case 7: case 8: System.out.print (“Shut the Gate”); break; case 9: case 10: System.out.print (“Start Again”); break; default: System.out print(“Invalid value”); }