原始问题:
用代码写一个代驾小程序
// 代码如下:
import java.util.Scanner;
public class DriverApp {
public static void main(String[] args) {
// Create a Scanner object for user input
Scanner scanner = new Scanner(System.in);
// Ask the user for their name and store it in a String variable
System.out.println("What is your name?");
String name = scanner.nextLine();
// Ask the user where they want to go and store it in a String variable
System.out.println("Where do you want to go?");
String destination = scanner.nextLine();
// Ask the user how many people will be travelling and store it in an int variable
System.out.println("How many people are travelling?");
int numOfPeople = Integer.parseInt(scanner.nextLine());
// Calculate fare based on number of people travelling and print out result System.out .println("Your fare will be $" + (numOfPeople * 10) + ".");
// Print out driver information with name, destination, number of people travelling, and fare System .out .println("Your driver's name is " + name + ". He/She will take you to " + destination + ". There are " + numOfPeople + " passengers travelling with you today and your total fare is $"+ (numOfPeople * 10) ); } }
Prev:手机流量卡封标