I am working on writing a program that reads inventory items from a file and adds a markup charge. I am assuming each line will be correct and not using any validation. However, I am building the program on the format of each line HOPEFULLY being: name quantity cost markup.
The cost is the wholesale cost the company paid for the item(per each). The markup is a number between 1 and 100 which indicates the percentage of the markup to determine the retail cost. I'm trying to Output all input data to a file, along with the price, the value of the items wholesale (quantity * cost), the value of the items retail (quantity * price). All currencies should be rounded to two decimals on output (printf). The file should be nicely formatted in tabular form using printf statements for output, and include a title row.
Currently, I am trying to determine the retail price using a value-returning method and it seems as if I'm missing something? I'm not understanding why even after outFile.print(Sect[0] + " " + Sect[1]); nothing prints to the output file?
(MY FULL CODE}
package pray;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Doitgoooo {
public static void main(String[] args) throws FileNotFoundException {
int Quantity;
double Cost, Markup, FinCost=0;
String Line, item1, item2, item3, item4;
String[] Sect;
Scanner inFile;
PrintWriter outFile;
System.out.println("(Basic) Inventory Program Starting. Opening file...");
System.out.println("Please ensure data is entered per line in the format of: 'Name Quantity Cost Markup' ");
inFile = new Scanner(new File("input.txt"));
outFile = new PrintWriter(new File("output.txt"));
while(inFile.hasNext()){
Line = inFile.nextLine();
Sect = Line.split(" ");
if(Sect.length == 4) {
item1 = Sect[0];
item2 = Sect[1];
item3 = Sect[2];
item4 = Sect[3];
Quantity = (int) Double.parseDouble(item2);
Cost = Double.parseDouble(item3);
Markup = Double.parseDouble(item4);
double Value = Quantity * Cost;
double ValueMarkup = Quantity * FinCost;
outFile.print(Sect[0] + " " + Sect[1]);
outFile.printf(" %.2f %.2f %.2f %.2f %.2f", Cost, Markup, FinCost, Value, ValueMarkup);
}
else {
outFile.println("Line did not have 4 item(s)");
}
}
}
private void CalculateRetail(double Cost, double Markup) {
double MarkPerct = Markup/100;
double MarkAdd = MarkPerct * Cost;
double FinCost = MarkAdd + Cost;
}
}
Aucun commentaire:
Enregistrer un commentaire