Skip to content

Commit

Permalink
Added cabServices for normal and premium
Browse files Browse the repository at this point in the history
  • Loading branch information
blsonalib committed Dec 17, 2019
1 parent a854cd4 commit 04c511a
Show file tree
Hide file tree
Showing 28 changed files with 165 additions and 56 deletions.
Binary file modified .gradle/5.2.1/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/5.2.1/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/5.2.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/5.2.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/5.2.1/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/5.2.1/javaCompile/classAnalysis.bin
Binary file not shown.
Binary file modified .gradle/5.2.1/javaCompile/jarAnalysis.bin
Binary file not shown.
Binary file modified .gradle/5.2.1/javaCompile/javaCompile.lock
Binary file not shown.
Binary file modified .gradle/5.2.1/javaCompile/taskHistory.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h1>Class com.cabinvoicegenerator.InvoiceServiceTest</h1>
<tr>
<td>
<div class="infoBox" id="tests">
<div class="counter">4</div>
<div class="counter">8</div>
<p>tests</p>
</div>
</td>
Expand All @@ -41,7 +41,7 @@ <h1>Class com.cabinvoicegenerator.InvoiceServiceTest</h1>
</td>
<td>
<div class="infoBox" id="duration">
<div class="counter">0.002s</div>
<div class="counter">0.011s</div>
<p>duration</p>
</div>
</td>
Expand All @@ -63,6 +63,9 @@ <h1>Class com.cabinvoicegenerator.InvoiceServiceTest</h1>
<li>
<a href="#tab0">Tests</a>
</li>
<li>
<a href="#tab1">Standard output</a>
</li>
</ul>
<div id="tab0" class="tab">
<h2>Tests</h2>
Expand All @@ -75,27 +78,55 @@ <h2>Tests</h2>
</tr>
</thead>
<tr>
<td class="success">givenDistanceAndTime_ShouldReturnTotalFare</td>
<td class="success">givenDistanceAndTimeForNormal_ShouldReturnTotalFare</td>
<td class="success">0.001s</td>
<td class="success">passed</td>
</tr>
<tr>
<td class="success">givenDistanceAndTimeForPremium_ShouldReturnTotalFare</td>
<td class="success">0s</td>
<td class="success">passed</td>
</tr>
<tr>
<td class="success">givenLessDistanceAndTime_ShouldReturnMinimumFare</td>
<td class="success">0.001s</td>
<td class="success">givenLessDistanceAndTimeForNormal_ShouldReturnMinimumFare</td>
<td class="success">0s</td>
<td class="success">passed</td>
</tr>
<tr>
<td class="success">givenMultipleRides_ShouldReturnInvoiceSummary</td>
<td class="success">givenLessDistanceAndTimeForPremium_ShouldReturnMinimumFare</td>
<td class="success">0s</td>
<td class="success">passed</td>
</tr>
<tr>
<td class="success">givenUserIdAndRides_ShouldReturnInvoiceSummary</td>
<td class="success">givenMultipleRidesForNormal_ShouldReturnInvoiceSummary</td>
<td class="success">0.002s</td>
<td class="success">passed</td>
</tr>
<tr>
<td class="success">givenMultipleRidesForPremium_ShouldReturnInvoiceSummary</td>
<td class="success">0.001s</td>
<td class="success">passed</td>
</tr>
<tr>
<td class="success">givenUserIdAndRidesForNormal_ShouldReturnInvoiceSummary</td>
<td class="success">0.001s</td>
<td class="success">passed</td>
</tr>
<tr>
<td class="success">givenUserIdAndRidesForPremium_ShouldReturnInvoiceSummary</td>
<td class="success">0.006s</td>
<td class="success">passed</td>
</tr>
</table>
</div>
<div id="tab1" class="tab">
<h2>Standard output</h2>
<span class="code">
<pre>InvoiceSummary{numOfRides=2, totalFare=60.0, averageFare=30.0}
InvoiceSummary{numOfRides=2, totalFare=30.0, averageFare=15.0}
</pre>
</span>
</div>
</div>
<div id="footer">
<p>
Expand All @@ -104,7 +135,7 @@ <h2>Tests</h2>
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
</label>
</div>Generated by
<a href="http://www.gradle.org">Gradle 5.2.1</a> at 16-Dec-2019, 6:15:10 PM</p>
<a href="http://www.gradle.org">Gradle 5.2.1</a> at 17-Dec-2019, 10:14:45 AM</p>
</div>
</div>
</body>
Expand Down
14 changes: 7 additions & 7 deletions build/reports/tests/test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h1>Test Summary</h1>
<tr>
<td>
<div class="infoBox" id="tests">
<div class="counter">4</div>
<div class="counter">8</div>
<p>tests</p>
</div>
</td>
Expand All @@ -38,7 +38,7 @@ <h1>Test Summary</h1>
</td>
<td>
<div class="infoBox" id="duration">
<div class="counter">0.002s</div>
<div class="counter">0.011s</div>
<p>duration</p>
</div>
</td>
Expand Down Expand Up @@ -82,10 +82,10 @@ <h2>Packages</h2>
<td class="success">
<a href="packages/com.cabinvoicegenerator.html">com.cabinvoicegenerator</a>
</td>
<td>4</td>
<td>8</td>
<td>0</td>
<td>0</td>
<td>0.002s</td>
<td>0.011s</td>
<td class="success">100%</td>
</tr>
</tbody>
Expand All @@ -109,10 +109,10 @@ <h2>Classes</h2>
<td class="success">
<a href="classes/com.cabinvoicegenerator.InvoiceServiceTest.html">com.cabinvoicegenerator.InvoiceServiceTest</a>
</td>
<td>4</td>
<td>8</td>
<td>0</td>
<td>0</td>
<td>0.002s</td>
<td>0.011s</td>
<td class="success">100%</td>
</tr>
</tbody>
Expand All @@ -126,7 +126,7 @@ <h2>Classes</h2>
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
</label>
</div>Generated by
<a href="http://www.gradle.org">Gradle 5.2.1</a> at 16-Dec-2019, 6:15:10 PM</p>
<a href="http://www.gradle.org">Gradle 5.2.1</a> at 17-Dec-2019, 10:14:45 AM</p>
</div>
</div>
</body>
Expand Down
10 changes: 5 additions & 5 deletions build/reports/tests/test/packages/com.cabinvoicegenerator.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h1>Package com.cabinvoicegenerator</h1>
<tr>
<td>
<div class="infoBox" id="tests">
<div class="counter">4</div>
<div class="counter">8</div>
<p>tests</p>
</div>
</td>
Expand All @@ -40,7 +40,7 @@ <h1>Package com.cabinvoicegenerator</h1>
</td>
<td>
<div class="infoBox" id="duration">
<div class="counter">0.002s</div>
<div class="counter">0.011s</div>
<p>duration</p>
</div>
</td>
Expand Down Expand Up @@ -80,10 +80,10 @@ <h2>Classes</h2>
<td class="success">
<a href="../classes/com.cabinvoicegenerator.InvoiceServiceTest.html">InvoiceServiceTest</a>
</td>
<td>4</td>
<td>8</td>
<td>0</td>
<td>0</td>
<td>0.002s</td>
<td>0.011s</td>
<td class="success">100%</td>
</tr>
</table>
Expand All @@ -96,7 +96,7 @@ <h2>Classes</h2>
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
</label>
</div>Generated by
<a href="http://www.gradle.org">Gradle 5.2.1</a> at 16-Dec-2019, 6:15:10 PM</p>
<a href="http://www.gradle.org">Gradle 5.2.1</a> at 17-Dec-2019, 10:14:45 AM</p>
</div>
</div>
</body>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="com.cabinvoicegenerator.InvoiceServiceTest" tests="4" skipped="0" failures="0" errors="0" timestamp="2019-12-16T12:45:10" hostname="admin1-desktop" time="0.003">
<testsuite name="com.cabinvoicegenerator.InvoiceServiceTest" tests="8" skipped="0" failures="0" errors="0" timestamp="2019-12-17T04:44:45" hostname="admin1-desktop" time="0.012">
<properties/>
<testcase name="givenLessDistanceAndTime_ShouldReturnMinimumFare" classname="com.cabinvoicegenerator.InvoiceServiceTest" time="0.001"/>
<testcase name="givenUserIdAndRides_ShouldReturnInvoiceSummary" classname="com.cabinvoicegenerator.InvoiceServiceTest" time="0.001"/>
<testcase name="givenDistanceAndTime_ShouldReturnTotalFare" classname="com.cabinvoicegenerator.InvoiceServiceTest" time="0.0"/>
<testcase name="givenMultipleRides_ShouldReturnInvoiceSummary" classname="com.cabinvoicegenerator.InvoiceServiceTest" time="0.0"/>
<system-out><![CDATA[]]></system-out>
<testcase name="givenMultipleRidesForNormal_ShouldReturnInvoiceSummary" classname="com.cabinvoicegenerator.InvoiceServiceTest" time="0.002"/>
<testcase name="givenDistanceAndTimeForPremium_ShouldReturnTotalFare" classname="com.cabinvoicegenerator.InvoiceServiceTest" time="0.0"/>
<testcase name="givenDistanceAndTimeForNormal_ShouldReturnTotalFare" classname="com.cabinvoicegenerator.InvoiceServiceTest" time="0.001"/>
<testcase name="givenUserIdAndRidesForPremium_ShouldReturnInvoiceSummary" classname="com.cabinvoicegenerator.InvoiceServiceTest" time="0.006"/>
<testcase name="givenLessDistanceAndTimeForPremium_ShouldReturnMinimumFare" classname="com.cabinvoicegenerator.InvoiceServiceTest" time="0.0"/>
<testcase name="givenMultipleRidesForPremium_ShouldReturnInvoiceSummary" classname="com.cabinvoicegenerator.InvoiceServiceTest" time="0.001"/>
<testcase name="givenLessDistanceAndTimeForNormal_ShouldReturnMinimumFare" classname="com.cabinvoicegenerator.InvoiceServiceTest" time="0.0"/>
<testcase name="givenUserIdAndRidesForNormal_ShouldReturnInvoiceSummary" classname="com.cabinvoicegenerator.InvoiceServiceTest" time="0.001"/>
<system-out><![CDATA[InvoiceSummary{numOfRides=2, totalFare=60.0, averageFare=30.0}
InvoiceSummary{numOfRides=2, totalFare=30.0, averageFare=15.0}
]]></system-out>
<system-err><![CDATA[]]></system-err>
</testsuite>
2 changes: 2 additions & 0 deletions build/test-results/test/binary/output.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
?InvoiceSummary{numOfRides=2, totalFare=60.0, averageFare=30.0}
 ?InvoiceSummary{numOfRides=2, totalFare=30.0, averageFare=15.0}
