Write a complete Java program to compute the cost of your annual coffee consumpt
ID: 3696997 • Letter: W
Question
Write a complete Java program to compute the cost of your annual coffee consumption.
(If you don't drink coffee, you can substitute tea, soda, or something else.)
The main method calls three methods to do this:
getDailyCost: requests from the user the estimated amount they spend on coffee
on each day of the week, Sunday through Saturday.
These values are stored in array of 7 doubles called dailyCost.
The method returns this array.
getAnnualCost: takes an array of doubles as a parameter (the dailyCost array)
and computes the annual cost for coffee (or tea, soda, etc).
Assume 52 weeks in a year.
The method returns the annual cost as a double.
printAnnualCost: takes a double (the annual cost) as a parameter and prints it
to the command line as, for example: “Your estimated total meal plan cost is: $1375.00.”
Explanation / Answer
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class coff
{
public static double[] getDailyCost()
{
int i=0;
System.out.println("enter the daily cost from Sunday to Saturday);
double c[7];
while(i<8)
{
Scanner sc - new Scanner(System.in);
c[i]= sc.nextDouble();
i++;
}
return c;
}
public static double getAnnualCost(double c[]);
{
System.out.print("enter the cost of coffee of each day");
int t=0;
double sum=0;
double p[7];
while(t<8)
{
Scanner c = new Scanner(System.in);
p[t] = c.nextDouble();
t++;
}
int k=0;
while(k<8)
{
sum= sum +c[k]*p[k];
}
sum=sum*52;
return sum;
}
public void printAnnualCost(double sum);
{
System.out.print("annual cost is" + sum);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.