You are to write a Java program that prompts the user to enter a number for each
ID: 3789527 • Letter: Y
Question
You are to write a Java program that prompts the user to enter a number for each type of transportation. Use System.out.println method to output the message. if you follow the instructions it will help solve the code
A2.20 Java example: Married couple names with variables 2.21 Lab2a Due 09-Feb-17 Students This content is controlled by your instructor, and is not zyBook content. Direct questions or concerns about this content to your instructor. If you have any technical issues with the zyLab submission system, use the "Trouble with lab?" button at the bottom Introduction Here is the program scenario: At a bicycle rental shop, there are unicycles, bicycles, and tandem bicycles available. A group of people want to ride and the program needs to calculate the total cost of the group rental. Background Reading Horstmann, Chapter 2.1-2. This program is similar to the Ticket Seller program in your Course Reader. Grading This lab is worth 10 points. ZyBook will give you a score out of 10, however, the grader will also review your code to give suggestions or corrections. If a program is written in such a way that it merits a major correction, a loss of points may occur. Task You are to write a Java program that prompts the user to enter a number for each type of transportation. Use System. out.println method to output the message. 1. The prompt should read exactly: Enter unicycles, bicycles tandems 2. Following this, use the Scanner class to read in 3 whole numbers to represent each transportation type in order. When defining your variables, choose a data type that represents whole numbers When the program runs, you can enter the three numbers on one line or Separate lines. Try it both ways. Example input: 08 3 3. Next your program will calculate the total cost. Rental prices are $2.50 for unicycles, $5.00 for bicycles, and $8.00 for tandem bicycles (a tandem bike has two seats). When defining the cost, choose a data type that represents a fractional (floating point number. Note that it is not necessary to define a variable to store the cost, but it may make your program more easy to read 4. Finally your program should output the cost calculated in step 3 preceded by the String "Total rental cost is Example Enter unicycles, bicycles tandems 0 8 3 Total rental cost is $64.0 Don't worry that the program doesn't print $64.00. We will have an opportunity to learn to format output later in the semester. Lab 2.21.1: Lab2a Due 09-Feb-17 Submissio Lab2a. java Load default template. 1 public class Lab2a 2 public static void mainCStringC args) f Type your code here.Explanation / Answer
Lab2a.java
import java.util.Scanner;
public class Lab2a {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter unicycles, bicycles, tandem: ");
int u = scan.nextInt();
int b = scan.nextInt();
int t = scan.nextInt();
double totalCost = u * 2.5 + b * 5 + t * 8;
System.out.println("Total rental cost is $"+totalCost);
}
}
Output:
Enter unicycles, bicycles, tandem:
0 8 3
Total rental cost is $64.0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.