Question
Need to solve this program which will run exactly like sample run .. Thanks
Project 2 Using Classes and Objects (Chapter 3) Duc: sec calendar Two files to be submitted: . Algorithm of method main (AlgorithmOfMain.txt, no credit if this is missing) Java Source code (CarpetBill.java- no credit if this has syntax errors) Write a program that creates customers bills for a carpet company when the information below is given: irst name .Length and width of the carpet in feet The customers last name, f . Carpet price per square foot The Customer ID is composed of the capitalized first letter of the users first name, followed by the first five characters of the uscrs last name (Assuming the user-entered last name is at lcast five-character long), followed by a random two-digit number in the range 10 to 99(inclusive). The tax rate is 8.5%, make this a named constant and use it in your program. The input data consist of a set of 2 integers representing the length and width, and a floating-point number representing the carpet price per square foot. The program is to prompt the user for the input as shown below Display leading zeroes for all numeric values except the tax. Print the percentage sign for the tax. Print the decimal numbers to 2 decimal places. Make sure the decimal points for the two columns are aligned. Display all values using the same number of digits as the sample runs. Display the dollar-signs as shown. (Your sample runs must follow the exact format.) Sample Run 1 Enter your first name: John Enter your last name Smith Enter length of room (feet): 23 Enter width of room (feet) 13 Enter cost per square foot: 14.20 CUSTOMER Last Name First Name ID Smith John JSmith45 MEASUREMENT Length Width Area 023 feet 013 feet 299 square feet CHARGES Description Cost/Sq.Ft. Charges 14.20 Carpet Tax $4245.80 0360.89 8.50% Total $4606.69
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Executable code:

import java.util.*;
import java.lang.*;
import java.util.concurrent.ThreadLocalRandom;//to generate random numbers
public class CarpetBill{
public static void main(String []args){
Scanner scan= new Scanner(System.in);
//prompts the user to enter the data: first name, last name, length, width and cost
System.out.println("Enter your first name:");
String firstname=scan.nextLine();
System.out.println("Enter your last name:");
String lastname=scan.nextLine();
System.out.println("Enter length of the room (feet) :");
int length=scan.nextInt();
System.out.println("Enter width of the room (feet) :");
int width=scan.nextInt();
System.out.println("Enter cost per square foot: ");
System.out.println();
double cost=scan.nextDouble();
//obtaining the ID by capitalizinb the first letter of first name using touppercase function, adding it to substring of 5 characters from last name and random number
String ID=Character.toUpperCase(firstname.charAt(0))+lastname.substring(0,5 )+ThreadLocalRandom.current().nextInt(10,100);
//prints the data according to the format specified
System.out.println("CUSTOMER\n"+"Last name "+lastname+"\nFirst name "+firstname+"\nID "+ID);
System.out.println();
System.out.println("MEASUREMENT\n"+"Length 0"+length+" feet\nWidth 0"+width+" feet\nArea "+length*width+" square feet");
//Area = length*width
System.out.println();
System.out.println("CHARGES\n"+"Description "+"Cost/Sq.Ft. "+"Charges");
System.out.println("----------- "+"----------- "+"--------");
System.out.print("Carpet "+cost+" ");
//cost incurred is equal to cost per sq.ft*area
System.out.printf("$%.2f\n", cost*length*width);
//declaring the tax as final i.e. constant
final double tax=8.5;
System.out.print("Tax "+tax+"% ");
//calculating and printing the amount of tax
System.out.printf("0%.2f\n", cost*length*width*tax*0.01);
System.out.println(" --------");
//print the total amount
double total =cost*length*width+cost*length*width*tax*0.01;
System.out.printf("Total $%.2f\n",total);
}
}

sample input:

John
Smith
23
13
14.20

sample output:

Enter your firs Enter your last name: Enter length of the room (feet): Enter width of the room (feet) Enter cost per square f

Add a comment
Know the answer?
Add Answer to:
Need to solve this program which will run exactly like sample run .. Thanks Project 2...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Flowchart 1: Create a flowchart for a program that calculates the total cost of carpeting a...

    Flowchart 1: Create a flowchart for a program that calculates the total cost of carpeting a room. Assume that the room is rectangular. The data required for running the program will be the length of the room, the width of the room, and the cost per square yard of the carpet. When the user runs the program it must, in the following order: Prompt for the length of the room. Prompt for the width of the room. Prompt for the...

  • program language: python 3 Purpose: Solve a problem by writing multiple functions that perform different subtasks,...

    program language: python 3 Purpose: Solve a problem by writing multiple functions that perform different subtasks, and combining their use to solve a larger problem. Also to practice documenting functions. Degree of Difficulty: Moderate Your task is to compute the cost of renovating the flooring in a rectangular room. This includes replacing the carpet and and the baseboards. Your task is to write a Python program that calculates and the cost of the renovation. To accomplish this, you will need...

  • This is in c programming using functions in visual studios Carpet Jolb A carpeting company wants...

    This is in c programming using functions in visual studios Carpet Jolb A carpeting company wants to estimate what it will cost a customer to have a room carpeted. They can carpet 65 sq. ft. of room space in 4 hours, and they charge $25.00 per hour as their labor rate Write a program to ask the user for the length of the room (in inches) to be carpeted, the width of the room (in inches) to be carpeted, and...

  • I need a c++ visual basic program that will. Carpet Calculator. This problem starts with the...

    I need a c++ visual basic program that will. Carpet Calculator. This problem starts with the FeetInches class that is provided in the course Content area on the assignment page for this week. This program will show how classes will interact with each other as data members within another class. Modify the FeetInches class by overloading the following operators which should all return a bool. <= >= != Next add a copy constructor to the FeetInches class and a multiply...

  • Design a modular program using pseudo-code which prompts a user for their first name, followed by...

    Design a modular program using pseudo-code which prompts a user for their first name, followed by their last name; then displays a "Hello" salutation which concatenates their first name with their last name. Sample output (user input shown in red): Please enter your first name: John Please enter your last name: Smith Hello, John Smith! Your program must include a main module and one function; this function prompts the user for either their first name or last name, using a...

  • I need a C++ program like this please! and please follow all instructions! Thanks so much!...

    I need a C++ program like this please! and please follow all instructions! Thanks so much! A menu-driven program with 3 choices: Names Rearranger, Number Validator, or Exit Menu Option 1: Name Rearranger: 1. Input ONE STRING from the user containing first name, middle name, and last name. ie, "John Allen Smith". USE THE GETLINE function. (Not cin) 2. Loop through the string and validate for a-z or A-Z or . If the name has any other characters, then ask...

  • c/c++ 6 Using some of the library string handling functions Here, you are to read first...

    c/c++ 6 Using some of the library string handling functions Here, you are to read first and last names of a person and join the two into a full nmae. But you will have to check that the string full name has a 'room' for all these characters. In this problem, the maximum number of characters in the full name is 20 Initially allow a maximum number of 15 characters of first & last names (One name length may compensate...

  • .Need code for my java class !! Write a simple java program that uses loops. You...

    .Need code for my java class !! Write a simple java program that uses loops. You may use ‘WHILE’ or ‘FOR’ or ‘DO-WHILE’ – you decide. The program should use a loop to compute the semester average for up to 5 students. In the loop the user will ask for a student name and their 3 test scores and add them up and divide the total by 3 giving the semester average. You will print out the student name and...

  • Write a program that prompts the user to enter a list of names. Each person's name...

    Write a program that prompts the user to enter a list of names. Each person's name is separated from the next by a semi-colon and a space (: and the names are entered lastName, firstName (i.e. separated by ',). Your program should then print out the names, one per line, with the first names first followed by the last names. A sample run of your program should look like Please enter your list of names: Epstein, Susan; St. John, Katherine;...

  • Your task for this project is to write a parser for a customer form. You need to develop a Java a...

       Your task for this project is to write a parser for a customer form. You need to develop a Java application using Parboiled library. Your program should include a grammar for the parser and display the parse tree with no errors. Remember that your fifth and sixth assignments are very similar to this project and you can benefit from them. The customer form should include the following structure: First name, middle name (optional), last name Street address, city, state (or...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT