Merge pull request #13118 from freelansam/JAVA-16260
JAVA-16301: Check Article Code Matches GitHub
This commit is contained in:
@@ -22,4 +22,9 @@ public class Car implements Vehicle {
|
||||
public String slowDown() {
|
||||
return "The car is slowing down.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getSpeed() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -22,4 +22,9 @@ public class Motorbike implements Vehicle {
|
||||
public String slowDown() {
|
||||
return "The motorbike is slowing down.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getSpeed() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -32,4 +32,9 @@ public class MultiAlarmCar implements Vehicle, Alarm {
|
||||
public String turnAlarmOff() {
|
||||
return Vehicle.super.turnAlarmOff() + " " + Alarm.super.turnAlarmOff();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getSpeed() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -19,4 +19,10 @@ public interface Vehicle {
|
||||
static int getHorsePower(int rpm, int torque) {
|
||||
return (rpm * torque) / 5252;
|
||||
}
|
||||
|
||||
double getSpeed();
|
||||
|
||||
default double getSpeedInKMH(double speed) {
|
||||
return speed * 1.60934;
|
||||
}
|
||||
}
|
||||
@@ -84,5 +84,14 @@ public class Pizza {
|
||||
this.setStatus(PizzaStatusEnum.DELIVERED);
|
||||
}
|
||||
}
|
||||
|
||||
public int getDeliveryTimeInDays() {
|
||||
switch (status) {
|
||||
case ORDERED: return 5;
|
||||
case READY: return 2;
|
||||
case DELIVERED: return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -70,7 +70,7 @@ public class PizzaUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDelivered_thenPizzaGetsDeliveredAndStatusChanges() {
|
||||
public void givenPizaOrder_whenDelivered_thenPizzaGetsDeliveredAndStatusChanges() {
|
||||
Pizza pz = new Pizza();
|
||||
pz.setStatus(Pizza.PizzaStatusEnum.READY);
|
||||
pz.deliver();
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.baeldung.reduce.entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Rating {
|
||||
|
||||
double points;
|
||||
List<Review> reviews = new ArrayList<>();
|
||||
|
||||
public Rating() {}
|
||||
|
||||
public void add(Review review) {
|
||||
reviews.add(review);
|
||||
computeRating();
|
||||
}
|
||||
|
||||
private double computeRating() {
|
||||
double totalPoints = reviews.stream().map(Review::getPoints).reduce(0, Integer::sum);
|
||||
this.points = totalPoints / reviews.size();
|
||||
return this.points;
|
||||
}
|
||||
|
||||
public static Rating average(Rating r1, Rating r2) {
|
||||
Rating combined = new Rating();
|
||||
combined.reviews = new ArrayList<>(r1.reviews);
|
||||
combined.reviews.addAll(r2.reviews);
|
||||
combined.computeRating();
|
||||
return combined;
|
||||
}
|
||||
|
||||
public double getPoints() {
|
||||
return points;
|
||||
}
|
||||
|
||||
public List<Review> getReviews() {
|
||||
return reviews;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.baeldung.reduce.entities;
|
||||
|
||||
public class Review {
|
||||
|
||||
int points;
|
||||
String review;
|
||||
|
||||
public Review(int points, String review) {
|
||||
this.points = points;
|
||||
this.review = review;
|
||||
}
|
||||
|
||||
public int getPoints() {
|
||||
return points;
|
||||
}
|
||||
|
||||
public void setPoints(int points) {
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
public String getReview() {
|
||||
return review;
|
||||
}
|
||||
|
||||
public void setReview(String review) {
|
||||
this.review = review;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user