Thursday, November 6, 2008

We did some basics review over the past couple of days in an attempt to solidify students' skills. Here's what we did:

Consider:



for(int i=0;i<=20;i++)
System.out.println(i);


and


for(int i=45;i>=-5; i-=5)
System.out.println(i);


Identify:
1. the loop control variable
2. the initialization code
3. exit condition
4. increment statement
5. executable satement(s)
6. what output will be produced?

We filled out the || and && and ! truth tables

Given:


do
PUT Prompt for usrNum
GET usrNum
//while usrNum is out of range
while(usrNum>10 || usrNum <1)>

-there is at least 1 other way to re-write this while condtion. What is it?

and there's also....

Given:
Loop control variable (i.e. counter): index
Executable stmt: finalValue: -= index;
increment statement: index++;
initialization statement: index = 1;

Write the for loop that implements these conditions.

Assume that finalValue has itself been intialized to a value of 7, what output would be produced by the following line of code assuming it came directly after the for loop exited.

System.out.println(“The final value is “ + finalValue);

Also


if (quantityPurchased >= 150 && price > 9.99)
discount = .05;
else if (quantityPurchased >= 1000 && price > 7.99)
discount = .1;
else if (quantityPurchased >= 10000 || price < discount =" .33;" discount =" 1;">


Answer the following questions:
1. What discount will be applied if I buy 175 items at a price of $8.00?
2. What discount will be applied if I buy 225 items at a price of $10.29?
3. What discount will be applied if I buy 50 items at $0.99?
4. What discount will be applied if I buy 1500 items at $11.99?
5. What discount will be applied if I buy 1500 items at $6.99?

I'll post the answers in the comments.

1 comment:

Mac said...

Alternate form of the while condition:

!(usrNum<10&&usrnum>1)

Answers to the discount questions:

1. 1
2. 0.5
3. .33
4. 0.5
5. 1