This problem is designed to make sure you can build a program that has multiple
ID: 3842653 • Letter: T
Question
This problem is designed to make sure you can build a program that has multiple files. This is important, since as we progress in the course we will be reusing code and need to separate out the reused pieces from the new / changed pieces.
To do this problem, you will need to copy the following files into your project:
PingPongTest.c – the test file, containing calls to supporting functions
PingPong.c – the functions called by the test file
PingPong.h – the declarations of the functions contained in
PingPong.c that are callable by the test file
The Solution / Test Requirements
Build the program after copying the files and placing them in your project. You should not be modifying any of the files.
Notice how they are documented. They have been documented in the manner I expect you to document future homework submissions, including the program description, function declarations and function definitions.
Run your program and submit the program output. Since you will not have modified any files, you need only submit the program output.
Explanation / Answer
import java.io.*; import java.util.*; public class PingPong extends java.lang.Thread { private String word; // word to print private int delay; // constructor: public PingPong (String whatToSay, int delayTime) { word = whatToSay; delay = delayTime; } public void run() { try { while(true) { System.out.print(word + " "); Thread.sleep(delay); // class method } } catch (java.lang.InterruptedException ex) {return;} } public static void main (String args[]) { PingPong ping = new PingPong("ping", 300); PingPong pong = new PingPong("PONG", 1000); ping.start(); pong.start(); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.