Question

In: Computer Science

Objectives: Write a program which reads User Input using Scanner Print formatted output using printf or...

Objectives:

Write a program which reads User Input using Scanner

Print formatted output using printf or DecimalFormat

Practice programming simple mathematical calculations

Instructions:

Samwise Gamgee has finally decided to submit his expense report for all of his adventures regarding his travels to Mordor. Part of those expenses are his stay at the Prancing Pony Inn located in Bree.

You are to write a simple Java program which will generate an Invoice for his stay at the Inn.

Your program should ask for user input which represents the following information:

the number of nights Sam stayed at the Inn

the tax rate for the taxes collected by the Shire

the tax rate for the taxes collected by the City of Bree

cost per night of staying at the Inn

The program should then print out an Invoice which is similar to:

The Prancing Pony Inn, City of Bree, Shire

Invoice for Samwise Gamgee
Cost per night: $110
Shire Taxes per night: @Rate of 6.75% is $7.42
City of Bree Taxes per night: @Rate of 1.25% is $1.37
Total Cost per night: $118.79
Number of nights Stayed: 4
Total Cost: $475.16

(Bonus: Change the program so that the name of the Person and the two Tax Districts can also be entered by the user. These names should be allowed to contain spaces)

Solutions

Expert Solution

import java.util.Scanner;
public class HelloWorld{

public static void main(String []args){

Scanner sc = new Scanner(System.in);
System.out.print("the number of nights Sam stayed at the Inn: ");
int nights = sc.nextInt();
System.out.print("the tax rate for the taxes collected by the Shire: ");
float shireTaxRate = sc.nextFloat();
System.out.print("the tax rate for the taxes collected by the City of Bree: ");
float breeTaxRate = sc.nextFloat();
System.out.print("cost per night of staying at the Inn: ");
int costPerNight = sc.nextInt();

float ShireTaxPerNight = (costPerNight*shireTaxRate)/100;
float breeTaxPerNight = (costPerNight*breeTaxRate)/100;
float totalCostPerNight = costPerNight + ShireTaxPerNight + breeTaxPerNight;

float totalCost = totalCostPerNight*nights;
System.out.println("The Prancing Pony Inn, City of Bree, Shire");
System.out.println("Invoice for Samwise Gamgee");
System.out.printf("Cost per night: $%d\n", costPerNight);
System.out.printf("Shire Taxes per night: @Rate of %.2f%% is $%.2f\n", shireTaxRate, ShireTaxPerNight);
System.out.printf("City of Bree Taxes per night: @Rate of %.2f%% is $%.2f\n", breeTaxRate, breeTaxPerNight);
System.out.printf("Total Cost per night: $%.2f\n", totalCostPerNight);
System.out.printf("Number of nights Stayed: %d\n", nights);
System.out.printf("Total Cost: $%.2f\n", totalCost);
}
}


Related Solutions

Write a Python program which prompts the user to input a string. Then, print the string...
Write a Python program which prompts the user to input a string. Then, print the string in reverse to the terminal Sample output Please enter a word: "zeus" The reverse of zeus is suez Hint: There are several ways to accomplish this. Recall that a string is an itterable object and therefore can be used with a for loop
User the Scanner class for your input Write a java program to calculate the area of...
User the Scanner class for your input Write a java program to calculate the area of a rectangle. Rectangle Area is calculated by multiplying the length by the width   display the output as follow: Length =   Width = Area = Load: 1. Design (Pseudocode ) 2. Source file (Java file, make sure to include comments) 3. Output file (word or pdf or jpig file)
Write a C++ or Java program that reads an input graph data from a user. Then,...
Write a C++ or Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number ofvertices in the input graph is less than or equal to 20. Input format: This is a sample input from a user. 4 12 0 1 2 0 3 7 0 2 5 1 0 2 1 2 8 1 3 3 2...
Write a Java program that reads an input graph data from a user. Then, it should...
Write a Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number of vertices in the input graph is less than or equal to 20. Input format: This is a sample input from a user. 4 12 0 1 2 0 3 7 0 2 5 1 0 2 1 2 8 1 3 3 2 0...
Write java program that will ask for the user for 2 input lines and print out...
Write java program that will ask for the user for 2 input lines and print out all words that occur 1 or more times on both lines (case sensitive). Write this without arrays and method. Here is a sample run: <Output> Enter two lines to process. The quick brown fox jumps over a lazy dog The fox hound outruns the lazy dog The words that occur on both lines are: The fox lazy dog
Write a program in C, that uses standard input and output to ask the user to...
Write a program in C, that uses standard input and output to ask the user to enter a sentence of up to 50 characters, the ask the user for a number between 1 & 10. Count the number of characters in the sentence and multiple the number of characters by the input number and print out the answer. Code so far: char sentence[50]; int count = 0; int c; printf("\nEnter a sentence: "); fgets(sentence, 50, stdin); sscanf(sentence, %s;    for(c=0;...
Ask the user to input a series of numbers, write a C# program to output the...
Ask the user to input a series of numbers, write a C# program to output the sum, max, and min. Be sure to do error checking if the user input is not a number.
Question 1: 5pts Write a program to receive two integers as user input and then print:...
Question 1: 5pts Write a program to receive two integers as user input and then print: Sum Difference Product Average Maximum of the two Minimum of the two You may use the min and max functions declared in the math class. ********************************************************************************** Question 2: 10pts An online bank wants you to create a program that will show a prospective customer, how the deposit will grow. Your program should read the initial balance and the annual interest rate. Interest rate is...
Question 1: Write a program to receive two integers as user input and then print: Sum...
Question 1: Write a program to receive two integers as user input and then print: Sum Difference Product Average Maximum of the two Minimum of the two You may use the min and max functions declared in the math class. ********************************************************************************** Question 2: An online bank wants you to create a program that will show a prospective customer, how the deposit will grow. Your program should read the initial balance and the annual interest rate. Interest rate is compounded monthly....
Objectives To learn to code, compile, and run a program using file input and an output...
Objectives To learn to code, compile, and run a program using file input and an output file. Assignment Plan and code a program utilizing one file for input and one file for output to solve the following problem: Write a program to determine the highest number, the lowest number, their total, and the average of each line of numbers in a file. A file contains 7 numbers per line. How many lines a file contains is unknown. Note Label all...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT