Pledged lab quiz
- This quiz is timed - you have 90 minutes to complete it.
- The only "good programming practice" that is required for
this lab is to include your name and e-mail ID in the header
comments. You are welcome to include more, but make sure you
get the programs working first, as the quiz is timed.
- The quiz is open textbook. You may also use the
Java
documentation for the String class.
- The activities of this week are not to be
discussed outside of lab. You are to produce two programs. Templates for them are
available:
- CircleArea.java (right click on the
link, select "save as...", then save the file to your home directory)
- StringQuiz.java (right click on the
link, select "save as...", then save the file to your home directory)
Advice
- Remember neither the lab assistants nor other students may
help you design, write, or debug the programs. If you are
having a problem getting JCreator to work right (which does NOT
mean a compilation error), or an error with the submissions,
then you may ask a TA.
- To maximize your points, make sure your programs compile
successfully.
- If towards the end things are not going as well as you
would want (i.e., the program does not compile), it might be
best to try commenting out errant statements (i.e., put a
// in front of them)
- Focus on getting the first program to work properly before moving onto
the second. Both programs are worth equal credit, and the first one is
easier.
- If you run out of time, submit what you have -- there will be partial
credit for this quiz. Also remember that you can submit a file as many
times as you want -- only the most recent submission is graded. So
once you have it working, submit what you have.
The Quiz
- Complete and
submit program CircleArea.java (right click on the
link, select "save as...", then save the file to your home directory) that
prompts from the user for the radius of a circle (this should be read in as
a double, not as an int). The program will
then compute the area of the circle, and print it out. Recall that the
area of a circle is a = pi * r * r. To get the value of PI, you can
use Math.PI or 3.14159265358979. A sample execution run is as
follows (the text in red is what was entered by the user).
Enter the radius:
2
The area of the circle with radius 2.0 is 12.566370614359172
- Complete and
submit program StringQuiz.java (right
click on the link, select "save as...", then save the file to your home
directory) that prompts the
user for two strings: a long string, and a short string contained within the
long string. You can assume that the short string will always be found
within the long string, and there are letters both before and after it
within the long string (meaning that the short string is not at the very
beginning or end of the long string) You need to then compute three strings
from this: the
beginning part (the part of the long string found before the occurrence of
the short string), the middle part (the short string itself), and the end
part (the part of the long string found after the short string). These
three parts should then be printed in the following order: end, middle,
beginning. A sample execution run is as follows
(the text in red was entered by the user).
Enter a long string
abclmnxyz
Enter a short string contained within the long string
lmn
The re-arranged string is:
xyzlmnabc
A few notes: You should use nextLine() (instead of next())
to read in the strings. Also, the position where the end string starts
is the sum of the position of where the shortString is found plus the length
of the shortString.
Submission
Submit both files
here.