1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Soloha48 [4]
3 years ago
7

In this scenario, two friends are eating dinner at a restaurant. The bill comes in the amount of 47.28 dollars. The friends deci

de to split the bill evenly between them, after adding 15% tip for the service. Calculate the tip, the total amount to pay, and each friend's share, then output a message saying "Each person needs to pay: " followed by the resulting number.

Computers and Technology
2 answers:
pickupchik [31]3 years ago
5 0

Answer:

The java program for the given scenario is as follows.

import java.util.*;

import java.lang.*;

public class Main

{

   //variables for bill and tip declared and initialized

   static double bill=47.28, tip=0.15;

   //variables for total bill and share declared

   static double total, share1;

public static void main(String[] args) {

    double total_tip= (bill*tip);

    //total bill computed

    total = bill + total_tip;

    //share of each friend computed

    share1 = total/2;

    System.out.printf("Each person needs to pay: $%.2f", share1);  

}

}

Explanation:

1. The variables to hold the bill and tip percent are declared as double and initialized with the given values.

static double bill=47.28, tip=0.15;

2. The variables to hold the values of total bill amount and total tip are declared as double.

3. All the variables are declared outside main() and at class level, hence declared as static.

4. Inside main(), the values of total tip, total bill and share of each person are computed as shown.

double total_tip= (bill*tip);

total = bill + total_tip;

share1 = total/2;

5. The share of each person is displayed to the user. The value is displayed with only two decimal places which is assured by %.2f format modifier. The number of decimal places required can be changed by changing the number, i.e. 2. This format is used with printf() and not with println() method.

System.out.printf("Each person needs to pay: $%.2f", share1);  

6. The program is not designed to take any user input.

7. The program can be tested for any value of bill and tip percent.

8. The whole code is put inside a class since java is a purely object-oriented language.

9. Only variables can be declared outside method, the logic is put inside a method in a purely object-oriented language.

10. As shown, the logic is put inside the main() method and only variables are declared outside the method.

11. Due to simplicity, the program consists of only one class.

12. The output is attached.

Sergio039 [100]3 years ago
5 0

Answer:

bill =  47.28

tip = bill *.15

total = bill + tip

share = total

print( "Each person needs to pay: "+str(share) )

Explanation:

You might be interested in
What is an administrator?
Drupady [299]
A person responsible for running a business, organization, etc.
3 0
2 years ago
A security administrator is required to submit a new csr to a ca. what is the first step?
m_a_m_a [10]
If an administrator needs to renew a certificate for a web server he/she should submit the CSR (Certificate Signing Request) to CA.
<span>If a security administrator is required to submit a new CSR to a CA, teh fisrt step the administrator should do is to g</span>enerate a new private key based on RSA.
4 0
3 years ago
Which best describes inserting a table using the Table Gallery
balandron [24]
The table gallery is to help you create the table.
4 0
3 years ago
Read 2 more answers
If you wanted to buy a house that cost $150,000 and you knew you needed a down payment of five percent, how much would you need
andrew11 [14]

Answer:

7,500 is the answer

Explanation:

7,500 is 5% of 150,000

8 0
2 years ago
Describe software as a service. what features distinguish it from application software installed on a personal computing device
Triss [41]
???????????????????????????
6 0
3 years ago
Read 2 more answers
Other questions:
  • What information is required for a complete citation of a website source?
    8·2 answers
  • What internet service provider first dominated the internet in the 1990s?
    15·1 answer
  • What is a Photojournalist
    5·1 answer
  • Who has access to the source code of proprietary software
    6·1 answer
  • Create a function called "strip_r_o" that takes in a STRING and strips all the Rs and Os from the string. Also use a FOR loop in
    7·1 answer
  • Explain the difference between social engineering and reverse social engineering.
    6·1 answer
  • How would you describe<br> "analogous color harmony" to a six year old?
    13·1 answer
  • Write a paragraph discussing privacy issues on the internet<br> and their impact on human lives.
    9·1 answer
  • A computer game allows a player to repeat a level until they run out of lives. Which two of the following loops would work corre
    8·2 answers
  • Question 1 of 10
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!