Created
November 28, 2018 18:53
-
-
Save D3strukt0r/4633fb9ac74cb05833857ed7b03d60bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LanguagesString { | |
private String en; | |
private String de; | |
public String getEn() { | |
return en; | |
} | |
public LanguagesString setEn(String en) { | |
this.en = en; | |
return this; | |
} | |
public String getDe() { | |
return de; | |
} | |
public LanguagesString setDe(String de) { | |
this.de = de; | |
return this; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Product { | |
private LanguagesString name; | |
private LanguagesString description; | |
private int number; | |
private double price; | |
public Product(LanguagesString name, LanguagesString description, int number, double price) { | |
this.name = name; | |
this.description = description; | |
this.number = number; | |
this.price = price; | |
} | |
// Return the languageString | |
public LanguagesString getName() { | |
return name; | |
} | |
// Return the language specific string | |
public String getName(String language) { | |
if (language.equals("en")) { | |
return name.getEn(); | |
} else if (language.equals("de")) { | |
return name.getDe(); | |
} | |
return ""; | |
} | |
public void setName(LanguagesString name) { | |
this.name = name; | |
} | |
// Return the languageString | |
public LanguagesString getDescription() { | |
return description; | |
} | |
// Return the language specific string | |
public String getDescription(String language) { | |
if (language.equals("en")) { | |
return description.getEn(); | |
} else if (language.equals("de")) { | |
return description.getDe(); | |
} | |
return ""; | |
} | |
public void setDescription(LanguagesString description) { | |
this.description = description; | |
} | |
public double getPrice() { | |
return price; | |
} | |
public void setPrice(double price) { | |
this.price = price; | |
} | |
public int getNumber() { | |
return number; | |
} | |
public void setNumber(int number) { | |
this.number = number; | |
} | |
public String toString(String language) { | |
return "Product-Nr.:" + getNumber() + "\n" + | |
"Name: " + getName(language) + | |
"\nDescription: " + getDescription(language) + | |
"\nPrice: " + getPrice() + "\n"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Iterator; | |
import java.util.Scanner; | |
public class Shop { | |
public static void main(String[] args) { | |
// Create the products list | |
ArrayList<Product> productList = new ArrayList<>(); | |
// Create and add product 1 | |
LanguagesString n1 = new LanguagesString() | |
.setEn("RAM") | |
.setDe("RAM"); | |
LanguagesString d1 = new LanguagesString() | |
.setEn("Storage for your PC") | |
.setDe("Speicher für dein PC"); | |
Product p1 = new Product(n1, d1, 1, 199.99); | |
productList.add(p1); | |
// Create and add product 2 | |
LanguagesString n2 = new LanguagesString() | |
.setEn("CPU") | |
.setDe("Prozessor"); | |
LanguagesString d2 = new LanguagesString() | |
.setEn("The brain of your computer") | |
.setDe("Das Gehirn deines Computers"); | |
Product p2 = new Product(n2, d2, 2, 199.99); | |
productList.add(p2); | |
// What language does the user want? | |
// Print all the products | |
// Go through all the products and print each one | |
// Select product to buy | |
// If no command has been set, or the command is "pay" than skip | |
// End the loop if user entered "pay" | |
// Get product id and add to cart | |
// Check whether it can be translated into an integer | |
// Check whether the product exists and add it to the shopping cart | |
// Check whether cart is empty or not | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment