please need this java program done with good programming sty
please need this java program done with good programming style and comments ASAP!
Solution
package example;
import com.sun.corba.se.impl.io.TypeMismatchException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.List;
/**
*
* @author Rashmi Tiwari
*/
interface Retail{
double retailCost(); //Retail cost of item before tax
double averageCost(); //Average cost of an item before tax
double totalCost(); //total cost of all items after tax
int totalItems(); //numbersof items in bag
}
class ShoppingFlag implements Retail{
private int numberOfItems; //Quantity of Items
private double taxRate; //Tax Rate
private double retailCost; //Retail Cost
private double averageCost; //Average cost
private double totalCost; //Total Cost
private String itemName; //Item Name
private static double total; //Total varaible to find sum of all the items cost
private static int count=0; //Number of items
ShoppingFlag(double taxRate){ //Constructor as Tax Rate argument
this.taxRate=taxRate;
}
public int getNumberOfItems() { //Getter setter for Variables
return numberOfItems;
}
public void setNumberOfItems(int numberOfItems) {
this.numberOfItems = numberOfItems;
}
public double getRetailCost() {
return retailCost;
}
public void setRetailCost(double retailCost) {
this.retailCost = retailCost;
}
public String getItemName() {
return itemName;
}
public void setItemName(String itemName) {
this.itemName = itemName;
}
void buy(int numberOfItems,double retailCost){
this.numberOfItems=numberOfItems;
this.retailCost=retailCost;
}
public String toString(){ //Overirding of ToString method for Print Object\'s Value
return \"Items: \"+numberOfItems+\"\ Retail Cost: \"+retailCost()+\"\ Average Items Cost:\"+averageCost()+\"\ Total Cost including tax (\"+taxRate+\"):\"+totalCost();
}
@Override
public double retailCost() {
return retailCost;
}
@Override
public double averageCost() {
return total/count;
}
@Override
public double totalCost() {
return ((taxRate*total)/100)+total;
}
@Override
public int totalItems() {
return numberOfItems;
}
public static void main(String args[]){
ShoppingFlag item = new ShoppingFlag(7);
try {
List<String> items = Files.readAllLines(java.nio.file.Paths.get(\"./items.txt\"), StandardCharsets.UTF_8); //Reading values from File
for (String i: items){
String[] tokens = i.split(\" \");//Read all values in a line seperated by space
item.setItemName(tokens[0]);
item.setNumberOfItems(Integer.parseInt(tokens[1])); //conversion of string to int
item.setRetailCost(Double.parseDouble(tokens[2])); //conversion of sting to double
total+=Double.parseDouble(tokens[2]);
count++;
}
System.out.println(item.toString());
}catch (TypeMismatchException e) { //exception handing if data comes in wrong format
e.printStackTrace();
}
catch (IOException e) { //exception handing if checked exception is there
e.printStackTrace();
}
}
}


