Colorado State University

Recitation R23 - Start P8 and Practice Quiz
Spring 2014

CS160: Foundations in Programming


PART A - Getting started on P8

See the P8 assignment on the Progress tab on the course website for instructions. Your TA will make sure you have P8 setup, and help will be available for questions related to P8.

PART B - Practice Quiz

This is a practice quiz that will not be graded except for attendance. However, we have setup automated grading to allow you to evaluate yourself by submitting to the Checkin tab on the course web site. The instructions for the programming quiz are shown below.

Create a project called Q5 in Eclipse, and a class called Q5. Note: You may refer to other projects that you have in your Eclipse workspace! Follow the steps shown below in order. All steps should be implemented in the main method, unless otherwise specified. Each step produces exactly one line of output.

IMPORTANT: Do the steps in order and make sure that each step A-I produces exactly one line of output!


List of Steps

You must first declare a scanner to read from the console, and a decimal formatter that limits the output to exactly 3 digits after the decimal point.
A) (10 points) Declare an integer called int0, use System.out.print() to print the the prompt "Enter an integer: ", read int0 from the console using the scanner.
B) (10 points) Declare a double called double0, use System.out.print() to print the the prompt "Enter a double: ", read double0 from the console using the scanner.
C) (10 points) Declare a String called string0, use System.out.print() to print the the prompt "Enter a string: ", read string0 from the console using the scanner. NOTE: You must read a single string without spaces for this step, not the entire line.
D) (10 points) Print an expression that typecasts int0 to a double, adds 123.0, then divides the result by 19.5. Use the decimal formatter created above to format the output. Do not change the value of int0 in this step.
E) (10 points) If the value of int0 is less then 14, print int0 multiplied by 2, else if the int0 is greater then 92, print int0 minus 3, otherwise print int0 squared.
F) (10 points) Print the string "Answer: " concatenated with the 3rd, 5th, 2nd, and 6th characters of string0 in that order with no spaces or punctuation in between. Note: No error handling is necessary if the user enter a string with fewer than 6 characters.
G) (10 points) Declare a character array called cArray of length 5 with the values 'c','$','8','!','G', then print the value of a call to Arrays.toString with cArray as a parameter.
H) (10 points) Implements a switch statement based on the string0 variable, as follows:
I) (20 points) Declare an integer array called iArray of length 4 with the values 123, 234, 345, and 456, and call the method computeSumOfArray with the array of type integer as a parameter and print the return value. For this step, you must them implement the static method computeSumOfArray, as follows:
  • Your program should have exactly 9 lines of output.
  • Make sure your Q5.java compiles and produces the correct output.
  • Submit your Q5.java to the Checkin tab to see your score.
  • You may leave after submitting the quiz.
    Submit your Q5.java program to the Checkin tab for grading, points on this lab are based only on attendance!

    © 2014 CS160 Colorado State University. All Rights Reserved.