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

PLEASE ANSWER THIS QUESTION USING JAVA Let’s think that Company XYZ produces t-s

ID: 3754289 • Letter: P

Question

PLEASE ANSWER THIS QUESTION USING JAVA

Let’s think that Company XYZ produces t-shirts. Develop a Java application that will input sales revenue and total number products sold (both as integers) for each year.

The program should calculate, and display selling price of product for each year and print the combined selling price of product (total sales revenue for all years/total number of products sold for all years) for all years up to this point.

All calculations should produce floating-point results.

Use class Scanner and sentinel-controlled iteration to obtain the data from user.

Explanation / Answer


import java.util.Scanner;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Vamsi
*/
public class product {
public static void main(String argv[])
{
//variable declaration
double revenue;//to store yearly revenue
double sold;//to store the number of products sold
String year;///to store year
double price;//to store price of each product in a year
double total_r=0;//to store total revenue of all years
double total_s=0;//to store total number of products sold in all years
double total;//to store combined selling price of product of all years
  
  
  
int flag=1;//sentinal value
  
//declaring scanner object
Scanner sc = new Scanner(System.in);
  
while(flag!=0)
{
//reading input
System.out.print("Enter year:");
year = sc.next();
  
System.out.print("Enter revenue:");
revenue = sc.nextDouble();
  
System.out.print("Enter Number of products:");
sold = sc.nextDouble();
  
//calculating each product value
price = revenue/sold;
  
//displaying output
System.out.println(" Selling price per product in year "+year+ " is:"+price);
  
//adding revenue to total revenue
total_r +=revenue;
  
//adding number of proudcts to total number of products sold
total_s +=sold;
  
System.out.print("Enter 0 to exit| 1 to continue:");
flag = sc.nextInt();//reading flag
  
  
  
}
//calculating combined selling price of product
total = total_r/total_s;
  
//displaying output
System.out.println("combined selling price of product :"+total);
}
  
  
  
//if you have any doubt in understanding, pls comment
//pls pls give a thumbsup, if you find this helpful
//it really helps alot, thanks
  
}

output:

run:
Enter year:2013
Enter revenue:20
Enter Number of products:10

Selling price per product in year 2013 is:2.0
Enter 0 to exit| 1 to continue:1
Enter year:2014
Enter revenue:40
Enter Number of products:10

Selling price per product in year 2014 is:4.0
Enter 0 to exit| 1 to continue:1
Enter year:2015
Enter revenue:50
Enter Number of products:15

Selling price per product in year 2015 is:3.3333333333333335
Enter 0 to exit| 1 to continue:0
combined selling price of product :3.142857142857143
BUILD SUCCESSFUL (total time: 1 minute 22 seconds)

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