Computer Programming I Homework #4

$24.99 $18.99

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:…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)
  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

    1. 30% of bill: 96.12 TL

    1. 70% of bill: 224.28 TL

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

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

  1. 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:

  1. 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.

  1. 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:

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

      1. 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.

  1. 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.

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

  1. Sample Input: 3 12.8 23 9.2 320.40

1/8

  1. Sample Runs

    1. Sample Run 1

7634 78KS Invalid Input !

    1. Sample Run 2

7789!

Invalid Input !

    1. Sample Run 3

4539 1488 0343 6467 DNumber:4_3_1_8_0_4_6_6_ LNumber:8569247803833437 Number is Valid

    1. Sample Run 4

8273 1232 7352 0569 DNumber:8_7_1_3_7_5_0_6_ LNumber:7253226253120539 Number is Invalid

    1. Sample Run 5

42 123 4598

DNumber:_2_2_4_9_

LNumber:441438598

Number is Invalid

  1. Sample Run 6

3 89 23 1234 DNumber:_8_2_1_3_ LNumber:379432264 Number is Valid

4/8

CSE1141 – S’21 | HW#4

IMPORTANT NOTES

  1. Only parts selected from the selected questions will be graded. So if you send only one program, you might get a grade of 0 based on our evaluation.

  1. Write a comment at the beginning of each program to explain the purpose of the program. Write your name and student ID as a comment. Include necessary comments to explain your actions.

  1. Select meaningful names for your variables.

  1. You are allowed to use the materials that you have learned in lectures and labs. Do not use the ones that you have not learned in the course.

  1. The outputs of your programs must be the same as the sample runs above.

  1. You should exactly print the outputs with 2 digits after the decimal point.

  1. Please be sure that your programs run properly on any computer.

  1. Since only selected parts will be graded, send a complete solution for the homework; otherwise, you may get a zero-grade based on our evaluation.

  1. Your program will be tested with an auto-grader. So, it should take the inputs exactly the same in the sample runs and it should print the outputs exactly the same in the sample runs. Otherwise, your program may fail.

  1. Your program should execute correctly for different test cases.

  1. You should not print any messages before input taking.

  1. Please do not write any package name at the beginning of your code.

  1. Please zip all your files into a single zip file using file naming convention StudentID_HW4.zip, e.g.,

150120123_HW4.zip. Your zip file should contain the followings:

    1. Java source code for Question 1 (HW4_Q1_StudentID.java)

    1. Java class file for Question 1 (HW4_Q1_StudentID.class

    1. Java source code for Question 2 (HW4_Q2_StudentID.java)

    1. Java class file for Question 2 (HW4_Q2_StudentID.class

    1. Java source code for Question 3 (HW4_Q3_StudentID.java)

    1. Java class file for Question 3 (HW4_Q3_StudentID.class

  1. Submit your zip file to http://ues.marmara.edu.tr before deadline.

  1. You are responsible for making sure you are turning in the right file, and that it is not corrupted in anyway. We will not allow resubmissions if you turn in the wrong file, even if you can prove that you have not modified the file after the deadline.

  1. Each student should submit his/her own homework. You can discuss with your peers about the homework, but you are not allowed to exchange codes or pseudocodes. This also applies to material found on the web. If some submitted homework assignments are found to be identical or suspected to be identical, all involved parties will get a grade of ZERO from all homework. You should submit your own work. In case of any forms of cheating or copying, both giver and receiver are equally culpable and suffer equal penalties. All types of plagiarism will result in FF grade from the course.

  1. No late submission will be accepted.

8/8

Computer Programming I Homework #4
$24.99 $18.99