small fixes
This commit is contained in:
parent
12ab19b864
commit
8548cf0acc
@ -1,20 +1,18 @@
|
||||
package dev.ksan.travelpathoptimizer.app;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import dev.ksan.travelpathoptimizer.util.TicketPrinter;
|
||||
import java.io.IOException;
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class TravelPathOptimizerApplication extends Application {
|
||||
@Override
|
||||
public void start(Stage stage) throws IOException {
|
||||
TicketPrinter.loadCounter();
|
||||
System.out.println(TicketPrinter.getTotalProfit() + " " + TicketPrinter.getTicketsSoldNum());
|
||||
FXMLLoader fxmlLoader =
|
||||
new FXMLLoader(TravelPathOptimizerApplication.class.getResource("main.fxml"));
|
||||
|
||||
@ -33,4 +31,3 @@ public class TravelPathOptimizerApplication extends Application {
|
||||
launch();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import java.util.List;
|
||||
public class TicketPrinter {
|
||||
private static final String COUNTER_FILE = "ticket_counter.txt";
|
||||
private static final String RECEIPTS_DIRECTORY = "receipts";
|
||||
private static final double totalProfit = 0.0;
|
||||
private static double totalProfit = 0.0;
|
||||
private static int ticketIdCounter = 0;
|
||||
|
||||
public static void generateTicketReceipt(List<Departure> departures, double totalPrice) {
|
||||
@ -44,7 +44,7 @@ public class TicketPrinter {
|
||||
|
||||
receipt.append("-----------------------------------------------------\n");
|
||||
receipt.append("Total Price: $").append(String.format("%.2f", totalPrice)).append("\n");
|
||||
|
||||
totalProfit += totalPrice;
|
||||
receipt.append("=====================================================\n");
|
||||
receipt.append("Thank you for choosing our service!\n");
|
||||
folderExists();
|
||||
@ -78,20 +78,40 @@ public class TicketPrinter {
|
||||
try {
|
||||
Path path = Paths.get(COUNTER_FILE);
|
||||
if (Files.exists(path)) {
|
||||
String counter = new String(Files.readAllBytes(path)).trim();
|
||||
ticketIdCounter = Integer.parseInt(counter);
|
||||
List<String> lines = Files.readAllLines(path);
|
||||
|
||||
for (String line : lines) {
|
||||
String[] parts = line.split("=");
|
||||
if ("ticketIdCounter".equals(parts[0].trim())) {
|
||||
ticketIdCounter = Integer.parseInt(parts[1].trim());
|
||||
} else if ("totalProfit".equals(parts[0].trim())) {
|
||||
totalProfit = Double.parseDouble(parts[1].trim());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ticketIdCounter = 0;
|
||||
totalProfit = 0.0;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
ticketIdCounter = 0;
|
||||
totalProfit = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
public static double getTotalProfit() {
|
||||
return totalProfit;
|
||||
}
|
||||
|
||||
public static int getTicketsSoldNum() {
|
||||
return ticketIdCounter;
|
||||
}
|
||||
|
||||
private static void saveCounter() {
|
||||
try {
|
||||
Files.write(Paths.get(COUNTER_FILE), String.valueOf(ticketIdCounter).getBytes());
|
||||
String str = "ticketIdCounter=" + ticketIdCounter + "\n" + "totalProfit=" + totalProfit;
|
||||
Files.write(Paths.get(COUNTER_FILE), str.getBytes());
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user