Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class Question_5_Average_Utility_Bill { String[] months = { January, February, March, April, May, June, July, August, September, October, November, December }; public static void main(String[]

public class Question_5_Average_Utility_Bill { String[] months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; public static void main(String[] args) { Question_5_Average_Utility_Bill billsAverage = new Question_5_Average_Utility_Bill(); billsAverage.billAverages(); } private void billAverages() { double[] bills = getYearBills(); double average = averageBillAmount(bills); System.out.println(String.format("Your average bill is %.2f", average)); printBillTable(bills); } public double[] getYearBills() { // TODO ask user for bill amount for January, then February... // Create a new double array. // Store values the user enters in this array. // Return this array. return null; // replace with your code } public double averageBillAmount(double[] bills) { // TODO Calculate the average value of all the bills, and return this number. return 0; // replace with your code } public void printBillTable(double[] bills) { // TODO display the month name, and bill amounts, in table form. // Use the months array to display the names. // Replace these lines with your code. You'll need to use a loop to display all the months. // String formatting is helpful. Here's some examples to space some columns with exactly 15 character width System.out.println(String.format("| %-15s| %-15s|", "Month", "Bill" )); System.out.println(String.format("| %-15s| %-15.2f|", "January", 44.5995 )); } } ---------------------------------------------------- package question5; import static input.InputUtils.doubleInput; /** * * A parcel delivery company charges the following rates to ship a parcel. Up to 10 pounds: $2.15 per pound Up to 20 pounds: $1.55 per pound Up to 30 pounds: $1.15 per pound The shipping company does not ship parcels that weigh over 30 pounds. So, a parcel that weighs 17 pounds will cost $1.55 x 17 = $26.35. Write a program that asks the user for the weight of a parcel and displays whether it can be shipped, and what it will cost. Optional extra: the most obvious solution to this problem uses if statements for the price bands. Can you think of a different way? Hint loops and arrays of price and max weights for price? */

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

Step: 3

blur-text-image

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

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions