Tuesday, October 4, 2011

Java Programming Helper


ASSIGNMENT

Simple-1

1.  Given an integer variable drivingAge that has already been declared, write a statement that assigns the value 17 to drivingAge.
Example:  So, after your code is executed, the variable drivingAge, will have the value 17

drivingAge = 17 ;

2.  Given two integer variables oldRecord and newRecord, write a statement that gives newRecord the same value that oldRecord has.

newRecord = oldRecord ;

3.  Given two integer variables matricAge and gradAge, write a statement that gives gradAge a value that is 4 more than the value of matricAge.

gradAge = matricAge + 4 ;

Compound-1

1.  Given an integer variable bridgePlayers, write a statement that increases the value of that variable by 4.
Example:  So, if the value of bridgePlayers is 20 before your code is executed, then the value of bridgePlayers will be 24 after your code is executed.
On the other hand, if the value of bridgePlayers is 56 before your code is executed, then the value of bridgePlayers will be 60 after your code is executed.

bridgePlayers += 4 ;

2.  Given an integer variable profits, write a statement that increases the value of that variable by a factor of 10.

profits *= 10 ;

3.  Given an integer variable strawsOnCamel, write a statement that uses the auto-increment operator to increase the value of that variable by 1.

++strawsOnCamel ;

4.  Given an integer variable timer, write a statement that uses the auto-decrement operator to decrease the value of that variable by 1.

--timer ;

Input
Keyboard_Input

1.  Given an int variable datum that has already been declared, write a few statements that read an integer value from standard input into this variable.

Scanner input = new Scanner(System.in) ;
datum = input.nextInt() ;

File_Input

Relational_Operators

1.  Write an expression that evaluates to true if and only if the value of the integer variable x is equal to zero.
So if the value of x were 3 the expression would be false.  Only if the value of x were 0 would the expression be true.

x == 0

2.  Write an expression that evaluates to true if and only if the variables profits and losses are exactly equal.

profits == losses

3.  Given the char variable c, write an expression that is true if and only if the value of  c is not the space character.

c !=' '

4.  Write an expression that evaluates to true if the value of index is greater than the value of lastIndex.

index > lastIndex

5.  Working overtime is defined as having worked more than 40 hours during the week.  Given the variable hoursWorked, write an expression that evaluates to true if the employee worked overtime.

hoursWorked > 40

6.  Write an expression that evaluates to true if the value  x is greater than or equal to y.

x >= y

7.  Given the variables numberOfMen and numberOfWomen, write an expression that evaluates to true if the number of men is greater than or equal to the number of women.

numberOfMen >= numberOfWomen

8.  Given a double variable called  average, write an expression that is true if and only if the variable's value is less than 60.0.

average < 60.0

9.  Given an int variable grossPay, write an expression that evaluates to true if and only if the value of grossPay is less than 10,000.

grossPay < 10000


No comments:

Post a Comment

Post a Comment