Last Update: Nov. 15, 2025

Assignment 6 (PS6): Text Processing, Calendar

This assignment focuses on text processing, file input, and file processing. It will use methods in the StdDraw class.

Due: 11:55 PM, Sunday, November 23, 2025

IMPORTANT: The best advice we can give you about PS6 is to carefully test, debug, and re-test your code as you write it. Do not attempt to write a whole program at once—if you do, then you may have no idea where to find the error if the program doesn't work. Proactive testing will save you enormous amounts of time in the long run. Trust us!

Part 0: Strings Processing (Offline Learning)

Watch this video on how to process strings. StdDraw. (pptx, pdf)
Read this document on how to use String.split() method.
Read this document and this document to learn how to basically use string arrays.

Part 1: TaskMan (Conditional, Text Processing, Text File Input)

It is said that the XMU College experience is to keep yourself busy, really busy, with many tasks. The objective of Part 2 is to help you, by writing a program that displays the remaining time to each future task, and the elapsed time from each past-due task.

Part 1.1: Input

As we are talking about many tasks, we should put them in a file. We ask that you name the file tasks.txt. The first line of the file indicates the number of tasks and each remaining line provides information about a task. For simplicity, we ask for only two pieces of information for each task: task name and the due time. These two pieces will be separated by a vertical bar (|). As an example, we provide tasks.txt that lists some lecture related tasks. Note that the due time format is first month, followed by day, followed by year, followed by hour, followed by minute. We could design a format that is easy for your program to parse, but we chose one that is more natural, as in natural language:
4
PS5 | 11/16/2025 11:55:00 PM
Exam 1 | 1/1/2025 11:35:00 AM
PS6 | 11/23/2025 11:55:00 PM
Winter | 1/11/2025 8:00:00 AM

Part 1.2: Program behaviors

The basic behavior of your program is simple: it reads tasks.txt and displays a timer for each task. The timers are updated every second. We add some details to the behavior:
  1. To avoid displaying long task names, you will display at most 6 letters for task name.
  2. Your program will validate if the due time of a task is valid: year should be positive (we are talking about tasks for XMU students), month should be between 1 to 12, day should be between 1 and the number of days in the month, hour should be between 1 to 12, minute between 0 to 59, and second between 0 and 59. For example, 2/30/2025 11:61:00 PM is invalid because the day is invalid; neither is 61 a valid value for minute. If a time is invalid, your program will print out the error line and exit.
  3. If a task is in the future, the timer displays the remaining time, and the color should be green.
  4. If a task deadline is in the past, the timer displays the overdue time, and the color should be red.
  5. The timer should include the number of days, two digits representing number of hours, two digits representing number of seconds, and two digits representing number of seconds. An example display is shown below. Your timer display (e.g., 67d 03h 33m 42s) must conform to the format. But other layouts are free form and you are welcome (encouraged) to design a more elegant graphics.

image

Part 1.3: Implementation suggestions

To save you some time, we provide a relatively already complete code skeleton:

Starter code: TaskMan.java. You are more than welcome to change it in any way you want. We discuss a few key points:

One issue you need to resolve is to parse each line representing a task into two pieces: task name and task deadline string. You can use the substring/indexOf method, or split. An example of using split is:

String string = "123-456789";
String[] parts = string.split("-");
String part1 = parts[0]; // 123
String part2 = parts[1]; // 456789
If you see extra space at the end of a string, you can use the trim() method of String.

We use Integer.parseInt() to convert a string to a number.

The sample code uses the GregorianCalendar class to convert time with multiple components to a much simpler representation commonly used in Computer Science called the Epoch time, i.e., time starting from the beginning of 1970. To use GregorianCalendar, the sample code has:

import java.util.GregorianCalendar;

Below is a code segment to represent the example PS6 time:

GregorianCalendar event = new GregorianCalendar(2016, 2, 6, 23, 55, 0);
// convert to milliseconds from EPOCH
long eventTimeMS = event.getTimeInMillis();

Note that since GregorianCalendar counts month from 0, one uses 0 for January, 1 for February, etc.

The sample code uses an infinite loop:

for ( ; ; ) 
{
    // get current time from EPOCH in millisecond
    long currentTimeMS = System.currentTimeMillis();

    // compute difference between currentTimeMS and eventTimeMS
    // and compute the display

    // sleep 1 second and then clear
}

Some Suggestions. Remember the top-down design and bottom-up implementation strategy we covered in class? You might want to make it a milestone to extract task time and test it with multiple inputs until it works before you move to the next step.

You may make a next milestone to implement and test if time is valid, which will involve defining other methods such as determining the number of days in a month.

Another suggested milestone will be converting from second to the day/hour/min/sec representation.

Part 3: Submit Your Assignment

Please submit electronically for assignment #6 and make sure you submit (1) TaskMan.java. Please be sure that you choose the .java file, NOT the .class file when uploading. The .class file is the compiled version of your code which we cannot examine and grade. So, please make sure you submit *.java files. Also, remember that you always need to include the header.

  //*******************************************************************
  //
  //   File: FileName.java          Assignment No.: 6
  //
  //   Author: <your name>      Email: <your email>
  //
  //   Class: ClassName
  // 
  //   Time spent on this problem: 
  //   --------------------
  //      Please give a description about your design. 
  //
  //*******************************************************************

The submission repository for ps6 is https://gitee.com/simmonsong/ct-xmuf25-ps6.

Please follow the instructions in Assignments Submission to submit your assignments.

Git introduction is a help document for git utilization..

Enjoy!


Some part of the problem set derived from Building Java Programs.