Unformatted Attachment Preview
•
First of all this is a java class 236, so it’s a basic one. Second, no need for short
cut, or professional technic. Keep it as simple as you can please. For the first
single line question, they are just one line answer. The 7 short answers no
need for the whole program. The whole program is the last one. Thank you.
•
•
•
15 single-line coding statements.
7 short coding blocks.
1 complete program.
One line coding problems:
21- write a statement that calls the method fvCalulator() and passes it the variables
iVal1 and iVal2.
22- write a statement that invokes a method and passes two arguments, dLength
and dWidth. Assume the return calculate and return the area to the calling method.
Use an appropriate name that follows class standards.
23- write a single line of code to declare a global variable for an integer value of 100
that stores the maximum allowable upper boundary for random number generation.
Follow class-naming standards in the notes.
24- write a single line of code that will extract the first character in sName and
store it to cChar.
25- write a single line of code that will determine the of string sAddress and store
it to the variable iLen.
26-write a method header for a method that receives one integer value and, in the
method, increases the value by5%, and returns the new value to the calling method.
27- write a statement to extract an integer from a file to the input-capture variable
iVal using the scanner ifsInput.
28-A method sums the values in a text file, which contains data of type double. The
value is stored in dSum. The number of items in the file is stored in iCount. Write a
statement a statement that calculate the mean and stores it to dMean.
29- write a statement to increase an employee’s hourly rate, stored in the variable
dRate[iSub], by 5%. Store the new value to the same array element.
30- assign the value 57 to the first ordinal position or the array iVals with an
individual assignment stamen.
31-write a declaration for an array that can store 24 hourly temperatures, in degree
Fahrenheit.
32- write a statement that will store the value of 98.6 to the last element in the array
you declared above.
33- write a statement that will sum the second and third values in the array you
declared above to the variable dSum.
34- write a statement that can be used to temporarily store the value of a given
temperature in the array you declared above. Assume this is the first step of an
interchange for an ascending bubble sorting operation. The array is traversed using
for loop in which the loop’s counter variable is iSub.
35-An array was declared to store five int variables. Write a for statement that will
take the array out of bounds if exc.
Short coding blocks:
36- write the complete method fvDrawTriangle() that display a figure consisting of
asterisks as designated by a parameter. Only this one parameter will be received by
the method. Here is an example of how the display would look if value passed as an
argument was 4:
****
***
**
*
37-write a while loop that uses a priming read to ask a user the question, “work? Y
or N: “ Accept either uppercase or lowercase Y and N as valid data. For Yy or Nn
terminates the captive loop; for any other value display “invalid” and keep running
the loop until valid input is entered. Assume the variable sIn has already been
declared, and the Scanner class has been instantiated.
38- write a complete void() method that receives a fully qualified filename and
prints each line in the file on the console. Catch FileNotFoundException and simply
display “MIA” if it happens.
39- completes this method, which someone else started writing, by adding a trycatch block and any additional code needed. Some variables are declared; you may
need others to complete your declarations/ instantiations:
public static int fiWriteEvens(int piVals[])
{
int iSub; //loop counter variable
int iCount; //count of even numbers encountered in the array
int iReturn; //value to return to the calling method
iCount=0; //initialize even value counter
...
}
The method’s code will examine the array, received as a parameter, and the output
the even values to an output file, out . text, located in the subfolder home of the H:
drive. The output values should be written on value per line in the output file.
Return one of the following: the number of even integers written to the file OR if the
file cannot be found, display “problem” and return a negative number, e.g. -1 to the
calling method.
40-write a complete value-returning method that will populate the array iVals
declared in main() with integers that fall within a designated range, inclusive,
governed by parameters. Receive the name of the array, the minimum integer value,
and the maximum integer value to the method in your method header. Return the
sum of the integers in the array.
41-write a block of code that will shift an array iVals to the right one position. There
is no display needed; just perform the shift.
42- a teacher wants to find the best and worst test scores based on an array of 25
values in the array iScores. Sort the array in ascending order and then display the
worst and best scores. Do not use a search high/low algorithm; sort it. Example
output provided to guide your coding.
Worst: 12
Best: 97
1 complete program:
43-you will need to write a main() method, plus three additional methods.
There is a forth method needed, which is not to be coded. You will simply call
the method and the “black box” will do the rest.
- Note: for the methods called from main(), base your traversal of the array
on array’s length ; do not hard-code the methods in the solution based on the
array size.
- Also, assume all the elements of the array will populated by the methods
fvPopArray(). This is different(and simpler)than the previous quiz because
the quiz was based on a data file which could have anywhere from 0 to 1,000
elements in it. This exam problem isn’t like that. So don’t overcomplicate it.
Specifications follow:
-
-
in the main() method, declare an array of 100 value of type double.
Call the method fvPopArray() which will , as if by magic, populate the
array with random value; you don’t write this – assume it is written and
will be available to be called. Pass the methods only the array.
Call the method fdCalcMean() to calculate the mean. Pass the method
only the array. Return the mean to main() and display it, as shown in the
sample below, to two decimal places.
Call the method fdCalcVarance() to calculate the variance. Pass the array
and the mean; return the variance to main() and display it, as shown in
the sample below, to two decimal places.
Call the method fdCalcStdDev() to calculate the standard deviation. Pass
variance; return and display it, as shown in the sample below, to two
decimal places.
Output sample:
Mean: 24.00
Variance: 80.00
Standard Deviation: 8.94
-
The formula to calculate standard deviation, s (the square root of the
variance), is: