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:

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

References

This lab is adapted from the Scratch Curriculum Guide v20110923, released under the Creative Commons Attribution-ShareAlike license.

 


Part 1: Preparation


Part 2: Implementation
    1. Create the heading using the Javadocs format found in the accompanying program template. Alter the comments and class name appropriately.
    2. Add an import statement to make Scanner available to your program. (import java.util.Scanner;)
    3. Create the class declaration and the main method declarations. Don't forget the braces to enclose the associated code.
    4. 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.
    5. 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)
    6. 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.)

    7. Calculate the equivalent hours, minutes, and seconds using your algorithm.
    8. 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.

Part 3: Submitting Your Work Through WebCAT

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.