CS 139
Algorithm Development
Lab03B: Submitting Your Program through WebCAT
Background
The programming assignments that you get over the rest of the
semester will be submitted using a tool called WebCAT. WebCAT will
also be the means by which you will receive feedback and grades for
your programs.
Objectives
The students will:
- Be able to login to WebCAT
- Be able to submit programs and receive feedback through WebCAT
- Know how to write Java programs that:
- Read values from the keyboard (standard input).
- Use integer division and remainder
- Display results with appropriate labels
Key Terms
- Scanner
- class with methods that return tokens from an input stream
- return value
- The value a method sends back to the caller at the completion
of the method execution
- instantiate
- The process of creating a new instance of an class (i.e., an
object)
- integer division(/) and remainder(%)
- Binary operations that perform integer division (/ produces
the quotient, % produces the remainder)
- import statements
- Statements in a java program that make available classes from
the standard java packages
Materials Needed
- Enrollment in the class (for Blackboard and WebCAT)
- Textbook
References
This lab is adapted from the Scratch
Curriculum Guide v20110923, released under the Creative
Commons Attribution-ShareAlike license.
Part 1: Preparation
- Develop (on paper) an algorithm for solving the following
problem. Indicate the names of all required containers, and list
all required steps in the conversion.
(Note: You may have been assigned this task as homework prior to
the lab.)
Requirements: A user needs to convert a seconds counter into
hours:minutes:seconds format, representing the equivalent number
of whole hours and the residual minutes and seconds.
For example:
Input
|
Output
|
Seconds Counter
|
Hours
|
Minutes
|
Seconds
|
5000
|
1
|
23
|
20
|
3625
|
1
|
0
|
25
|
1000
|
0
|
16
|
40
|
Write the algorithm to make this conversion. Remember to
identify conversion factors as constants, and to identify the
required containers for input and output variables.
As you develop the algorithm, think about problem solving in
general. First, make sure that you know how to do this task on
paper. Then you can begin to think about how to describe the
process algorithmically.
Part 2: Implementation
- Create a new program, SecondsToHours.java,
using the following structure.
- Create the heading using the Javadocs format found in the
accompanying program template. Alter the comments and class
name appropriately.
- Add an import statement to make Scanner available to your program. (import java.util.Scanner;)
- Create the class declaration and the main method
declarations. Don't forget the braces to enclose the
associated code.
- Add all required constant and variable declarations at the
start of the main method. Look at your algorithm and declare
all of your containers. You should have constants to define
the number of seconds per hour and minute.
- Declare your Scanner variable with the other declarations.
You will need to instantiate a Scanner object passing it System.in. (see Gaddis, Section 2.13)
- Next, build a prompt for the input, then read the seconds
using your Scanner variable and
an appropriate next method.
Refer to your book for an appropriate method to use.
The input prompt should be "Enter the
number of seconds: ", exactly. Notice the space
directly following the colon. Use the print
method rather than a println method
so that the cursor remains on the same line as the prompt.
(Any deviation from this specification will cause your program
to be flagged as incorrect.)
- Calculate the equivalent hours, minutes, and seconds using
your algorithm.
- Finally, output the your result.
The program output must be very specific. Use the following
format, filling in the blanks with the appropriate input and
output values.
(blank line)
_____ seconds = __ hours, ___ minutes, and
___ seconds
(blank line)
For example:
1000 seconds = 0 hours, 16 minutes, and 40 seconds
Include spaces around each of the values. There should be
exactly one space between elements on the output line, and no
leading or trailing spaces. Be sure to include the right
number of blank lines in the output (use the newline
character, "\n"). Incorrect spacing or anything other than
three lines of output (each with one newline character at the
end) will cause the program to be flagged as incorrect.
Remember that System.out.println(...) generates one newline
character automatically.
- Test your program with several input values, and make
corrections if the output is not correct.
Part 3: Submitting Your Work Through WebCAT
- Create another Java source file, named
SecondsToHours_Test.java, containing the following code:
import
java.io.*;
import junit.framework.TestCase;
/**
* This is a minimal test class for SecondsToHours.
*
* @author R.Grove
* @version 1.0
*/
public class SecondsToHours_Test extends TestCase {
/**
* Executes the main method, but no actual test
is performed.
*/
public void testMain() {
SecondsToHours sth = new SecondsToHours();
System.setIn(new
ByteArrayInputStream("1\n".getBytes()));
ByteArrayOutputStream output = new
ByteArrayOutputStream();
System.setOut(new PrintStream(output));
sth.main(new String[] {});
}
}
Don't worry about the contents of
SecondsToHours_Test at this point. We'll cover testing later in
the class.
- Submit your program for grading by following these steps
- Open a console window, and navigate to your working
directory (where the Java files are).
- Create a new zip file containing the two Java files:
zip lab3b.zip
SecondsToHours.java SecondsToHours_Test.java
- Login to WebCat (webcat.cs.jmu.edu), if you aren't logged in
already. (Your password is the last four digits of your
student ID number.)
- Click the "Submit" button next to the assignment "Lab3b".
- Browse to the zip file that was created above, then click
"Upload Submission".
- Confirm that the correct files were uploaded (and click
"Confirm").
- Wait for the Submission Results report to appear.
- Interpreting the Submission Results report:
If the program is correct, you'll see a score summary at the top
of the page indicating 50/50 points for Correctness/Testing. The
Design/Readability Score will be added later by the instructor.
If the Code Coverage from Your Tests is not 100%, then you have
an error in your program. The output that it is generating is
not what was specified. You will need to check the
specifications again, and revise your program.
Correct Program
|
Incorrect Program
|


|

|