CSE1020 Labtest 2A

Please read this part carefully

No collaboration is allowed during a labtest. Refrain from speaking with other students during the test. If you have a question, please ask the teaching assistants or the instructor.

In your home directory you will find a copy of your submitted work from Labs 03–06 in the directory unsubmit. You may use pens/pencils and blank sheets of paper. No other aids are allowed.

Your work will be evaluated based on its correctness and conformance to the style rules. Your code must compile to receive a passing grade.

Remember to save your work and submit your work at regular intervals during the test.

APIs

Test Problem 1 of 2

Cut-and-paste the following program into your editor:

import java.io.PrintStream;

public class Test2A
{
   public static void main(String[] args)
   {
      PrintStream out = System.out;
      
      final int START = Integer.parseInt(args[0]);
      final int STOP = Integer.parseInt(args[1]);
      
   }
}


START and STOP are both integer amounts of time in seconds. You may assume that START and STOP are both zero or greater, and that START is larger than STOP.

Complete the program so that it counts down the time from START to STOP in increments of 1 second, and outputs each increment on a separate line.

For a maximum of 6 out of 10 marks: The output is simply each time increment in seconds; for example, counting down from 5 seconds to 0 seconds (you type in the text in red to run your program, your program outputs the text in black):

java Test2A 5 0
5
4
3
2
1
0


For a maximum of 10 out of 10 marks: The output is formatted like a digital clock showing minutes followed by a colon followed by 2 digits for the seconds. for example, counting down from 5 seconds to 0 seconds:

java Test2A 5 0
0:05
0:04
0:03
0:02
0:01
0.00


and counting down from 602 seconds to 598 seconds

java Test2A 602 598
10:02
10:01
10:00
9:59
9:58
 

Submit

Submit your program using the command:

submit 1020 test02 Test2A.java

 

Test Problem 2 of 2

Cut-and-paste the following program into your editor:

import java.io.PrintStream;

public class Test2B
{
   public static void main(String[] args)
   {
      PrintStream out = System.out;
      
      final String WORD = args[0];
      
   }
}


English words like beefily, billowy, and mossy are unusual in that they are made up of letters that are in alphabetical order (when read from left to right). For example, looking at the letters in mossy:

For a maximum of 15 out of 20 marks: Complete the program so that it prints true if WORD is made up of characters all in alphabetic order, and false otherwise. Some examples:

java Test2B beefily
true

java Test2B almost
true

java Test2B xylophone
false

java Test2B spoonfeed
false


For a maximum of 20 out of 20 marks: Complete the program so that it prints true if WORD is made up of characters all in alphabetic order, and false otherwise. Also, your program must compute and output the length of the longest consecutive sequence of letters in WORD that are in alphabetical order. Some examples:

java Test2B beefily
true
longest sequence of letters in alphabetical order: 7

java Test2B almost
true
longest sequence of letters in alphabetical order: 6

java Test2B xylophone
false
longest sequence of letters in alphabetical order: 3

java Test2B wonk
false
longest sequence of letters in alphabetical order: 1
 

Here is an explanation of the outputs for the four test cases above (your program should not generate the explanation):

longest alphabetic sequence in beefily is b-e-e-f-i-l-y
longest alphabetic sequence in almost is a-l-m-o-s-t
longest alphabetic sequence in xylophone is l-o-p
longest alphabetic sequence in wonk is 'w' (or 'o', or 'n', or 'k')
 

Submit

Submit your program using the command:

submit 1020 test02 Test2B.java