CS 149
Algorithm Development
Lab04A: 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 CANVAS and WebCAT)
- Textbook
- Algorithm and examples developed from class on Friday.
Part 1: Preparation
- Review your algorithms 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. 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. Save this file as SecondsToHours.java. Alter the comments and class
name appropriately.
- Add an import statement to make Scanner available to your program. (import java.util.Scanner;) Review Thursday's lab for an example of using the 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 (See below), 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
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 blank lines in the output (either using a "\n" character or System.out.println(). Incorrect spacing or anything other than
two 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
- SEE DEMO BEFORE STARTING THIS STEP