Netbeans Java Write a java program to create customers bill

Netbeans Java

Write a java program to create customer’s bill for a company. The company sells only five types of products: TV, VCR, CD Player, IPod, and Remote Control. The sales for each type of product for the current week are: $12500.55, $2250.00, $2350.00, $1450.50, and $29.95, respectively.

Write a class called Sales. Convince yourself that this class requires two types of variables – instance variables, and class variables. Write appropriate constructor that accepts the name of each product and its associated sales amount for the current week. Provide instance methods to return the value for each instance variable named; also, provide class methods for each class variable used.

Dont need a test class

Solution

/** * @author * @fileName Sales.java * @since 16/2/17 */ import java.util.ArrayList; public class Sales { /** * class variable */ private static int currentWeekNUmber; private static ArrayList listOfSales = new ArrayList<>(); /** * instance variable */ private String productName; private double price; /** * This is instance method * @param productName * @param price */ public Sales(String productName, double price) { this.productName = productName; this.price = price; listOfSales.add(this); } /** * This is class method * @return */ public static int getCurrentWeekNumber() { return currentWeekNUmber; } /** * This is class method * @return */ public static void setCurrentWeekNumber(int weekNumber) { currentWeekNUmber = weekNumber; } /** * This class method */ public static void bill() { double total = 0.0; System.out.println(\"Week Number:\" + currentWeekNUmber); for (Sales s : listOfSales) { System.out.println(String.format(\"%-10s$%-10.2f\", s.productName, s.price)); } } /*** * Thsi is class method * @return */ public static ArrayList getListOfSales() { return listOfSales; } /** * * This is also instance method * @return */ public String getProductName() { return productName; } }
Netbeans Java Write a java program to create customer’s bill for a company. The company sells only five types of products: TV, VCR, CD Player, IPod, and Remote

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site