Last active
April 24, 2018 14:54
-
-
Save d630/5e8ae1b1203fdcd4e52397908c17e4f3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package article; | |
public class Article { | |
private int artikelID; | |
private int artikelPreis; | |
private int verkaufsmenge; | |
public Article(int[] a) { | |
this.artikelID = a[0]; | |
this.artikelPreis = a[1]; | |
this.verkaufsmenge = a[2]; | |
} | |
public void printArticle() { | |
System.out.println(this.artikelID + " " + this.artikelPreis + " " + this.verkaufsmenge); | |
} | |
public void printUmsatz() { | |
System.out.println("Artikel-Nummer: " + this.artikelID + "\nUmsatz: " + (this.artikelPreis * this.verkaufsmenge) + "\n"); | |
} | |
} |
This file contains hidden or 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
package article; | |
import java.io.FileNotFoundException; | |
import java.io.FileReader; | |
import java.util.ArrayList; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.util.Arrays; | |
import java.util.ListIterator; | |
public class Main { | |
static void readArticles(ArrayList<Article> arrayList, String file) { | |
try { | |
BufferedReader br = new BufferedReader(new FileReader(file)); | |
String str; | |
while ((str = br.readLine()) != null) { | |
if (!str.trim().isEmpty()) { | |
//System.out.println(str.split("\\s+")); | |
// Needs exactly a line like: [0-9]+ [0-9]+ [0-9]+ | |
arrayList.add(new Article(Arrays.stream(str.split("\\s+")).mapToInt(Integer::parseInt).toArray())); | |
} | |
} | |
br.close(); | |
} catch (FileNotFoundException e) { | |
} catch (IOException e) { | |
} | |
} | |
static void printArticles(ArrayList<Article> arrayList) { | |
ListIterator<Article> li = arrayList.listIterator(); | |
while (li.hasNext()) { | |
li.next().printUmsatz(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment