Hi Leute.
Ich habe die Aufgabe (im Anhang) und da hänge ich etwas im unteren Schritt mit "Ergänzen Sie nun eine öffentliche Klassenmethode createProductFrom(). Diese soll die übergebenen Parameter in das bereits erstellte Projekt p speichern."
Ich habe erstmal wie in den Schritten davor mehrere private Variablen in meiner Klasse gesetzt etc und habe für diese auch alle Getters und Setters generiert (über Java)
Nun weiß ich nicht, ob ich diese Klassenmethode "createProductFrom()" in "Product" machen soll oder in der Klasse "ProductManager".
Ich denke auch mal in meiner Klasse "Product" ,oder?
Aber wie kann ich denn Klassenübergreifend speichern? Also ich nehme mal an, der möchte, dass ich die Sachen von "Name" "description" "price" etc in p speichere, oder?
Aber ich habe ehrlich gesagt keine Ahnung wie... Jemand einen Ratschlag?
Hier meine Klasse "Product" :
Und meine Klasse "ProductManager"
Ich habe die Aufgabe (im Anhang) und da hänge ich etwas im unteren Schritt mit "Ergänzen Sie nun eine öffentliche Klassenmethode createProductFrom(). Diese soll die übergebenen Parameter in das bereits erstellte Projekt p speichern."
Ich habe erstmal wie in den Schritten davor mehrere private Variablen in meiner Klasse gesetzt etc und habe für diese auch alle Getters und Setters generiert (über Java)
Nun weiß ich nicht, ob ich diese Klassenmethode "createProductFrom()" in "Product" machen soll oder in der Klasse "ProductManager".
Ich denke auch mal in meiner Klasse "Product" ,oder?
Aber wie kann ich denn Klassenübergreifend speichern? Also ich nehme mal an, der möchte, dass ich die Sachen von "Name" "description" "price" etc in p speichere, oder?
Aber ich habe ehrlich gesagt keine Ahnung wie... Jemand einen Ratschlag?
Hier meine Klasse "Product" :
Java:
class Product {
//Instanzvariablen
private String name;
private String description;
private double price ;
private int id;
private int nextId;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getNextId() {
return nextId;
}
public void setNextId(int nextId) {
this.nextId = nextId;
}
public void createProductFrom() {
}
}
Und meine Klasse "ProductManager"
Java:
import Prog1Tools.IOTools;
public class ProductManager {
public static final int LIST = 0;
public static final int REGISTER = 1;
public static final int ADJUST_STOCK = 2;
public static final int EXIT = 3;
/**
* Provides a command line interface to interact with the product management system for an online shop
* @param args
*/
public static void main(String[] args) {
Warehouse warehouse = new Warehouse();
warehouse.registerProducts(Warehouse.preloadInitialDataSet());
System.out.println("Welcome to the online shop product management");
boolean running = true;
while (running) {
System.out.println("Please, enter one of the following commands:"
+ "\n0 to list all products"
+ "\n1 to register a new product"
+ "\n2 to adjust stock levels" + "\n3 to exit.");
int command = IOTools.readInt();
switch (command) {
case LIST :
warehouse.printInventory();
break;
case REGISTER :
Product p = Product.createProductFromUserinput();
warehouse.registerProducts(p);
System.out.println("The following product has been added to the catalog:\n"
+ p.toString());
break;
case ADJUST_STOCK :
int id = IOTools.readInt("Please, enter product id:");
int stock = IOTools.readInt("Please, enter new stock level:");
warehouse.setStockForProductById(id, stock);
break;
case EXIT :
running = false;
break;
default :
System.out.println("Unknown command: " + command);
break;
}
}
System.out.println("Byebye!");
}
}