Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package TestJan;
- import java.util.Scanner;
- public class FriendlyTrip {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- double km = Double.parseDouble(scan.nextLine());
- double fuelConsumption = Double.parseDouble(scan.nextLine());
- double fuelPrice = Double.parseDouble(scan.nextLine());
- double sum = Double.parseDouble(scan.nextLine());
- double carConsumption = (km *fuelConsumption) / 100;
- double costs = carConsumption * fuelPrice;
- double totalMoneyLeft = costs - sum;
- if(totalMoneyLeft <= 0){
- System.out.printf("You can take a trip. %.2f money left.", Math.abs(totalMoneyLeft));
- }else{
- double pricePerPerson = sum /5;
- System.out.printf("Sorry, you cannot take a trip. Each will receive %.2f money.", pricePerPerson);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement