Created
November 25, 2019 21:14
-
-
Save bennypr0fane/2eedffdd1932b54a7d1a16be1e4311fd to your computer and use it in GitHub Desktop.
Book practice class
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
<html>Simple <b>Java</b> application that includes a class with <code>main()</code> method</html> |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="Encoding"> | |
<file url="PROJECT" charset="UTF-8" /> | |
</component> | |
</project> |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ProjectKey"> | |
<option name="state" value="project://e2804f05-5315-4fc6-a121-c522a6c26470" /> | |
</component> | |
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11.0.4 (3)" project-jdk-type="JavaSDK"> | |
<output url="file://$PROJECT_DIR$/out" /> | |
</component> | |
</project> |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ProjectModuleManager"> | |
<modules> | |
<module fileurl="file://$PROJECT_DIR$/ES07_Buch.iml" filepath="$PROJECT_DIR$/ES07_Buch.iml" /> | |
</modules> | |
</component> | |
</project> |
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
<template> | |
<input-field default="com.company">IJ_BASE_PACKAGE</input-field> | |
</template> |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ChangeListManager"> | |
<list default="true" id="8e68e4b5-178a-4229-be79-3fd737d5c0e0" name="Default Changelist" comment="" /> | |
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> | |
<option name="SHOW_DIALOG" value="false" /> | |
<option name="HIGHLIGHT_CONFLICTS" value="true" /> | |
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> | |
<option name="LAST_RESOLUTION" value="IGNORE" /> | |
</component> | |
<component name="FileTemplateManagerImpl"> | |
<option name="RECENT_TEMPLATES"> | |
<list> | |
<option value="Class" /> | |
<option value="Interface" /> | |
</list> | |
</option> | |
</component> | |
<component name="ProjectId" id="1Tw5dQUuhD8V9bYS7s9NzCWXbzP" /> | |
<component name="PropertiesComponent"> | |
<property name="last_opened_file_path" value="$PROJECT_DIR$" /> | |
</component> | |
<component name="RunDashboard"> | |
<option name="ruleStates"> | |
<list> | |
<RuleState> | |
<option name="name" value="ConfigurationTypeDashboardGroupingRule" /> | |
</RuleState> | |
<RuleState> | |
<option name="name" value="StatusDashboardGroupingRule" /> | |
</RuleState> | |
</list> | |
</option> | |
</component> | |
<component name="RunManager"> | |
<configuration name="Main" type="Application" factoryName="Application" temporary="true"> | |
<option name="MAIN_CLASS_NAME" value="Main" /> | |
<module name="ES07_Buch" /> | |
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" /> | |
<RunnerSettings RunnerId="Run" /> | |
<ConfigurationWrapper RunnerId="Run" /> | |
<method v="2"> | |
<option name="Make" enabled="true" /> | |
</method> | |
</configuration> | |
<recent_temporary> | |
<list> | |
<item itemvalue="Application.Main" /> | |
</list> | |
</recent_temporary> | |
</component> | |
<component name="SvnConfiguration"> | |
<configuration /> | |
</component> | |
<component name="TaskManager"> | |
<task active="true" id="Default" summary="Default task"> | |
<changelist id="8e68e4b5-178a-4229-be79-3fd737d5c0e0" name="Default Changelist" comment="" /> | |
<created>1574358403147</created> | |
<option name="number" value="Default" /> | |
<option name="presentableId" value="Default" /> | |
<updated>1574358403147</updated> | |
</task> | |
<servers /> | |
</component> | |
</project> |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<module type="JAVA_MODULE" version="4"> | |
<component name="NewModuleRootManager" inherit-compiler-output="true"> | |
<exclude-output /> | |
<content url="file://$MODULE_DIR$"> | |
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | |
</content> | |
<orderEntry type="inheritedJdk" /> | |
<orderEntry type="sourceFolder" forTests="false" /> | |
</component> | |
</module> | |
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; | |
public class Buch { | |
private String autor; | |
private Index index; | |
private ArrayList<Kapitel> kapitelliste = new ArrayList<>(); | |
private String klappentext; | |
private String titel; | |
private Inhaltsverzeichnis inhaltsverzeichnis; | |
public Buch (String autor, ArrayList<Kapitel> kapitelliste, String klappentext, String titel) { | |
this.autor = autor; | |
this.kapitelliste = kapitelliste; | |
//this.index = index; | |
this.klappentext = klappentext; | |
this.titel = titel; | |
} | |
public String getAutor() { | |
return autor; | |
} | |
public void setAutor(String autor) { | |
this.autor = autor; | |
} | |
public Index getIndex() { | |
return index; | |
} | |
public void setIndex(Index index) { | |
this.index = index; | |
} | |
public String getKlappentext() { | |
return klappentext; | |
} | |
public void setKlappentext(String klappentext) { | |
this.klappentext = klappentext; | |
} | |
public String getTitel() { | |
return titel; | |
} | |
public void setTitel(String titel) { | |
this.titel = titel; | |
} | |
public Inhaltsverzeichnis getInhaltsverzeichnis() { | |
return inhaltsverzeichnis; | |
} | |
public void setInhaltsverzeichnis(Inhaltsverzeichnis inhaltsverzeichnis) { | |
this.inhaltsverzeichnis = inhaltsverzeichnis; | |
} | |
public void addKapitel(Kapitel einKapitel) { | |
this.kapitelliste.add(einKapitel); | |
} | |
public Seite getSeiteViaSeitennummer (int seitennummer) { | |
for (Kapitel kapitel : this.kapitelliste) { | |
for ( Seite seite : kapitel.getSeiten()) { | |
if (seite.getSeitennummer() == seitennummer) { | |
return seite; | |
} | |
} | |
} | |
System.out.println("Seite existiert nicht!"); | |
return null; | |
} | |
public Seite getSeiteViaIndexBezeichnung (String bezeichnung) { | |
for (IndexEintrag eintrag : this.index.getAuflistung()) { | |
if (eintrag.getBezeichnung().equals(bezeichnung)) { | |
int seitennummer = eintrag.getPosition(); | |
return getSeiteViaSeitennummer(seitennummer); | |
} | |
} | |
return null; | |
} | |
public Seite getSeiteViaIndexEintrag(IndexEintrag eintrag) { | |
int seitennummer = eintrag.getPosition(); | |
return getSeiteViaSeitennummer(seitennummer); | |
} | |
} |
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; | |
public class Index { | |
private ArrayList<IndexEintrag> auflistung = new ArrayList<>(); | |
public Index(ArrayList<IndexEintrag> auflistung) { | |
this.auflistung = auflistung; | |
} | |
public ArrayList<IndexEintrag> getAuflistung() { | |
return auflistung; | |
} | |
public void addIndexEintrag (IndexEintrag eintrag) { | |
this.auflistung.add(eintrag); | |
} | |
public void read() { | |
for (IndexEintrag eintrag : auflistung) { | |
System.out.println(eintrag.getBezeichnung()); | |
System.out.println(eintrag.getPosition()); | |
} | |
} | |
} |
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 IndexEintrag { | |
private String bezeichnung; | |
private int position; | |
public IndexEintrag(String bezeichnung, int position) { | |
this.bezeichnung = bezeichnung; | |
this.position = position; | |
} | |
public String getBezeichnung() { | |
return bezeichnung; | |
} | |
public void setBezeichnung(String bezeichnung) { | |
this.bezeichnung = bezeichnung; | |
} | |
public int getPosition() { | |
return position; | |
} | |
public void setPosition(int position) { | |
this.position = position; | |
} | |
} |
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; | |
public class Inhaltsverzeichnis implements read { | |
private ArrayList<Kapitel> kapiteluebersicht; | |
public Inhaltsverzeichnis(ArrayList<Kapitel> kapiteluebersicht) { | |
this.kapiteluebersicht = kapiteluebersicht; | |
} | |
public void addKapitel (Kapitel kapitel) { | |
this.kapiteluebersicht.add(kapitel); | |
} | |
public void read () { | |
for (Kapitel kapitel : this.kapiteluebersicht) { | |
System.out.println(kapitel.getNummer()); | |
System.out.println(kapitel.getUeberschrift()); | |
System.out.println(kapitel.getPositionImBuch()); | |
} | |
} | |
} |
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; | |
public class Kapitel implements read { | |
private float nummer; | |
private int positionImBuch; | |
private ArrayList<Seite> seiten; | |
private int seitenanzahl; | |
private String ueberschrift; | |
public Kapitel(int positionImBuch, ArrayList<Seite> seiten, | |
int seitenanzahl) { | |
this.positionImBuch = positionImBuch; | |
this.seiten = new ArrayList<>(); | |
this.seitenanzahl = seitenanzahl; | |
} | |
public float getNummer() { | |
return nummer; | |
} | |
public void setNummer(float nummer) { | |
this.nummer = nummer; | |
} | |
public int getPositionImBuch() { | |
return positionImBuch; | |
} | |
public void setPositionImBuch(int positionImBuch) { | |
this.positionImBuch = positionImBuch; | |
} | |
public int getSeitenanzahl() { | |
return seitenanzahl; | |
} | |
public void setSeitenanzahl(int seitenanzahl) { | |
this.seitenanzahl = seitenanzahl; | |
} | |
public String getUeberschrift() { | |
return ueberschrift; | |
} | |
public void setUeberschrift(String ueberschrift) { | |
this.ueberschrift = ueberschrift; | |
} | |
public ArrayList<Seite> getSeiten() { | |
return seiten; | |
} | |
public void addSeite(Seite seite) { | |
this.seiten.add(seite); | |
} | |
public void read() { | |
System.out.println(this.nummer); | |
System.out.println(this.ueberschrift); | |
} | |
} |
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; | |
public class Main { | |
public static void main(String[] args) { | |
IndexEintrag eintrag1 = new IndexEintrag("Datenstruktur", 3); | |
IndexEintrag eintrag2 = new IndexEintrag("Parameter", 2); | |
IndexEintrag eintrag3 = new IndexEintrag("asynchron", 2); | |
ArrayList<IndexEintrag> auflistung1 = new ArrayList<>(); | |
Index index1 = new Index(auflistung1); | |
auflistung1.addIndexeintrag(eintrag1); | |
auflistung1.add(eintrag2); | |
auflistung1.add(eintrag3); | |
Seite seite1 = new Seite(1, "blabla."); | |
Seite seite2 = new Seite(2, "blabla?"); | |
Seite seite3 = new Seite(3, "blabla!"); | |
Seite seite4 = new Seite(4, "blabla..."); | |
ArrayList<Seite> seitenlisteKap1 = new ArrayList<>(); | |
seitenlisteKap1.addSeite(seite1); | |
seitenlisteKap1.add(seite2); | |
ArrayList<Seite> seitenlisteKap2 = new ArrayList<>(); | |
seitenlisteKap2.add(seite3); | |
seitenlisteKap2.add(seite4); | |
Kapitel kap1 = new Kapitel(1, seitenlisteKap1, 2); | |
Kapitel kap2 = new Kapitel(2, seitenlisteKap2, 2); | |
ArrayList<Kapitel> kapitellisteJavaIst = new ArrayList<>(); | |
kapitellisteJavaIst.add(kap1); | |
kapitellisteJavaIst.add(kap2); | |
ArrayList<Kapitel> kapiteluebersicht1 = new ArrayList<>(); | |
kapiteluebersicht1.add(kap1); | |
kapiteluebersicht1.add(kap2); | |
Inhaltsverzeichnis verzeichnisJavaIst = new Inhaltsverzeichnis(kapiteluebersicht1); | |
Buch sehrKurz = new Buch ("Benjamin", kapitellisteJavaIst, "Ein Klassiker! Unbedingt lesen!", "Java ist..."); | |
sehrKurz.setIndex(index1); | |
sehrKurz.setInhaltsverzeichnis(verzeichnisJavaIst); | |
System.out.println(sehrKurz.getTitel()); | |
System.out.println(sehrKurz.getSeiteViaSeitennummer(2)); | |
} | |
} |
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 interface read { | |
void read(); | |
} |
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 Seite implements read{ | |
private int seitennummer; | |
private String text; | |
public Seite(int seitennummer, String text) { | |
this.seitennummer = seitennummer; | |
this.text = text; | |
} | |
public int getSeitennummer() { | |
return seitennummer; | |
} | |
public void setSeitennummer(int seitennummer) { | |
this.seitennummer = seitennummer; | |
} | |
public String getText() { | |
return text; | |
} | |
public void setText(String text) { | |
this.text = text; | |
} | |
public void read() { | |
System.out.println(this.text); | |
System.out.println(this.seitennummer); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment