Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a Java application that: asks the user for the daily sales for each day

ID: 3571840 • Letter: 1

Question

1. Write a Java application that:

asks the user for the daily sales for each day of a week using a repetition loop and calculates its total.

calculates the average daily sales for the week

displays the total and average sales for the week.

Each of the three components of the program should be handled by a different method.

2. A painting company has determined that for every 115 square feet of wall space, one gallon of paint and eight hours of labor will be required. The company charges $18.00 per hour for labor. Write a Java program (from scratch) that allows the user to enter the wall space to be painted and the price of paint per gallon. The program should have methods that return the following data:

The number of gallons of paint required

The cost of the paint

The hours of labor required

The labor charges

The total cost of the paint job

Then it should display the results on the screen.

Explanation / Answer

1)

DailySalesOfAWeek.java

import java.util.Scanner;

public class DailySalesOfAWeek {

   public static void main(String[] args) {
  
       //Creating an array of size 7
   int sales[]=new int[7];
  
   //Calling the method by passing the sales array as argument
   sales=getDailySales(sales);
  
   //Calling the methods
double avg=calAvgSales(sales);
displayResult(sales,avg);
   }

  
   //This method will display the result
   private static void displayResult(int[] sales,double avg) {
      
       double sum=0.0;
       for(int i=0;i<7;i++)
       {
           sum+=sales[i];
       }
      
       //Displaying the total sales in the week
       System.out.println("The Total sales of the week :$"+sum);
      
       //Displaying the average sales in the week
       System.out.printf("The Average Sales of the week :$%.2f",avg);
   }

   //This method will calculate the average sales of the week
   private static double calAvgSales(int[] sales) {
       double average=0.0,sum=0.0;
       for(int i=0;i<7;i++)
       {
           sum+=sales[i];
       }
       average=sum/7;
       return average;
   }

  
   /* This method will get the sales of the week
   * and populate them into an sales array
   */
   private static int[] getDailySales(int[] sales) {
       Scanner sc=new Scanner(System.in);
      
       String week[]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
      
       /* This method will get the sales of each day
       * of the week and populate it into an array
       */
       for(int i=0;i<7;i++)
       {
           System.out.print("Enter sales in "+week[i]+" :$");
           sales[i]=sc.nextInt();
       }
       return sales;
   }

}

__________________________

Output:

Enter sales in Monday :$1700
Enter sales in Tuesday :$1600
Enter sales in Wednesday :$1400
Enter sales in Thursday :$1500
Enter sales in Friday :$1800
Enter sales in Saturday :$1900
Enter sales in Sunday :$2000
The Total sales of the week :$11900.0
The Average Sales of the week :$1700.00

_______________

2)

CostOfPaint.java

import java.util.Scanner;

public class CostOfPaint {

   public static void main(String[] args) {
       //Declaring variables
       int wall_space;
       double price;
      
       //Scanner class object is used to read the inputs entered by the user
   Scanner sc=new Scanner(System.in);
  
   //Getting the wall space
   System.out.print("Enter the wall space (in Sqft):");
   wall_space=sc.nextInt();
  
   //Getting the price of the paint per gallon entered by the user
   System.out.print("Enter the Price of paint (per gallon):$");
   price=sc.nextDouble();
  
   //Calling the methods
   double paint_required=paintReq(wall_space);
   double cost_of_paint=costOfPaint(paint_required,price);
   double hours=hoursOfLabor(wall_space);
   double labor_charges=calLaborCharges(hours);
double tot_cost=totalCost(cost_of_paint,labor_charges);
  
//Displaying the results
System.out.printf(" Paint Required :%.2f Gallons",paint_required);
System.out.printf(" Cost of Paint :$ %.2f",cost_of_paint);
System.out.printf(" Total Hours Of labor :%.2f",hours);
System.out.printf(" Total Labor charges :$ %.2f ",labor_charges);
System.out.printf(" Total cost of Paint Job :$ %.2f ",tot_cost);
   }

   private static double costOfPaint(double paint_required, double price) {
      
       return paint_required*price;
   }

   private static double totalCost(double cost_of_paint, double labor_charges) {
          
       return (cost_of_paint+labor_charges);
   }

   private static double calLaborCharges(double hours) {
      
       return hours*18;
   }

   private static double hoursOfLabor(int wall_space) {
      
       return ((double)wall_space/115)*8;
   }

   private static double paintReq(int wall_space) {
      
       return (double)wall_space/115;
   }

}

____________________

Output:

Enter the wall space (in Sqft):2500
Enter the Price of paint (per gallon):$120

Paint Required :21.74 Gallons
Cost of Paint :$ 2608.70
Total Hours Of labor :173.91
Total Labor charges :$ 3130.43
Total cost of Paint Job :$ 5739.13

_____________Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote