I have made an application in java to manage and use a washing machine with the following requirements :
"1. There must be the possibility to create different garments. In the constructor of a garment, a type, a weight and a name must be given.
2. There must be a class of washing machine that can do the following:
There must be a function to turn the washing machine on and off
There must be a function to start the washing machine with the selected program (Fast, Delicate, Cotton, Eco, Warm), temperature and washing time as argument.
There must be a function to add items of clothing to the washing machine. This function returns true if successful. Please note the following:
If the washing machine is on, no item of clothing may be added and false will be returned.
The washing machine has a capacity that is set via the constructor. The capacity of the washing machine may not be exceeded and then false is returned.
The same item of clothing cannot be added more than once.
There must be a function to remove clothes from the washing machine.
There must be a function to make the washing machine available again. The washing machine is emptied and turned off.
3. There must be a class to manage multiple washing machines
In this class there must be a function to add, view and delete washing machines.
There should also be a function in this class to request to use a washing machine. The input for this function is the weight of the clothes you wish to wash. A washing machine is then selected that is switched off and has sufficient capacity.
Now I want to turn it into a javafx application. For that I need an interface (fxml code ) , ee, main controller and adapted class. Can you make this and give it to me. Here is the original command code to change to javafx :
Here is main.java : public class Main {
public static void main(String[] args) {
// Voorbeeldgebruik van de classes
// Maak een nieuwe wasmachine aan met capaciteit van 10 kg
WashingMachine washingMachine1 = new WashingMachine(10);
// Zet de wasmachine aan
washingMachine1.turnOn();
// Voeg kledingsstukken toe aan de wasmachine
ClothingItem item1 = new ClothingItem("T-shirt", 0.2, "Shirt 1");
boolean added = washingMachine1.addClothingItem(item1);
if (added) {
System.out.println("Item toegevoegd aan de wasmachine.");
} else {
System.out.println("Kan item niet toevoegen aan de wasmachine.");
}
// Start de wasmachine met het Katoen programma, temperatuur 40°C en duur van 60 minuten
boolean started = washingMachine1.start(WashProgram.KATOEN, 40, 60);
if (started) {
System.out.println("Wasmachine gestart.");
} else {
System.out.println("Kan de wasmachine niet starten.");
}
// Verwijder een kledingsstuk uit de wasmachine
boolean removed = washingMachine1.removeClothingItem(item1);
if (removed) {
System.out.println("Item verwijderd uit de wasmachine.");
} else {
System.out.println("Kan item niet verwijderen uit de wasmachine.");
}
// Zet de wasmachine uit en maak deze leeg
washingMachine1.turnOff();
washingMachine1.finish();
Assistant
// Maak een wasmachinebeheerder aan
WashingMachineManager manager = new WashingMachineManager();
// Voeg de wasmachine toe aan de beheerder
manager.addWashingMachine(washingMachine1);
// Vraag een beschikbare wasmachine op voor kleding met een gewicht van 5 kg
WashingMachine availableMachine = manager.getAvailableWashingMachine(5);
if (availableMachine != null) {
System.out.println("Beschikbare wasmachine gevonden.");
// Doe hier verdere verwerking met de beschikbare wasmachine
} else {
System.out.println("Geen beschikbare wasmachine gevonden.");
}
}
} Here is classe ClotihingItem.java : public class ClothingItem {
private String type;
private double weight;
private String name;
public boolean removeClothingItem(ClothingItem item) {
if (!on || inUse) {
return false;
}
return clothingItems.remove(item);
}
public void finish() {
this.inUse = false;
this.clothingItems.clear();
}
public double getLoad() {
double load = 0;
for (ClothingItem item : clothingItems) {
load += item.getWeight();
}
return load;
}
public int getCapacity() {
return capacity;
}
} Here is classe WashingMachineManager.java : import java.util.ArrayList;
import java.util.List;
class WashingMachineManager {
private List washingMachines;
public WashingMachineManager() {
this.washingMachines = new ArrayList<>();
}
public void addWashingMachine(WashingMachine washingMachine) {
washingMachines.add(washingMachine);
}
public void removeWashingMachine(WashingMachine washingMachine) {
washingMachines.remove(washingMachine);
}
public WashingMachine getAvailableWashingMachine(double weight) {
for (WashingMachine machine : washingMachines) {
if (!machine.isOn() && machine.getLoad() == 0 && weight <= machine.getCapacity()) {
return machine;
}
}
return null;
}
} Here is classe kledingsstuk.java : public class kledingsstuk {
private String type;
private double weight;
private String name;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/main.fxml"));
primaryStage.setTitle("Washing Machine Manager");
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Add the following imports to the WashingMachine.java and WashingMachineManager.java classes:
import java.io.Serializable;
Now you have a basic JavaFX application for the Washing Machine Manager. The application allows you to input a weight and find an available washing machine that has enough capacity for that weight. You can further enhance the interface to manage washing machines and perform other operations. Note that you might need to adjust imports and package names based on your project setup.