Advertisement
eranseg

Taxi

Jul 21st, 2019
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. Homework Assignment 4 - Taxi
  2. --------------------------------------
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class Taxi {
  7.     public static void main(String[] args) {
  8.         Scanner s = new Scanner(System.in);
  9.         final float initRate = 10.2f; // Setting the initial rate as a constant by defining it as 'final'
  10.         float pricePerKM = 1.3f;
  11.         int suitCaseRate = 2;
  12.         float distance;
  13.         int numOfCases;
  14.         // Getting data from the user
  15.         System.out.println("Please enter the distance to your destination: ");
  16.         distance = s.nextFloat();
  17.         System.out.println("Please enter the number of suitcases: ");
  18.         numOfCases = s.nextInt();
  19.         // Calculating the total cost and printing it to the console
  20.         System.out.println("The total price for the ride is: " + (initRate + distance*pricePerKM + numOfCases*suitCaseRate));
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement