Java Code drüberlesen - sieht das richtig aus?

Diskutiere Java Code drüberlesen - sieht das richtig aus? im Hausaufgaben Bereich.
O

OracleBoy

Hallo, sieht das so richtig aus, bin etwas überfragt...


public class MainView extends HBox{

private TableView<Console> tableViewConsole = new TableView<>();
private TableView<VideoGame> tableViewVideoGame = new TableView<>();

private Storage<Console> consoleStorage = new Storage<Console>(10);
private Storage<VideoGame> videoGameStorage = new Storage<VideoGame>(Integer.MAX_VALUE);

private BorderPane borderPaneLeft = new BorderPane();
private VBox vBoxVideoGame = new VBox();
private VBox vBoxConsole = new VBox();
private HBox buttonHBox = new HBox();

private Button buyButton = new Button("Kaufen");
private Button sellButton = new Button("Verkaufen");

private ComboBox<Manufacturer> comboBoxManufacturer = new ComboBox<>(FXCollections.observableArrayList(Manufacturer.values()));
private ComboBox<Genre> comboBoxGenre = new ComboBox<>(FXCollections.observableArrayList(Genre.values()));
private ComboBox<String> comboBoxSelect = new ComboBox<>(FXCollections.observableArrayList("Konsole","Videospiel"));

private TextField videoGameNameTextField = new TextField();
private TextField ageRestrictionTextField = new TextField();
private TextField consoleNameTextField = new TextField();

public MainView() {
createView();
setProperties();
createConsoleTableView();
createVideoGameTableView();
handleActions();
}

private void createView() {
this.getChildren().addAll(this.borderPaneLeft, this.tableViewConsole);
this.vBoxVideoGame.getChildren().addAll(this.videoGameNameTextField, this.comboBoxGenre, this.ageRestrictionTextField);
this.vBoxConsole.getChildren().addAll(this.consoleNameTextField, this.comboBoxManufacturer);
this.buttonHBox.getChildren().addAll(this.buyButton,this.sellButton);
this.borderPaneLeft.setTop(this.comboBoxSelect);
this.borderPaneLeft.setBottom(this.buttonHBox);
}

private void setProperties() {
this.videoGameNameTextField.setPromptText("Name");
this.ageRestrictionTextField.setPromptText("Altersbeschränkung");
this.consoleNameTextField.setPromptText("Name");
}

private void handleActions() {
this.comboBoxSelect.setOnAction(e -> {
this.getChildren().removeAll(this.tableViewConsole,this.tableViewVideoGame);
switch (this.comboBoxSelect.getValue()) {
case "Videospiel":
this.borderPaneLeft.setCenter(this.vBoxVideoGame);
this.getChildren().add(this.tableViewVideoGame);
break;
case "Konsole":
this.borderPaneLeft.setCenter(this.vBoxConsole);
this.getChildren().add(this.tableViewConsole);
break;
default:
this.borderPaneLeft.setCenter(null);
break;
}

});

this.buyButton.setOnAction(e -> {
switch (this.comboBoxSelect.getValue()) {
case "Videospiel":
if(this.comboBoxGenre.getValue()==null) {
VideoGame videoGame = new VideoGame(this.videoGameNameTextField.getText(), Integer.parseInt(this.ageRestrictionTextField.getText()));
this.videoGameStorage.addToStorage(videoGame);
break;
} else {
VideoGame videoGame = new VideoGame(this.videoGameNameTextField.getText(), Integer.parseInt(this.ageRestrictionTextField.getText()), this.comboBoxGenre.getValue());
this.videoGameStorage.addToStorage(videoGame);
break;
}
case "Konsole":
Console console = new Console(this.consoleNameTextField.getText(), this.comboBoxManufacturer.getValue());
this.consoleStorage.addToStorage(console);
break;
default:
break;
}
});

this.sellButton.setOnAction(e -> {
switch (this.comboBoxSelect.getValue()) {
case "Videospiel":
this.videoGameStorage.removeItemFromStorage(this.tableViewVideoGame.getSelectionModel().getSelectedItem());
break;
case "Konsole":
this.consoleStorage.removeItemFromStorage(this.tableViewConsole.getSelectionModel().getSelectedItem());
break;
default:
break;
}
});
}

private void createVideoGameTableView() {
TableColumn<VideoGame,Integer> idColumnVideoGame = new TableColumn<>("ID: ");
idColumnVideoGame.setCellValueFactory(new PropertyValueFactory<>("id"));

TableColumn<VideoGame,String> nameColumnVideoGame = new TableColumn<>("Name: ");
nameColumnVideoGame.setCellValueFactory(new PropertyValueFactory<>("name"));

TableColumn<VideoGame,Genre> genreColumn = new TableColumn<>("Genre: ");
genreColumn.setCellValueFactory(new PropertyValueFactory<>("genre"));

TableColumn<VideoGame, Integer> ageRestrictionColumn = new TableColumn<>("Altersbeschränkung");
ageRestrictionColumn.setCellValueFactory(new PropertyValueFactory<>("ageRestriction"));

this.tableViewVideoGame.getColumns().addAll(idColumnVideoGame,nameColumnVideoGame,genreColumn,ageRestrictionColumn);
this.tableViewVideoGame.setItems(this.videoGameStorage.getStorageElements());
}

private void createConsoleTableView() {
TableColumn<Console, Integer> idColumnConsole = new TableColumn<>("ID: ");
idColumnConsole.setCellValueFactory(new PropertyValueFactory<>("id"));

TableColumn<Console,String> nameColumnConsole = new TableColumn<>("Name: ");
nameColumnConsole.setCellValueFactory(new PropertyValueFactory<>("name"));

TableColumn<Console,Manufacturer> manufacturerConsole = new TableColumn<>("Hersteller: ");
manufacturerConsole.setCellValueFactory(new PropertyValueFactory<>("manufacturer"));

this.tableViewConsole.getColumns().addAll(idColumnConsole, nameColumnConsole, manufacturerConsole);
this.tableViewConsole.setItems(this.consoleStorage.getStorageElements());
}
}

////////////////////////////////////////////////////////////////////////////////////////////

public class Article {

private String name;
private int id;
private static int counter = 0;



public Article(String name) {
super();
this.name = name;
this.id = counter++;
}

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public int getId() {
return this.id;
}

public void setId(int id) {
this.id = id;
}

}

//////////////////////////////////////////////////////////////////////////////////////////

public class Console extends Article {

private Manufacturer manufacturer;

public Console(String name, Manufacturer manufacturer) {
super(name);
this.manufacturer = manufacturer;
}

public Manufacturer getManufacturer() {
return this.manufacturer;
}

public void setManufacturer(Manufacturer manufacturer) {
this.manufacturer = manufacturer;
}


}

///////////////////////////////////////////////////////////////////////////////////////////

public class VideoGame extends Article {

private int ageRestriction;
private Genre genre;

public VideoGame(String name, int ageRestriction, Genre genre) {
super(name);
this.ageRestriction = ageRestriction;
this.genre = genre;
}

public VideoGame(String name, int ageRestriction) {
super(name);
this.ageRestriction = ageRestriction;
this.genre = this.genre.ACTION;
}

public int getAgeRestriction() {
return this.ageRestriction;
}

public void setAgeRestriction(int ageRestriction) {
this.ageRestriction = ageRestriction;
}

public Genre getGenre() {
return this.genre;
}

public void setGenre(Genre genre) {
this.genre = genre;
}


}

///////////////////////////////////////////////////////////////////////////////////////

public class Storage<T extends Article> {

private ObservableList<T> storageElements = FXCollections.observableArrayList();
private int maxCapacity;

public Storage(int maxCapacity) {
this.maxCapacity = maxCapacity;
}

public ObservableList<T> getStorageElements() {
return this.storageElements;
}

public void addToStorage(T article) {
if (this.maxCapacity > this.storageElements.size()) {
this.storageElements.add(article);
}
}

public void removeItemFromStorage(T article) {
this.storageElements.remove(article);
}



}

///////////////////////////////////////////////////////////////////////////////////////

public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
MainView root = new MainView();
Scene scene = new Scene(root,700,700);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
launch(args);
}
}
//////
Neue Java-Datei
------------------

package application;

import javafx.collections.FXCollections;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBase;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Control;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import pokemon.PokeDex;
import pokemon.Type;

public class GUI {
private Scene scene;
private VBox root = new VBox();
private HBox hBox = new HBox();
private Label pkmFound = new Label();
private TextField searchName = new TextField();
private ChoiceBox<Type> firstTypeBox = new ChoiceBox<>(FXCollections.observableArrayList(Type.values()));
private ChoiceBox<Type> secondTypeBox = new ChoiceBox<>(FXCollections.observableArrayList(Type.values()));
private ComboBox<String> choiceBox = new ComboBox<>(FXCollections.observableArrayList("", "Total", "HP", "Attack",
"Defense", "Special Attack", "Special Defense", "Speed"));
private ComboBox<String> choiceBox2 = new ComboBox<>(FXCollections.observableArrayList("", "<", ">", "="));
private TextField searchValue = new TextField();
private PokeDex pokeDex;

public void start(Stage stage) {
pokeDex = new PokeDex(stage, pkmFound);
stage.setTitle("PokeDex");
editBoxesAndFields();
hBox.getChildren().addAll(searchName, firstTypeBox, secondTypeBox, choiceBox, choiceBox2, searchValue);
root.getChildren().addAll(hBox, pkmFound, pokeDex.getPokeDex());
scene = new Scene(root, 890, 1000);
stage.setScene(scene);
stage.setResizable(false);
stage.show();
actionHandling();
}
private void actionHandling() {
searchName.setOnKeyReleased(event -> filter());
firstTypeBox.setOnAction(event -> filter());
secondTypeBox.setOnAction(event -> filter());
choiceBox.setOnAction(event -> filter());
choiceBox2.setOnAction(event -> filter());
searchValue.setOnKeyReleased(event -> filter());

}
private void filter() {
pokeDex.filterPokemon(searchName.getText(),
firstTypeBox.getValue().toString(), secondTypeBox.getValue().toString(), choiceBox.getValue(),
choiceBox2.getValue(), searchValue.getText());
}
private void editBoxesAndFields() {
searchName.setPromptText("Name");
searchValue.setPromptText("Wert");
firstTypeBox.setValue(Type.NONE);
secondTypeBox.setValue(Type.NONE);
choiceBox.setValue("");
choiceBox2.setValue("");
}
}
///////////////////////////////
package application;

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;


public class Main extends Application {

@Override
public void start(Stage stage) {
GUI gui = new GUI();
gui.start(stage);
}

public static void main(String[] args) {
launch(args);
}
}
///////////////////////////////
#,Name,Type 1,Type 2,Total,HP,Attack,Defense,Sp. Atk,Sp. Def,Speed
1,Bulbasaur,Grass,Poison,318,45,49,49,65,65,45
2,Ivysaur,Grass,Poison,405,60,62,63,80,80,60
3,Venusaur,Grass,Poison,525,80,82,83,100,100,80 csv
///////////////////////////////
package pokemon;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import javafx.collections.FXCollections;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;

public class PokeDex {
private TableView<Pokemon> pokeDex = new TableView<>();
private List<Pokemon> pokemons = new ArrayList<>();
private String path = "./src/pokemon/pokedex.csv";
private Label pkmFound;

public PokeDex(Stage stage, Label pkmFound) {
this.pkmFound = pkmFound;
readPokemonsFromFile();
createTableColumns();
pokeDex.prefHeightProperty().bind(stage.heightProperty());
pokeDex.prefWidthProperty().bind(stage.widthProperty());
pokeDex.setItems(FXCollections.observableArrayList(pokemons));
}

private void readPokemonsFromFile() {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(path), "UTF8"));) {
String line = reader.readLine();
while ((line = reader.readLine()) != null) {
String[] pokemonArray = line.split(",");
if (pokemonArray[3].equals("")) {
pokemonArray[3] = Type.NONE.toString();
}
pokemons.add(new Pokemon(Integer.parseInt(pokemonArray[0]), pokemonArray[1],
Type.valueOf(pokemonArray[2].toUpperCase()), Type.valueOf(pokemonArray[3].toUpperCase()),
Integer.parseInt(pokemonArray[4]), Integer.parseInt(pokemonArray[5]),
Integer.parseInt(pokemonArray[6]), Integer.parseInt(pokemonArray[7]),
Integer.parseInt(pokemonArray[8]), Integer.parseInt(pokemonArray[9]),
Integer.parseInt(pokemonArray[10])));
}
pkmFound.setText("Founds: " + pokemons.size());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public void filterPokemon(String name, String firstType, String secondType, String value, String math,
String value2) {
Predicate<? super Pokemon> namePredicate = s -> s.getName().toLowerCase().contains(name.toLowerCase())
|| name.equals("");
Predicate<? super Pokemon> firstTypePredicate = s -> s.getFirstType().toString().equals(firstType)
|| firstType.equals("NONE");
Predicate<? super Pokemon> secondTypePredicate = s -> s.getSecondType().toString().equals(secondType)
|| secondType.equals("NONE");
Predicate<? super Pokemon> valuePredicate = s -> (value.equals("") || value2.equals("") || math.equals("")) || mathOperation(value, value2, math, s);

List<Pokemon> filteredPokemons = this.pokemons.stream()
.filter(namePredicate)
.filter(firstTypePredicate)
.filter(secondTypePredicate)
.filter(valuePredicate)
.collect(Collectors.toList());
pokeDex.setItems(FXCollections.observableArrayList(filteredPokemons));
pkmFound.setText("Founds: " + filteredPokemons.size());

}

private boolean mathOperation(String value, String value2, String math, Pokemon p) {
if (!(value.equals("") || value2.equals("") || math.equals(""))) {
switch (math) {
case "<":
return p.getValue(value) < Integer.parseInt(value2);
case ">":
return p.getValue(value) > Integer.parseInt(value2);
case "=":
return p.getValue(value) == Integer.parseInt(value2);
default:
return false;
}
}
return false;
}

private void createTableColumns() {
TableColumn<Pokemon, String> name = new TableColumn<>("Name");
name.setCellValueFactory(new PropertyValueFactory<>("name"));
name.setMinWidth(170);
name.setResizable(false);

TableColumn<Pokemon, String> firstType = new TableColumn<>("Type 1");
firstType.setCellValueFactory(new PropertyValueFactory<>("firstType"));
firstType.setResizable(false);

TableColumn<Pokemon, String> secondType = new TableColumn<>("Type 2");
secondType.setCellValueFactory(new PropertyValueFactory<>("secondType"));
secondType.setResizable(false);

TableColumn<Pokemon, String> total = new TableColumn<>("Total");
total.setCellValueFactory(new PropertyValueFactory<>("total"));
total.setResizable(false);

TableColumn<Pokemon, String> hp = new TableColumn<>("HP");
hp.setCellValueFactory(new PropertyValueFactory<>("hp"));
hp.setResizable(false);

TableColumn<Pokemon, String> attack = new TableColumn<>("Attack");
attack.setCellValueFactory(new PropertyValueFactory<>("attack"));
attack.setResizable(false);

TableColumn<Pokemon, String> defense = new TableColumn<>("defense");
defense.setCellValueFactory(new PropertyValueFactory<>("defense"));
defense.setResizable(false);

TableColumn<Pokemon, String> specialAttack = new TableColumn<>("specialAttack");
specialAttack.setCellValueFactory(new PropertyValueFactory<>("specialAttack"));
specialAttack.setResizable(false);

TableColumn<Pokemon, String> specialDefense = new TableColumn<>("specialDefense");
specialDefense.setCellValueFactory(new PropertyValueFactory<>("specialDefense"));
specialDefense.setResizable(false);

TableColumn<Pokemon, String> speed = new TableColumn<>("speed");
speed.setCellValueFactory(new PropertyValueFactory<>("speed"));
speed.setResizable(false);

pokeDex.getColumns().addAll(name, firstType, secondType, total, hp, attack, defense, specialAttack,
specialDefense, speed);
}

public TableView<Pokemon> getPokeDex() {
return pokeDex;
}

}

///////////////////////////////
package pokemon;

public class Pokemon {
int id;
String name;
Type firstType;
Type secondType;
int total;
int hp;
int attack;
int defense;
int specialAttack;
int specialDefense;
int speed;
public Pokemon(int id, String name, Type firstType, Type secondType, int total, int hp, int attack, int defense,
int specialAttack, int specialDefense, int speed) {
super();
this.id = id;
this.name = name;
this.firstType = firstType;
this.secondType = secondType;
this.total = total;
this.hp = hp;
this.attack = attack;
this.defense = defense;
this.specialAttack = specialAttack;
this.specialDefense = specialDefense;
this.speed = speed;
}
public int getValue(String value) {
switch (value.toLowerCase()) {
case "total":
return this.total;
case "hp":
return this.hp;
case "attack":
return this.attack;
case "defense":
return this.defense;
case "specialAttack":
return this.specialAttack;
case "specialDefense":
return this.specialDefense;
case "speed":
return this.speed;
default:
break;
}
return 0;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Type getFirstType() {
return firstType;
}
public void setFirstType(Type firstType) {
this.firstType = firstType;
}
public Type getSecondType() {
return secondType;
}
public void setSecondType(Type secondType) {
this.secondType = secondType;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public int getHp() {
return hp;
}
public void setHp(int hp) {
this.hp = hp;
}
public int getAttack() {
return attack;
}
public void setAttack(int attack) {
this.attack = attack;
}
public int getDefense() {
return defense;
}
public void setDefense(int defense) {
this.defense = defense;
}
public int getSpecialAttack() {
return specialAttack;
}
public void setSpecialAttack(int specialAttack) {
this.specialAttack = specialAttack;
}
public int getSpecialDefense() {
return specialDefense;
}
public void setSpecialDefense(int specialDefense) {
this.specialDefense = specialDefense;
}
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}


}
////////////////


///////////////////////////////
package pokemon;

public enum Type {
NONE, BUG, DRAGON, FAIRY, FIRE, GHOST, GROUND, NORMAL, PSYCHIC, STEEL, DARK, ELECTRIC, FIGHTING, FLYING, GRASS, ICE,
POISON, ROCK, WATER;
}
///////////////

package application;

import Controller.CalenderManager;

/**
*
*
*/
public class Main {

public static void main(String[] args) {
CalenderManager cm = new CalenderManager();
cm.start();

}
}
////////////////////////
package Controller;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Scanner;

import Model.Caleder;
import Model.Meeting;

public class CalenderManager {

private Caleder calender;
private Scanner sc;
private StringBuilder sb;

public CalenderManager() {
this.calender = new Caleder();
this.sc = new Scanner(System.in);
this.sb = new StringBuilder();
this.sb.append("Was wollen sie tun? Bitte geben Sie die Zahl ein." + "\n");
this.sb.append("1-Kalender anzeigen" + "\n");
this.sb.append("2- Neuen Termin anklegen" + "\n");
this.sb.append("3-Einen vorhandenen Termin löschen" + "\n");
this.sb.append("4-Anwendung beenden" + "\n");
this.sb.append("5-Nur Termine zwischen bestimmten Daten auflisten" + "\n");
this.sb.append("6-diffirenz zum Heutien Datum in Tagen" + "\n");

}

public void start() {
System.out.println("Herzlich Willkommne zu Ihrem Kalender");
showMenu();
}

private void showMenu() {
System.out.println(this.sb.toString());

String input = this.sc.nextLine();
switch (input) {
case ("1"):
showCalender();
break;
case ("2"):
addNewMeeting();
break;
case ("3"):
removeMeeting();
break;
case ("4"):
closeApplication();
break;
case ("5"):
showCalenderBetween();
break;
case ("6"):
showDiff();
break;
default:
System.out.println("das war keine gültige eingabe bitte wählen sie erneut!");
break;
}

showMenu();
}

private void showDiff() {
System.out.println("Bitte datum eingeben!");
LocalDate date = convertStringToDate(this.sc.nextLine());
System.out.println("Die Differenz zum eingegeben Datum und heute beträgt: "
+ ChronoUnit.DAYS.between(LocalDate.now(), date) + " Tage \n");
}

private void showCalenderBetween() {

System.out.println("bitte erstes Datum eingeben");
String date1 = this.sc.nextLine();
System.out.println("bitte zweites Datum eingeben");
String date2 = this.sc.nextLine();
this.calender.showMeetingBetween(convertStringToDate(date1), convertStringToDate(date2));

}

private void closeApplication() {
this.sc.close();
System.out.println("Auf Wiedersehen.");

}

private void removeMeeting() {
System.out.println("Bitte geben sie das Datum vom Meeting das sie entfernen wollen an (im Format tt.mm.jjj)");
String dateString = this.sc.nextLine();
LocalDate date = convertStringToDate(dateString);
if (this.calender.getMeetings().get(date) == null) {
System.out.println("Ein Meeting mit diesem Datum existiert nicht.");
} else {
this.calender.removeMeeting(date);
System.out.println("Das Meeting wurde erfolgreich gelöscht");

}
showMenu();
}

private void addNewMeeting() {
System.out.println("Bitte geben sie einen Namen für ihr Meeting ein");
String name = this.sc.nextLine();
System.out.println("Bitte geben Sie den Tag an, an dem der Termin stattfindne soll. (im Format tt.mm.jjj)");
String dateString = this.sc.nextLine();
LocalDate date = convertStringToDate(dateString);

if (checkDate(date)) {
try {
this.calender.addMeeting(new Meeting(name, date));
System.out.println("der Termin wurde erfolgreich hinzugefügt.");

} catch (DuplicateMeetingException e) {

handleDuplicateMeetingException(name, date);
}

showMenu();
} else {
System.err.println(
"Dieses Datum liegt in der Vergangenheit! Eintragung nicht möglich! \nBitte korrigieren sie die Eingabe!\n");
addNewMeeting();
}
}

private boolean checkDate(LocalDate date) {

if (date.isBefore(LocalDate.now())) {
return false;
}

return true;
}

private void handleDuplicateMeetingException(String name, LocalDate date) {
StringBuilder sb2 = new StringBuilder();
sb2.append("Was wollen sie tun? \n");
sb2.append("1-Termin überschreiben \n");
sb2.append("2-Eingabe verwerfen \n");
System.out.println(sb2.toString());

switch (this.sc.nextLine()) {
case "1":
this.calender.removeMeeting(date);
try {
this.calender.addMeeting(new Meeting(name, date));
} catch (DuplicateMeetingException e1) {
e1.printStackTrace();
}
case "2":
break;
default:
System.out.println("Diese Eingabe ist ungültig! bitte neu wählen!");
System.out.println(sb2.toString());
handleDuplicateMeetingException(name, date);

}
}

private LocalDate convertStringToDate(String dateString) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d.MM.yyyy");
LocalDate date = LocalDate.parse(dateString, formatter);
return date;
}

private void showCalender() {

if (this.calender.getMeetings().size() == 0) {
System.out.println("Keine Termine eingetragen");
showMenu();
} else {

System.out.println(this.calender);

}
this.sc.nextLine();
showMenu();
}

}

////////////////////////
package Controller;

public class DuplicateMeetingException extends Exception {

/**
*
*/
private static final long serialVersionUID = 4260416168451581192L;

public DuplicateMeetingException() {
super();
System.err.println("Dieses Datum ist bereits belegt.");
}
}

////////////////////////
package Model;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import Controller.DuplicateMeetingException;

public class Caleder {

private Map<LocalDate, Meeting> meetings;

public Caleder() {
this.meetings = new HashMap<>();
}

public void addMeeting(Meeting meeting) throws DuplicateMeetingException {
if (this.meetings.containsKey(meeting.getDate())) {
throw new DuplicateMeetingException();
} else {
this.meetings.put(meeting.getDate(), meeting);
}
}

public final Map<LocalDate, Meeting> getMeetings() {
return this.meetings;
}

public void removeMeeting(LocalDate date) {
this.meetings.remove(date);
}

@Override
public String toString() {
List<Meeting> meetings = this.meetings.values().stream().sorted().collect(Collectors.toList());
StringBuilder sb = new StringBuilder();

sb.append("Ihre Termine: \n");

for (Meeting meeting : meetings) {
sb.append(meeting + "\n");
}

return sb.toString();
}

public void showMeetingBetween(LocalDate date1, LocalDate date2) {

List<Meeting> meetings = this.meetings.values().stream().sorted()
.filter(meeting -> meeting.getDate().isAfter(date1) && meeting.getDate().isBefore(date2))
.collect(Collectors.toList());
StringBuilder sb = new StringBuilder();

sb.append("Ihre Termine: \n");

for (Meeting meeting : meetings) {
sb.append(meeting + "\n");
}

System.out.println(sb.toString());
}

}

////////////////////////
package Model;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Meeting implements Comparable<Meeting> {

private LocalDate date;
private String name;
private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d.MM.yyyy");

public Meeting(String name, LocalDate date) {
this.name = name;
this.date = date;

}

public final LocalDate getDate() {
return this.date;
}

public final void setDate(LocalDate date) {
this.date = date;
}

public final String getName() {
return this.name;
}

public final void setName(String name) {
this.name = name;
}

@Override
public String toString() {
return this.date.format(this.formatter) + " " + this.date.getDayOfWeek().toString() + " : " + this.name;
}

@Override
public int compareTo(Meeting meeting) {
if (this.date.isBefore(meeting.getDate())) {
return -1;
} else if (this.date.isAfter(meeting.getDate())) {
return 1;
}
return 0;
}

}
////

@FunctionalInterface
public interface Calculator {

int calculate(int a, int b);
}
/////////////
import java.util.ArrayList;
import java.util.List;

public class Main {

public static void main(String[] args) {
warmUp();
}

private static void warmUp() {
Calculator mul = (a, b) -> a * b;
Calculator sub = (a, b) -> a - b;
Calculator sum = (a, b) -> a + b;
Calculator div = (a, b) -> a / b;
List<Calculator> calcs = new ArrayList<>();
calcs.add(mul);
calcs.add(sub);
calcs.add(div);
calcs.add(sum);

for (Calculator calculator : calcs) {
System.out.println(calculator.calculate(10, 5));
}
}
}
///////////////////
public class Multiply implements Calculator {

@Override
public int calculate(int a, int b) {
return a * b;
}

}
///////////////////
public enum Operations {
SUM, SUB, DIV, MUL
}
/////////////////////
@FunctionalInterface
public interface TwoNumbers {
double twoNumbers(int i, int j, Operations operation);
}
 
MoxxiManagarm

MoxxiManagarm

So wie du es formatiert hast wird lesen echt schwierig....
Bitte formatiere es mit [code=java][/java] und wenn möglich die einzelnen Klassen auch mit [spoiler][/spoiler] abtrennen. Etwas so

Java:
class Klasse1
Java:
class Klasse2
 
MoxxiManagarm

MoxxiManagarm

Unabhängig davon hier aber ein paar Punkte welche mir beim Überfliegen augefallen sind:

---

Java:
@Override
public int compareTo(Meeting meeting) {
  if (this.date.isBefore(meeting.getDate())) {
   return -1;
  } else if (this.date.isAfter(meeting.getDate())) {
    return 1;
  }
  return 0;
}
Das geht auch kürzer:

Java:
public int compareTo(Meeting meeting) {
  return Comparator.comparing(Meeting::getDate).compare(this, meeting);
}
Das geht weil date bei dir ein LocalDate ist, welches als ChronoLocalDate vergleichbar ist.

---

Java:
Calculator div = (a, b) -> a / b;
Denk an Division durch 0 und du machst hier eine Ganzzahldivision.

---

Java:
List<Meeting> meetings = this.meetings.values().stream().sorted().collect(Collectors.toList());
Eine Liste kannst du auch so sortieren ohne den Umweg über einen Stream. Die doppelte Benennung meetings ist im übrigen sehr bescheiden.

Java:
List<Meeting> meetings = this.meetings.values().sort(Comparator.naturalOrder());
---

Java:
private Map<LocalDate, Meeting> meetings;

public Caleder() {
  this.meetings = new HashMap<>();
}
Die Reihenfolge der Meetings spielt bei dir ja eine große Rolle. Anstatt diese in einer HashMap zu speichern und anschließend zu sortieren wäre es vermutlich ratsamer zu einer TreeMap zu greifen, welche die Einträge direkt an die entsprechende Stelle einsortiert.

Bitte Benenne doch Cale*n*dar auch richtig.

---

Ich bin noch etwas skeptisch wegen der Relation LocalDate-Meeting. Aktuell kannst du pro Tag nur ein Meeting haben. Ist das so gewollt? Sollte es vielleicht ein private Map<LocalDate, List<Meeting>> meetings; sein ? Auch ist es etwas komisch, dass ein Meeting keine Uhrzeit kennt?! Meiner Meinung nach ist LocalDate für die Map richtig, aber LocalDateTime als Attribut im Meeting.
 
Zuletzt bearbeitet:
O

OracleBoy

Java:
public class MainView extends HBox{

    private TableView<Console> tableViewConsole = new TableView<>();
    private TableView<VideoGame> tableViewVideoGame = new TableView<>();

    private Storage<Console> consoleStorage = new Storage<Console>(10);
    private Storage<VideoGame> videoGameStorage = new Storage<VideoGame>(Integer.MAX_VALUE);

    private BorderPane borderPaneLeft = new BorderPane();
    private VBox vBoxVideoGame = new VBox();
    private VBox vBoxConsole = new VBox();
    private HBox buttonHBox = new HBox();

    private Button buyButton = new Button("Kaufen");
    private Button sellButton = new Button("Verkaufen");

    private ComboBox<Manufacturer> comboBoxManufacturer = new ComboBox<>(FXCollections.observableArrayList(Manufacturer.values()));
    private ComboBox<Genre> comboBoxGenre = new ComboBox<>(FXCollections.observableArrayList(Genre.values()));
    private ComboBox<String> comboBoxSelect = new ComboBox<>(FXCollections.observableArrayList("Konsole","Videospiel"));

    private TextField videoGameNameTextField = new TextField();
    private TextField ageRestrictionTextField = new TextField();
    private TextField consoleNameTextField = new TextField();

    public MainView() {
        createView();
        setProperties();
        createConsoleTableView();
        createVideoGameTableView();
        handleActions();
    }

    private void createView() {
        this.getChildren().addAll(this.borderPaneLeft, this.tableViewConsole);
        this.vBoxVideoGame.getChildren().addAll(this.videoGameNameTextField, this.comboBoxGenre, this.ageRestrictionTextField);
        this.vBoxConsole.getChildren().addAll(this.consoleNameTextField, this.comboBoxManufacturer);
        this.buttonHBox.getChildren().addAll(this.buyButton,this.sellButton);
        this.borderPaneLeft.setTop(this.comboBoxSelect);
        this.borderPaneLeft.setBottom(this.buttonHBox);
    }

    private void setProperties() {
        this.videoGameNameTextField.setPromptText("Name");
        this.ageRestrictionTextField.setPromptText("Altersbeschränkung");
        this.consoleNameTextField.setPromptText("Name");
    }

    private void handleActions() {
        this.comboBoxSelect.setOnAction(e -> {
            this.getChildren().removeAll(this.tableViewConsole,this.tableViewVideoGame);
            switch (this.comboBoxSelect.getValue()) {
            case "Videospiel":
                this.borderPaneLeft.setCenter(this.vBoxVideoGame);
                this.getChildren().add(this.tableViewVideoGame);
                break;
            case "Konsole":
                this.borderPaneLeft.setCenter(this.vBoxConsole);
                this.getChildren().add(this.tableViewConsole);
                break;
            default:
                this.borderPaneLeft.setCenter(null);
                break;
            }

        });

        this.buyButton.setOnAction(e -> {
            switch (this.comboBoxSelect.getValue()) {
            case "Videospiel":
                if(this.comboBoxGenre.getValue()==null) {
                    VideoGame videoGame = new VideoGame(this.videoGameNameTextField.getText(), Integer.parseInt(this.ageRestrictionTextField.getText()));
                    this.videoGameStorage.addToStorage(videoGame);
                    break;
                } else {
                    VideoGame videoGame = new VideoGame(this.videoGameNameTextField.getText(), Integer.parseInt(this.ageRestrictionTextField.getText()), this.comboBoxGenre.getValue());
                    this.videoGameStorage.addToStorage(videoGame);
                    break;
                }
            case "Konsole":
                Console console = new Console(this.consoleNameTextField.getText(), this.comboBoxManufacturer.getValue());
                this.consoleStorage.addToStorage(console);
                break;
            default:
                break;
            }
        });

        this.sellButton.setOnAction(e -> {
            switch (this.comboBoxSelect.getValue()) {
            case "Videospiel":
                this.videoGameStorage.removeItemFromStorage(this.tableViewVideoGame.getSelectionModel().getSelectedItem());
                break;
            case "Konsole":
                this.consoleStorage.removeItemFromStorage(this.tableViewConsole.getSelectionModel().getSelectedItem());
                break;
            default:
                break;
            }
        });
    }

    private void createVideoGameTableView() {
        TableColumn<VideoGame,Integer> idColumnVideoGame = new TableColumn<>("ID: ");
        idColumnVideoGame.setCellValueFactory(new PropertyValueFactory<>("id"));

        TableColumn<VideoGame,String> nameColumnVideoGame = new TableColumn<>("Name: ");
        nameColumnVideoGame.setCellValueFactory(new PropertyValueFactory<>("name"));

        TableColumn<VideoGame,Genre> genreColumn = new TableColumn<>("Genre: ");
        genreColumn.setCellValueFactory(new PropertyValueFactory<>("genre"));

        TableColumn<VideoGame, Integer> ageRestrictionColumn = new TableColumn<>("Altersbeschränkung");
        ageRestrictionColumn.setCellValueFactory(new PropertyValueFactory<>("ageRestriction"));

        this.tableViewVideoGame.getColumns().addAll(idColumnVideoGame,nameColumnVideoGame,genreColumn,ageRestrictionColumn);
        this.tableViewVideoGame.setItems(this.videoGameStorage.getStorageElements());
    }

    private void createConsoleTableView() {
        TableColumn<Console, Integer> idColumnConsole = new TableColumn<>("ID: ");
        idColumnConsole.setCellValueFactory(new PropertyValueFactory<>("id"));

        TableColumn<Console,String> nameColumnConsole = new TableColumn<>("Name: ");
        nameColumnConsole.setCellValueFactory(new PropertyValueFactory<>("name"));

        TableColumn<Console,Manufacturer> manufacturerConsole = new TableColumn<>("Hersteller: ");
        manufacturerConsole.setCellValueFactory(new PropertyValueFactory<>("manufacturer"));

        this.tableViewConsole.getColumns().addAll(idColumnConsole, nameColumnConsole, manufacturerConsole);
        this.tableViewConsole.setItems(this.consoleStorage.getStorageElements());
    }
}

////////////////////////////////////////////////////////////////////////////////////////////

public class Article {
    
    private String name;
    private int id;
    private static int counter = 0;
    
    
    
    public Article(String name) {
        super();
        this.name = name;
        this.id = counter++;
    }
    
    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public int getId() {
        return this.id;
    }
    
    public void setId(int id) {
        this.id = id;
    }
    
}

//////////////////////////////////////////////////////////////////////////////////////////

public class Console extends Article {
    
    private Manufacturer manufacturer;
    
    public Console(String name, Manufacturer manufacturer) {
        super(name);
        this.manufacturer = manufacturer;
    }

    public Manufacturer getManufacturer() {
        return this.manufacturer;
    }

    public void setManufacturer(Manufacturer manufacturer) {
        this.manufacturer = manufacturer;
    }
    
    
}

///////////////////////////////////////////////////////////////////////////////////////////

public class VideoGame extends Article {

    private int ageRestriction;
    private Genre genre;

    public VideoGame(String name, int ageRestriction, Genre genre) {
        super(name);
        this.ageRestriction = ageRestriction;
        this.genre = genre;
    }
    
    public VideoGame(String name, int ageRestriction) {
        super(name);
        this.ageRestriction = ageRestriction;
        this.genre = this.genre.ACTION;
    }

    public int getAgeRestriction() {
        return this.ageRestriction;
    }

    public void setAgeRestriction(int ageRestriction) {
        this.ageRestriction = ageRestriction;
    }

    public Genre getGenre() {
        return this.genre;
    }

    public void setGenre(Genre genre) {
        this.genre = genre;
    }
    
    
}

///////////////////////////////////////////////////////////////////////////////////////

public class Storage<T extends Article> {

    private ObservableList<T> storageElements = FXCollections.observableArrayList();
    private int maxCapacity;

    public Storage(int maxCapacity) {
        this.maxCapacity = maxCapacity;
    }

    public ObservableList<T> getStorageElements() {
        return this.storageElements;
    }

    public void addToStorage(T article) {
        if (this.maxCapacity > this.storageElements.size()) {
            this.storageElements.add(article);
        }
    }

    public void removeItemFromStorage(T article) {
        this.storageElements.remove(article);
    }



}

///////////////////////////////////////////////////////////////////////////////////////

public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {
            MainView root = new MainView();
            Scene scene = new Scene(root,700,700);
            scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
    
    public static void main(String[] args) {
        launch(args);
    }
}
//////
Neue Java-Datei
------------------

package application;

import javafx.collections.FXCollections;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBase;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Control;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import pokemon.PokeDex;
import pokemon.Type;

public class GUI {
    private Scene scene;
    private VBox root = new VBox();
    private HBox hBox = new HBox();
    private Label pkmFound = new Label();
    private TextField searchName = new TextField();
    private ChoiceBox<Type> firstTypeBox = new ChoiceBox<>(FXCollections.observableArrayList(Type.values()));
    private ChoiceBox<Type> secondTypeBox = new ChoiceBox<>(FXCollections.observableArrayList(Type.values()));
    private ComboBox<String> choiceBox = new ComboBox<>(FXCollections.observableArrayList("", "Total", "HP", "Attack",
            "Defense", "Special Attack", "Special Defense", "Speed"));
    private ComboBox<String> choiceBox2 = new ComboBox<>(FXCollections.observableArrayList("", "<", ">", "="));
    private TextField searchValue = new TextField();
    private PokeDex pokeDex;

    public void start(Stage stage) {
        pokeDex = new PokeDex(stage, pkmFound);
        stage.setTitle("PokeDex");
        editBoxesAndFields();
        hBox.getChildren().addAll(searchName, firstTypeBox, secondTypeBox, choiceBox, choiceBox2, searchValue);
        root.getChildren().addAll(hBox, pkmFound, pokeDex.getPokeDex());
        scene = new Scene(root, 890, 1000);
        stage.setScene(scene);
        stage.setResizable(false);
        stage.show();
        actionHandling();
    }
    private void actionHandling() {
        searchName.setOnKeyReleased(event -> filter());
        firstTypeBox.setOnAction(event -> filter());
        secondTypeBox.setOnAction(event -> filter());
        choiceBox.setOnAction(event -> filter());
        choiceBox2.setOnAction(event -> filter());
        searchValue.setOnKeyReleased(event -> filter());
        
    }
    private void filter() {
        pokeDex.filterPokemon(searchName.getText(),
                firstTypeBox.getValue().toString(), secondTypeBox.getValue().toString(), choiceBox.getValue(),
                choiceBox2.getValue(), searchValue.getText());
    }
    private void editBoxesAndFields() {
        searchName.setPromptText("Name");
        searchValue.setPromptText("Wert");
        firstTypeBox.setValue(Type.NONE);
        secondTypeBox.setValue(Type.NONE);
        choiceBox.setValue("");
        choiceBox2.setValue("");
    }
}
///////////////////////////////
package application;
    
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;


public class Main extends Application {

    @Override
    public void start(Stage stage) {
        GUI gui = new GUI();
        gui.start(stage);
    }

    public static void main(String[] args) {
        launch(args);
    }
}
///////////////////////////////
#,Name,Type 1,Type 2,Total,HP,Attack,Defense,Sp. Atk,Sp. Def,Speed
1,Bulbasaur,Grass,Poison,318,45,49,49,65,65,45
2,Ivysaur,Grass,Poison,405,60,62,63,80,80,60
3,Venusaur,Grass,Poison,525,80,82,83,100,100,80 csv
///////////////////////////////
package pokemon;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import javafx.collections.FXCollections;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;

public class PokeDex {
    private TableView<Pokemon> pokeDex = new TableView<>();
    private List<Pokemon> pokemons = new ArrayList<>();
    private String path = "./src/pokemon/pokedex.csv";
    private Label pkmFound;

    public PokeDex(Stage stage, Label pkmFound) {
        this.pkmFound = pkmFound;
        readPokemonsFromFile();
        createTableColumns();
        pokeDex.prefHeightProperty().bind(stage.heightProperty());
        pokeDex.prefWidthProperty().bind(stage.widthProperty());
        pokeDex.setItems(FXCollections.observableArrayList(pokemons));
    }

    private void readPokemonsFromFile() {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(path), "UTF8"));) {
            String line = reader.readLine();
            while ((line = reader.readLine()) != null) {
                String[] pokemonArray = line.split(",");
                if (pokemonArray[3].equals("")) {
                    pokemonArray[3] = Type.NONE.toString();
                }
                pokemons.add(new Pokemon(Integer.parseInt(pokemonArray[0]), pokemonArray[1],
                        Type.valueOf(pokemonArray[2].toUpperCase()), Type.valueOf(pokemonArray[3].toUpperCase()),
                        Integer.parseInt(pokemonArray[4]), Integer.parseInt(pokemonArray[5]),
                        Integer.parseInt(pokemonArray[6]), Integer.parseInt(pokemonArray[7]),
                        Integer.parseInt(pokemonArray[8]), Integer.parseInt(pokemonArray[9]),
                        Integer.parseInt(pokemonArray[10])));
            }
            pkmFound.setText("Founds: " + pokemons.size());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public void filterPokemon(String name, String firstType, String secondType, String value, String math,
            String value2) {
        Predicate<? super Pokemon> namePredicate = s -> s.getName().toLowerCase().contains(name.toLowerCase())
                || name.equals("");
        Predicate<? super Pokemon> firstTypePredicate = s -> s.getFirstType().toString().equals(firstType)
                || firstType.equals("NONE");
        Predicate<? super Pokemon> secondTypePredicate = s -> s.getSecondType().toString().equals(secondType)
                || secondType.equals("NONE");
        Predicate<? super Pokemon> valuePredicate = s -> (value.equals("") || value2.equals("") || math.equals("")) || mathOperation(value, value2, math, s);

        List<Pokemon> filteredPokemons = this.pokemons.stream()
                .filter(namePredicate)
                .filter(firstTypePredicate)
                .filter(secondTypePredicate)
                .filter(valuePredicate)
                .collect(Collectors.toList());
        pokeDex.setItems(FXCollections.observableArrayList(filteredPokemons));
        pkmFound.setText("Founds: " + filteredPokemons.size());

    }

    private boolean mathOperation(String value, String value2, String math, Pokemon p) {
        if (!(value.equals("") || value2.equals("") || math.equals(""))) {
            switch (math) {
            case "<":
                    return p.getValue(value) < Integer.parseInt(value2);
            case ">":
                    return p.getValue(value) > Integer.parseInt(value2);
            case "=":
                    return p.getValue(value) == Integer.parseInt(value2);
            default:
                return false;
            }
        }
        return false;
    }

    private void createTableColumns() {
        TableColumn<Pokemon, String> name = new TableColumn<>("Name");
        name.setCellValueFactory(new PropertyValueFactory<>("name"));
        name.setMinWidth(170);
        name.setResizable(false);

        TableColumn<Pokemon, String> firstType = new TableColumn<>("Type 1");
        firstType.setCellValueFactory(new PropertyValueFactory<>("firstType"));
        firstType.setResizable(false);

        TableColumn<Pokemon, String> secondType = new TableColumn<>("Type 2");
        secondType.setCellValueFactory(new PropertyValueFactory<>("secondType"));
        secondType.setResizable(false);

        TableColumn<Pokemon, String> total = new TableColumn<>("Total");
        total.setCellValueFactory(new PropertyValueFactory<>("total"));
        total.setResizable(false);

        TableColumn<Pokemon, String> hp = new TableColumn<>("HP");
        hp.setCellValueFactory(new PropertyValueFactory<>("hp"));
        hp.setResizable(false);

        TableColumn<Pokemon, String> attack = new TableColumn<>("Attack");
        attack.setCellValueFactory(new PropertyValueFactory<>("attack"));
        attack.setResizable(false);

        TableColumn<Pokemon, String> defense = new TableColumn<>("defense");
        defense.setCellValueFactory(new PropertyValueFactory<>("defense"));
        defense.setResizable(false);

        TableColumn<Pokemon, String> specialAttack = new TableColumn<>("specialAttack");
        specialAttack.setCellValueFactory(new PropertyValueFactory<>("specialAttack"));
        specialAttack.setResizable(false);

        TableColumn<Pokemon, String> specialDefense = new TableColumn<>("specialDefense");
        specialDefense.setCellValueFactory(new PropertyValueFactory<>("specialDefense"));
        specialDefense.setResizable(false);

        TableColumn<Pokemon, String> speed = new TableColumn<>("speed");
        speed.setCellValueFactory(new PropertyValueFactory<>("speed"));
        speed.setResizable(false);

        pokeDex.getColumns().addAll(name, firstType, secondType, total, hp, attack, defense, specialAttack,
                specialDefense, speed);
    }

    public TableView<Pokemon> getPokeDex() {
        return pokeDex;
    }

}

///////////////////////////////
package pokemon;

public class Pokemon {
    int id;
    String name;
    Type firstType;
    Type secondType;
    int total;
    int hp;
    int attack;
    int defense;
    int specialAttack;
    int specialDefense;
    int speed;
    public Pokemon(int id, String name, Type firstType, Type secondType, int total, int hp, int attack, int defense,
            int specialAttack, int specialDefense, int speed) {
        super();
        this.id = id;
        this.name = name;
        this.firstType = firstType;
        this.secondType = secondType;
        this.total = total;
        this.hp = hp;
        this.attack = attack;
        this.defense = defense;
        this.specialAttack = specialAttack;
        this.specialDefense = specialDefense;
        this.speed = speed;
    }
    public int getValue(String value) {
        switch (value.toLowerCase()) {
        case "total":
            return this.total;
        case "hp":
            return this.hp;
        case "attack":
            return this.attack;
        case "defense":
            return this.defense;
        case "specialAttack":
            return this.specialAttack;
        case "specialDefense":
            return this.specialDefense;
        case "speed":
            return this.speed;
        default:
            break;
        }
        return 0;
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Type getFirstType() {
        return firstType;
    }
    public void setFirstType(Type firstType) {
        this.firstType = firstType;
    }
    public Type getSecondType() {
        return secondType;
    }
    public void setSecondType(Type secondType) {
        this.secondType = secondType;
    }
    public int getTotal() {
        return total;
    }
    public void setTotal(int total) {
        this.total = total;
    }
    public int getHp() {
        return hp;
    }
    public void setHp(int hp) {
        this.hp = hp;
    }
    public int getAttack() {
        return attack;
    }
    public void setAttack(int attack) {
        this.attack = attack;
    }
    public int getDefense() {
        return defense;
    }
    public void setDefense(int defense) {
        this.defense = defense;
    }
    public int getSpecialAttack() {
        return specialAttack;
    }
    public void setSpecialAttack(int specialAttack) {
        this.specialAttack = specialAttack;
    }
    public int getSpecialDefense() {
        return specialDefense;
    }
    public void setSpecialDefense(int specialDefense) {
        this.specialDefense = specialDefense;
    }
    public int getSpeed() {
        return speed;
    }
    public void setSpeed(int speed) {
        this.speed = speed;
    }
    
    
}
////////////////


///////////////////////////////
package pokemon;

public enum Type {
    NONE, BUG, DRAGON, FAIRY, FIRE, GHOST, GROUND, NORMAL, PSYCHIC, STEEL, DARK, ELECTRIC, FIGHTING, FLYING, GRASS, ICE,
    POISON, ROCK, WATER;
}
///////////////

package application;

import Controller.CalenderManager;

/**
 *
 *
 */
public class Main {

    public static void main(String[] args) {
        CalenderManager cm = new CalenderManager();
        cm.start();

    }
}
////////////////////////
package Controller;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Scanner;

import Model.Caleder;
import Model.Meeting;

public class CalenderManager {

    private Caleder calender;
    private Scanner sc;
    private StringBuilder sb;

    public CalenderManager() {
        this.calender = new Caleder();
        this.sc = new Scanner(System.in);
        this.sb = new StringBuilder();
        this.sb.append("Was wollen sie tun? Bitte geben Sie die Zahl ein." + "\n");
        this.sb.append("1-Kalender anzeigen" + "\n");
        this.sb.append("2- Neuen Termin anklegen" + "\n");
        this.sb.append("3-Einen vorhandenen Termin löschen" + "\n");
        this.sb.append("4-Anwendung beenden" + "\n");
        this.sb.append("5-Nur Termine zwischen bestimmten Daten auflisten" + "\n");
        this.sb.append("6-diffirenz zum Heutien Datum in Tagen" + "\n");

    }

    public void start() {
        System.out.println("Herzlich Willkommne zu Ihrem Kalender");
        showMenu();
    }

    private void showMenu() {
        System.out.println(this.sb.toString());

        String input = this.sc.nextLine();
        switch (input) {
        case ("1"):
            showCalender();
            break;
        case ("2"):
            addNewMeeting();
            break;
        case ("3"):
            removeMeeting();
            break;
        case ("4"):
            closeApplication();
            break;
        case ("5"):
            showCalenderBetween();
            break;
        case ("6"):
            showDiff();
            break;
        default:
            System.out.println("das war keine gültige eingabe bitte wählen sie erneut!");
            break;
        }

        showMenu();
    }

    private void showDiff() {
        System.out.println("Bitte datum eingeben!");
        LocalDate date = convertStringToDate(this.sc.nextLine());
        System.out.println("Die Differenz zum eingegeben Datum und heute beträgt: "
                + ChronoUnit.DAYS.between(LocalDate.now(), date) + " Tage \n");
    }

    private void showCalenderBetween() {

        System.out.println("bitte erstes Datum eingeben");
        String date1 = this.sc.nextLine();
        System.out.println("bitte zweites Datum eingeben");
        String date2 = this.sc.nextLine();
        this.calender.showMeetingBetween(convertStringToDate(date1), convertStringToDate(date2));

    }

