The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
You have been tasked with creating an application that accepts product data and displays this information. The application also computes average sales and shipping charges. Using appropriate control structures, enhance your product class to include the 2 new methods designed in an earlier task.
The computeAverageSales() method should use sentinel-controlled repetition to allow a user to enter product sales data until the user has indicated that he or she is done. The average of the entered sales data will be computed and returned by the method to be displayed by the application. For example, if the user entered 500.50, 250.50, and 300.30, then the average sales would be computed for these 3 values and returned by the method. The prompting of the sales data is done within the method. If the value of the average sales exceeds $200.00, a message should be displayed to alert the user that the product has produced a significant amount of revenue. The computeAverageSales() method should return type "double."
The computeShippingCharges() method should use sentinel-controlled repetition, to allow a user to enter shipping data until the user has indicated that he or she is done. The total shipping charges will be computed and returned as a double value.
Modify your application to call the computeAverageSales() and computeShippingCharges() methods.
As a result of these modifications, the following requirements should be met:
Your code should be well commented. Use the following steps to guide your work:
Â
/**
* ProductCategory Class
*/
public class ProductCategory {
String categoryName;
int productsInStock;
double averagePrice;
/**
* Constructor
*/
public ProductCategory(String cat, int products, double price) {
categoryName = cat;
productsInStock = products;
averagePrice = price;
}
/**
* returns the name of category
* */
public String getCategoryName() {
return categoryName;
}
/**
* returns the products in stock
* */
public int getProductsInStock() {
return productsInStock;
}
/**
* returns the average price
* */
public double getAveragePrice() {
return averagePrice;
}
/**
* sets the name of category
* */
public void setCategoryName(String cat) {
categoryName = cat;
}
/**
* sets products in stock
* */
public void setProductsInStock(int products){
productsInStock = products;
}
/**
* sets average price
* */
public void setAveragePrice(double price){
averagePrice = price;
}
}
import java.util.Scanner;
/**
* ProductCategoryTest class
* */
public class ProductCategoryTest {
public static void main(String args) {
Scanner input = new Scanner(System.in);
String categoryName;
int productsInStock;
double averagePrice;
// prompt and read category name
System.out.print("Enter the name of category: ");
categoryName = input.nextLine();
// prompt and read products in stock
System.out.print("Enter the products in the category: ");
productsInStock = input.nextInt();
// prompt and read average price
System.out.print("Enter the average price of products: ");
averagePrice = input.nextDouble();
// create ProductCategory object
ProductCategory objProductCategory = new
ProductCategory(categoryName, productsInStock, averagePrice);
// display the details using getters of the class
System.out.println("\nCategory Name: " +
objProductCategory.getCategoryName());
System.out.println("Products in Stock: " +
objProductCategory.getProductsInStock());
System.out.println("Average price of products: " +
objProductCategory.getAveragePrice());
}
}
-----------