0% found this document useful (0 votes)
11 views3 pages

(2330300)Simple Stopwatch using JAVA

The document outlines a project by Debayan Roy to develop a Java-based digital stopwatch application. The application allows users to start, stop, and reset a timer while accurately tracking elapsed time through a command-line interface. It demonstrates the use of Java's time functions and object-oriented programming concepts, with potential for future enhancements like a GUI.

Uploaded by

2330293
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

(2330300)Simple Stopwatch using JAVA

The document outlines a project by Debayan Roy to develop a Java-based digital stopwatch application. The application allows users to start, stop, and reset a timer while accurately tracking elapsed time through a command-line interface. It demonstrates the use of Java's time functions and object-oriented programming concepts, with potential for future enhancements like a GUI.

Uploaded by

2330293
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

OPEN ENDED EXPERIMENT USING JAVA

Name of student Debayan Roy


Roll No. 2330300
Group 2
Branch ECSc

Title of the Project:


Java-Based Digital Stopwatch Application.

Aim:
To develop a simple stopwatch application using Java that allows users to start, stop,
and reset the timer while displaying elapsed time in seconds.

Objective:
1. Implement a user-friendly stopwatch using Java's built-in
System.currentTimeMillis() function.
2. Utilize object-oriented programming concepts such as encapsulation and methods
to manage the stopwatch's functionality.
3. Provide an interactive command-line interface for users to control the stopwatch
(start, stop, reset, and exit).
4. Ensure accurate time tracking and efficient handling of elapsed time even when
paused and resumed.
5. Improve the understanding of Java concepts like loops, conditionals, and user
input handling.

Programming Language Used:


JAVA

Code:
import java.util.Scanner;

public class Stopwatch {


private long startTime;
private long elapsedTime;
private boolean running;

public void start() {


if (!running) {
running = true;
startTime = System.currentTimeMillis() - elapsedTime;
System.out.println("Stopwatch started!");
}
}

public void stop() {


if (running) {
elapsedTime = System.currentTimeMillis() - startTime;
running = false;
System.out.println("Stopped at: " + getTime() + " seconds");
}
}

public void reset() {


running = false;
elapsedTime = 0;
System.out.println("Stopwatch reset!");
}

public double getTime() {


return running ? (System.currentTimeMillis() - startTime) / 1000.0 :
elapsedTime / 1000.0;
}

public static void main(String[] args) {


Stopwatch stopwatch = new Stopwatch();
Scanner scanner = new Scanner(System.in);

while (true) {
System.out.print("\nCommands: (S)tart | (T)op | (R)eset | (E)xit : ");
String command = scanner.next().toLowerCase();

switch (command) {
case "s" -> stopwatch.start();
case "t" -> stopwatch.stop();
case "r" -> stopwatch.reset();
case "e" -> {
System.out.println("Exiting...");
scanner.close();
return;
}
default -> System.out.println("Invalid command!");
}
}
}
}
Output:

Conclusion:
The Java-based stopwatch successfully fulfills its purpose by allowing users to track
elapsed time through a simple command-line interface. The implementation
effectively demonstrates the use of Java’s time functions and object-oriented
programming principles. This project serves as a foundational step for further
enhancements, such as integrating a graphical user interface (GUI) or adding features
like lap timing.

You might also like