Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1) Write a program that calculates the invoice of each flat in an apartment building. Assume that there are N flats in a building and

1) Write a program that calculates the invoice of each flat in an apartment building. Assume that there are N flats in a building and apartment heating is the central system. 30% of bill will be shared equally among the flats, the rest 70% will be shared according to the consumption of each flat.

Sample Calculation:

Suppose that an apartment building has 3 flats

Consumption of each flat (m3 ): 12.8, 23, 9.2

Total Bill: 320.40 TL o 30% of bill: 96.12 TL o 70% of bill: 224.28 TL

Then, the bill for each flat should be calculated as follows:

o The bill for Flat #1: 32.04 + 63.80 = 95.83 TL

o The bill for Flat #2: 32.04 + 114.63 = 146.67 TL

o The bill for Flat #3: 32.04 + 45.85 = 77.89 TL

Your program must have the following methods:

a) public static void main(String[] args)

Main method will take the inputs from the user.

Then, it will invoke the methods calculateTheInvoice() and printBills(), respectively

. b) public static double[] calculateTheInvoice (double[] flats, double totalBill)

You should calculate the bill of each flat based on the given sample calculation scenario.

This method should take the following parameters:

o A double array flats that indicates the consumption of each flat.

o A double value totalBill that contains the total consumption of the whole apartment building.

Then, the method should return a double array, which contains the calculated bill for each flat, to the main() method

. c) public static void printBills (double[] bills)

You should print the values to the console display.

First input (N) is the number of flats in the apartment building.

It is followed by N inputs for N flat consumption, and the last input is for the total bill.

o Input Format: N C1 C2 C3 .. Cn TotalBill

o Sample Input: 3 12.8 23 9.2 320.40

where,

N is the number of flats, C1, C2, .. Cn are the consumptions of each flat, and TotalBill is the total bill for the apartment building.

d) Sample Runs

i) Sample Run 1

(Input: 3 12.8 23 9.2 320.40)

3 12.8 23 9.2 320.40

Flat #1: 95.83

Flat #2: 146.67

Flat #3: 77.89

ii) Sample Run 2

(Input: 15 12 14.2 15.87 21.4 19 13 8.1 11 15.14 16 23.14 27 5.98 7.18 17 812.90)

15 12 14.2 15.87 21.4 19 13 8.1 11 15.14 16 23.14 27 5.98 7.18 17 812.90

Flat #1: 46.47

Flat #2: 52.0

Flat #3: 56.21

Flat #4: 70.13

Flat #5: 64.09

Flat #6: 48.98

Flat #7: 36.65

Flat #8: 43.95

Flat #9: 54.37

Flat #10: 56.54

Flat #11: 74.51

Flat #12: 84.23

Flat #13: 31.31

Flat #14: 34.33

Flat #15: 59.05

iii) Sample Run 3

(Input: 5 44.02 0 17 21.01 7.56 210.82)

5 44.02 0 17 21.01 7.56 210.82 1.

Flat: 85.15 2.

Flat: 12.64 3.

Flat: 40.65 4.

Flat: 47.25 5.

Flat: 25.

PLEASE write new code do not reuse java eclipse

I WILL BE VERY HAPPY IF YOU TRY TO WRITE A BEGINNING-LEVELS JAVA ( ECLIPSE ) CODE. DO NOT USE A CLASS OUTSIDE THE SCANNER CLASS ( import.util.Scanner ) SO ( do not use import java.util.Collections , etc imort java.io

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems

Authors: Carlo Zaniolo, Stefano Ceri, Christos Faloutsos, Richard T. Snodgrass, V.S. Subrahmanian, Roberto Zicari

1st Edition

155860443X, 978-1558604438

More Books

Students also viewed these Databases questions

Question

What are the purposes of collection messages? (Objective 5)

Answered: 1 week ago