Binary file modified build/test-results/test/binary/output.bin.idx
Binary file not shown.
Binary file modified build/test-results/test/binary/results.bin
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.cabinvoicegenerator;

public enum CabSubscriptionsType {
NORMAL, PREMIUM
}
30 changes: 21 additions & 9 deletions src/main/java/com/cabinvoicegenerator/InVoiceService.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
package com.cabinvoicegenerator;

import java.awt.*;
import java.util.List;

public class InVoiceService {

private static final int COST_PER_TIME = 1;
private static final double MINIMUM_COST_PER_KM = 10;
private static final double MINIMUM_FARE = 5;
private static final int PREMIUM_COST_PER_TIME = 2;
private static final double PREMIUM_MINIMUM_COST_PER_KM = 15;
private static final double PREMIUM_MINIMUM_FARE = 20;

public InVoiceService(CabSubscriptionsType cabSubscriptions) {
this.cabSubscriptions = cabSubscriptions;
}

private RideRepository rideRepository = new RideRepository();
CabSubscriptionsType cabSubscriptions;

public double calculateTotalFare(double distance, int time) {
double totalFare = distance * MINIMUM_COST_PER_KM + time * COST_PER_TIME;
return Math.max(totalFare, MINIMUM_FARE);
if (CabSubscriptionsType.NORMAL.equals(cabSubscriptions)) {
double totalFare = distance * MINIMUM_COST_PER_KM + time * COST_PER_TIME;
return Math.max(totalFare, MINIMUM_FARE);
} else if (CabSubscriptionsType.PREMIUM.equals(cabSubscriptions)) {
double totalFare = distance * PREMIUM_MINIMUM_COST_PER_KM + time * PREMIUM_COST_PER_TIME;
return Math.max(totalFare, PREMIUM_MINIMUM_FARE);
}
return 0.0;
}

public InvoiceSummary calculateTotalFare(Ride[] rides) {
Expand All @@ -23,13 +35,13 @@ public InvoiceSummary calculateTotalFare(Ride[] rides) {
return new InvoiceSummary(rides.length, totalFare);
}

public void addRides (String userId, Ride[] rides) {
rideRepository.addRides(userId,rides);

public void addRides(String userId, Ride[] rides) {
rideRepository.addRides(userId, rides);
}

public InvoiceSummary getInvoiceSummmary(String userId) {
Ride[] rides=rideRepository.getRides(userId);
Ride[] rides = rideRepository.getRides(userId);
return this.calculateTotalFare(rides);
}
}

9 changes: 9 additions & 0 deletions src/main/java/com/cabinvoicegenerator/InvoiceSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@ public boolean equals(Object o) {
Double.compare(that.totalFare, totalFare) == 0 &&
Double.compare(that.averageFare, averageFare) == 0;
}

@Override
public String toString() {
return "InvoiceSummary{" +
"numOfRides=" + numOfRides +
", totalFare=" + totalFare +
", averageFare=" + averageFare +
'}';
}
}
Loading

0 comments on commit 04c511a

Please sign in to comment.