New tested Stopwatch :D

This commit is contained in:
LinlyBoi
2022-03-11 21:36:49 +02:00
parent 8ef95916e1
commit c22ad78dc8
6 changed files with 95 additions and 1 deletions

View File

@@ -23,4 +23,5 @@ public class Employees
{
return yearsWithCompany;
}
//Emploice mus wash hans
}

View File

@@ -2,6 +2,7 @@ package IceCreamMachineStuff;
public class IceCreamMachine
{
double Cream;
double Sugar;
double Icecream;

View File

@@ -1,11 +1,12 @@
package Phonebook;
import java.util.LinkedList;
import java.util.Stack;
public class Phonebook
{
public Stack<PhoneNumber> Numbers = new Stack<PhoneNumber>();
public LinkedList<PhoneNumber> Numbers = new LinkedList<>();
public boolean insert(String phoneNum, String name)
{
@@ -26,6 +27,7 @@ public class Phonebook
}
PhoneNumber toInsert = new PhoneNumber(phoneNum, name);
Numbers.push(toInsert);
return true;
}

View File

@@ -0,0 +1,36 @@
package Stopwatch;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
public class StopWatch
{
private LocalTime startTime,endTime;
StopWatch()
{
startTime=LocalTime.of(0,0,0);
endTime= LocalTime.of(0,0,0);
}
public LocalTime getStartTime()
{
return startTime;
}
public LocalTime getEndTime()
{
return endTime;
}
public LocalTime start()
{
return startTime=LocalTime.now();
}
public LocalTime stop()
{
return endTime=LocalTime.now();
}
public Long getElapsedTime()
{
Long milliesbetween= ChronoUnit.MILLIS.between(startTime,endTime);
return (milliesbetween);
}
}

View File

@@ -0,0 +1,53 @@
package Stopwatch;
import org.junit.Test;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.*;
public class StopWatchTest
{
@Test
public void getElapsedTime() throws InterruptedException
{
StopWatch Watch1 = new StopWatch();
StopWatch Watch2 = new StopWatch();
StopWatch Watch3 = new StopWatch();
StopWatch Watch4 = new StopWatch();
Watch1.start();
try
{
TimeUnit.MINUTES.sleep(1);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
Watch1.stop();
Watch2.start();
TimeUnit.MILLISECONDS.sleep(69);
Watch2.stop();
Watch3.start();
TimeUnit.MILLISECONDS.sleep(10);
Watch3.stop();
Watch4.start();
TimeUnit.MILLISECONDS.sleep(12);
Watch4.start();
TimeUnit.MILLISECONDS.sleep(69);
Watch4.stop();
assertEquals(60000, Watch1.getElapsedTime(), 10);
assertEquals(69, Watch2.getElapsedTime(),10);
assertEquals(10, Watch3.getElapsedTime(),10);
assertEquals(69, Watch4.getElapsedTime(),10);
}
}

View File

@@ -4,6 +4,7 @@ import java.util.Date;
import java.util.Stack;
public class Coffee extends Batch {
String name;
double price;
int stock;