    private void closeApplication() {
        this.sc.close();
        System.out.println("Auf Wiedersehen.");

    }

    private void removeMeeting() {
        System.out.println("Bitte geben sie das Datum vom Meeting das sie entfernen wollen an (im Format tt.mm.jjj)");
        String dateString = this.sc.nextLine();
        LocalDate date = convertStringToDate(dateString);
        if (this.calender.getMeetings().get(date) == null) {
            System.out.println("Ein Meeting mit diesem Datum existiert nicht.");
        } else {
            this.calender.removeMeeting(date);
            System.out.println("Das Meeting wurde erfolgreich gelöscht");

        }
        showMenu();
    }

    private void addNewMeeting() {
        System.out.println("Bitte geben sie einen Namen für ihr Meeting ein");
        String name = this.sc.nextLine();
        System.out.println("Bitte geben Sie den Tag an, an dem der Termin stattfindne soll. (im Format tt.mm.jjj)");
        String dateString = this.sc.nextLine();
        LocalDate date = convertStringToDate(dateString);

        if (checkDate(date)) {
            try {
                this.calender.addMeeting(new Meeting(name, date));
                System.out.println("der Termin wurde erfolgreich hinzugefügt.");

            } catch (DuplicateMeetingException e) {

                handleDuplicateMeetingException(name, date);
            }

            showMenu();
        } else {
            System.err.println(
                    "Dieses Datum liegt in der Vergangenheit! Eintragung nicht möglich! \nBitte korrigieren sie die Eingabe!\n");
            addNewMeeting();
        }
    }

    private boolean checkDate(LocalDate date) {

        if (date.isBefore(LocalDate.now())) {
            return false;
        }

        return true;
    }

    private void handleDuplicateMeetingException(String name, LocalDate date) {
        StringBuilder sb2 = new StringBuilder();
        sb2.append("Was wollen sie tun? \n");
        sb2.append("1-Termin überschreiben \n");
        sb2.append("2-Eingabe verwerfen \n");
        System.out.println(sb2.toString());

        switch (this.sc.nextLine()) {
        case "1":
            this.calender.removeMeeting(date);
            try {
                this.calender.addMeeting(new Meeting(name, date));
            } catch (DuplicateMeetingException e1) {
                e1.printStackTrace();
            }
        case "2":
            break;
        default:
            System.out.println("Diese Eingabe ist ungültig! bitte neu wählen!");
            System.out.println(sb2.toString());
            handleDuplicateMeetingException(name, date);

        }
    }

    private LocalDate convertStringToDate(String dateString) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d.MM.yyyy");
        LocalDate date = LocalDate.parse(dateString, formatter);
        return date;
    }

    private void showCalender() {

        if (this.calender.getMeetings().size() == 0) {
            System.out.println("Keine Termine eingetragen");
            showMenu();
        } else {

            System.out.println(this.calender);

        }
        this.sc.nextLine();
        showMenu();
    }

}

////////////////////////
package Controller;

public class DuplicateMeetingException extends Exception {

    /**
     *
     */
    private static final long serialVersionUID = 4260416168451581192L;

    public DuplicateMeetingException() {
        super();
        System.err.println("Dieses Datum ist bereits belegt.");
    }
}

////////////////////////
package Model;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import Controller.DuplicateMeetingException;

public class Caleder {

    private Map<LocalDate, Meeting> meetings;

    public Caleder() {
        this.meetings = new HashMap<>();
    }

    public void addMeeting(Meeting meeting) throws DuplicateMeetingException {
        if (this.meetings.containsKey(meeting.getDate())) {
            throw new DuplicateMeetingException();
        } else {
            this.meetings.put(meeting.getDate(), meeting);
        }
    }

    public final Map<LocalDate, Meeting> getMeetings() {
        return this.meetings;
    }

    public void removeMeeting(LocalDate date) {
        this.meetings.remove(date);
    }

    @Override
    public String toString() {
        List<Meeting> meetings = this.meetings.values().stream().sorted().collect(Collectors.toList());
        StringBuilder sb = new StringBuilder();

        sb.append("Ihre Termine: \n");

        for (Meeting meeting : meetings) {
            sb.append(meeting + "\n");
        }

        return sb.toString();
    }

    public void showMeetingBetween(LocalDate date1, LocalDate date2) {

        List<Meeting> meetings = this.meetings.values().stream().sorted()
                .filter(meeting -> meeting.getDate().isAfter(date1) && meeting.getDate().isBefore(date2))
                .collect(Collectors.toList());
        StringBuilder sb = new StringBuilder();

        sb.append("Ihre Termine: \n");

        for (Meeting meeting : meetings) {
            sb.append(meeting + "\n");
        }

        System.out.println(sb.toString());
    }

}

////////////////////////
package Model;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Meeting implements Comparable<Meeting> {

    private LocalDate date;
    private String name;
    private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d.MM.yyyy");

    public Meeting(String name, LocalDate date) {
        this.name = name;
        this.date = date;

    }

    public final LocalDate getDate() {
        return this.date;
    }

    public final void setDate(LocalDate date) {
        this.date = date;
    }

    public final String getName() {
        return this.name;
    }

    public final void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return this.date.format(this.formatter) + " " + this.date.getDayOfWeek().toString() + " : " + this.name;
    }

    @Override
    public int compareTo(Meeting meeting) {
        if (this.date.isBefore(meeting.getDate())) {
            return -1;
        } else if (this.date.isAfter(meeting.getDate())) {
            return 1;
        }
        return 0;
    }

}
////

@FunctionalInterface
public interface Calculator {
    
    int calculate(int a, int b);
}
/////////////
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) {
        warmUp();
    }
    
    private static void warmUp() {
        Calculator mul = (a, b) -> a * b;
        Calculator sub = (a, b) -> a - b;
        Calculator sum = (a, b) -> a + b;
        Calculator div = (a, b) -> a / b;
        List<Calculator> calcs = new ArrayList<>();
        calcs.add(mul);
        calcs.add(sub);
        calcs.add(div);
        calcs.add(sum);

        for (Calculator calculator : calcs) {
            System.out.println(calculator.calculate(10, 5));
        }
    }
}
///////////////////
public class Multiply implements Calculator {

    @Override
    public int calculate(int a, int b) {
        return a * b;
    }
    
}
///////////////////
public enum Operations {
    SUM, SUB, DIV, MUL
}
/////////////////////
@FunctionalInterface
public interface TwoNumbers {
    double twoNumbers(int i, int j, Operations operation);
}[/java]
 
MoxxiManagarm

MoxxiManagarm

Jetzt ist diese Seite auf einmal total unperformant. Spoilers wären besser gewesen dann muss nicht alles gerendered werden
 
mihe7

mihe7

private String path = "./src/pokemon/pokedex.csv";
Keine gute Idee, das src-Verzeichnis existiert ja nur im Projekt. Verwende eine Ressource (s. z. B. Class#getResourceAsStream). BTW: der BufferedReader kann Dir mit lines() einen Stream liefern, dann kannst Du Dir die Schleife auch sparen.
 
Thema: 

Java Code drüberlesen - sieht das richtig aus?

Passende Stellenanzeigen aus deiner Region:
Anzeige

Neue Themen

Anzeige

Anzeige
Oben