Ich habe keine Idee, wie Array Enum hinzuzufügen. Ich habe einen Konstruktor gemacht, der Felder mit enum und seinen Funktionen verwendet, aber ich weiß nicht, wie man es im Konstruktor ohne Feld machen kann. Ich hoffe, du verstehst, worüber ich nachdenke. In meinem Code kommentiere ich wo ich denke ich habe ein Problem. Ich habe:Wie kann ich Konstruktor ohne Felder mit enum machen?
public enum Components {
WIFI, BLUETOOTH, CAMERA, SSD
}
public Laptop(){
System.out.println("name of producer:");
String producername = Main.sc.nextLine();
System.out.println("name of model:");
String modelname = Main.sc.nextLine();
System.out.println("ram:");
int ram = Main.sc.nextInt();
System.out.println("cpu:");
String cpu = Main.sc.nextLine();
cpu = Main.sc.nextLine();
System.out.println("components:");
System.out.println("how many components do you want to add?");
int z = Main.sc.nextInt();
Components[] com = new Components[z];
for(int i=0; i<com.length;i++){
com[i] = //<-- how to add enum in array?
}
setProducerName(producername);
setModelName(modelname);
setRam(ram);
setCpu(cpu);
setComponents(com);
}
Mein Konstruktor Feld wie die Verwendung ist und es funktioniert.
public Laptop(String ProducerName, String ModelName, int Ram, String Cpu, Components... components) {
super();
this.ProducerName= ProducerName;
this.ModelName= ModelName;
this.Ram= Ram;
this.Cpu= Cpu;
this.components= new Components[components.length];
this.components= Arrays.copyOf(components, components.length);
}
Bitte helfen.