|
|
|
Pledged Lab Quiz
This lab quiz is pledged. You may use your textbook, the online
String or
Scanner references, and NOTHING ELSE. However, you should
still save your file into your home directory. This includes any files in your home
directory, previous assignments, slides, etc. Note that there is a
String class reference on page 877 of your textbook; Scanner reference on
page 870.
You will need to
submit a single file called LabQuiz1.java. No skeleton code is
being provided.
The TAs cannot help you with Java-related issues on this quiz. If
you are having problems getting JCreator to work, can't log in to the
machines, etc., then you are welcome to ask the TAs for assistance. If you
do not understand what the lab is asking, the TAs may be able to help you
(meaning if it's a problem with our explanation, then they can help you --
if you've been skipping the lectures so far and have no idea what any of
this means, you are on your own).
Advice
- 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)
- 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.
String Manipulation
The program you are to write will read in three values: two ints (we'll
call them i and j), and one String (we'll call it
s). You should use .next() to read in the String.
And each value should be prompted for and read in separately.
The program must do a number of String operations:
- The program will print the substring of s
from i to the character right before j. See
below for an example of this execution part.
- The program will print the first index of the
character 'a' in s
- The program will print the last index of 'a'
in s
- The program will print the upper case version
of String s
- The program will print the length of String s
- Lastly, the program will print if the String is a "long" String or a
"short" String. Any String of 10 or more characters is considered
"long"
Your program needs to be in a public class LabQuiz1, with
the file being named LabQuiz1.java.
You are welcome to look at the online
String or
Scanner references, as well as the String class reference on page 877 of
your textbook; Scanner reference on page 870.
Sample output
Note that your program should prompt for (and obtain) input on 3 separate
lines (what's shown below compacts the input into one line). And the
numbering below is to show what output corresponds to the steps listed
above; you don't have to print the numbers.
If the input is "2 5 asdfasdf", the program will print the following
values
- dfa
- 0
- 4
- ASDFASDF
- 8
- short
Other Requirements
You are REQUIRED to include most of the good programming practices
discussed in HW J1 (all but the test code). For your reference, they
are included below.
- Header: The comments at the very beginning of the file, and need to
include your name, e-mail ID, 101 section (or 101-E, if appropriate),
and a line or two about what this program does.
- Comments: A line or two before each major "block" (section of code,
class, method, variable, etc.) describing what it does.
- Whitespace: A line or two between separate elements of the code
(methods, code segments, etc.) and good indentation.
- Legend: The program should print out a line or two that states what
the purpose of the program is (i.e. "This is a BMI calculator", or "Are
you ready for an Ironman Triathlon? Let's find out!"). This should be
the first line(s) printed to the screen.
- Echoing input: All user input should be echoed back to the screen.
This can be a line saying "you entered 5" after the user enters each
input, but can also be a single line saying, "You entered: Swim:
0.5, Bike: 1.3, Run: 0.7".
- Variable names: All final variables should be in all caps with
underscores between the words, such as BOX_WIDTH. Non-final variable
names should have the firstLetterOfEachWordCaptilized in the variable
name (excepting the very first letter). Variable names should be
relevant and informative, such as mileage and not m.
- Line length: The lines should not go over about 72 characters.
Essentially, when displayed on an 80-character wide screen (what we are
using), the line should not go past the end of the screen. You can have a println() statement, for example, use multiple lines (as long as each
string starts and ends on the same line). JCreator tells you the column
that the cursor is currently in (at the bottom on the status bar), so you can use that to gauge how long your
lines are.
Submission
When you are finished,
submit your LabQuiz1.java file. You will have to "sign" a pledge
on the submission.
Lastly, you should be able to pick up your test at the end of your lab
quiz. If it's not ready, then you can pick it up next week in lab.
Either way, your score will be available on the website by the end of the
day tomorrow (you'll receive and e-mail about it).
|
|