Last active
September 7, 2017 14:04
-
-
Save SKocur/3c8158ab118afd55c74dc7a3fac6e52d to your computer and use it in GitHub Desktop.
Zadanie z informatyki na 08.09.2017
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.Scanner; | |
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.util.ArrayList; | |
import java.util.List; | |
class lista_program { | |
static List<BookPOJO> books; | |
public static void main(String[] args){ | |
books = new ArrayList<BookPOJO>(); | |
try { | |
File file = new File("lista.txt"); | |
Scanner scanner = new Scanner(file); | |
//Ignore first line of file | |
scanner.nextLine(); | |
while(scanner.hasNext()) { | |
String[] bookData = scanner.nextLine().split(";"); | |
BookPOJO book = new BookPOJO(); | |
book.setAuthor(bookData[2]); | |
book.setBinding(bookData[1]); | |
book.setPrice(bookData[5]); | |
book.setPublisher(bookData[3]); | |
book.setTitle(bookData[0]); | |
book.setYear(Integer.parseInt(bookData[4])); | |
books.add(book); | |
} | |
//titleOnS(); | |
//bookOlder2003(); | |
//bookThirdTask(); | |
//bookFourthTask(); | |
//bookFifthTask(); | |
//bookSixthTask(); | |
//bookSeventhTask(); | |
scanner.close(); | |
} catch (FileNotFoundException e) { | |
System.out.println("File not found!"); | |
} | |
} | |
static void bookSeventhTask() { | |
for(BookPOJO book : books) { | |
if((book.getYear() > 2002 && book.getYear() <= 2009) && (book.getPublisher().charAt(book.getPublisher().length() -2) == 'd' || | |
book.getPublisher().charAt(0) == 'S')) | |
System.out.println(book.toString()); | |
} | |
} | |
static void bookSixthTask() { | |
for(BookPOJO book : books) { | |
if(book.getTitle().charAt(0) == 'D' || book.getTitle().charAt(0) == 'Z') | |
System.out.println(book.getTitle()); | |
} | |
} | |
static void bookFifthTask() { | |
for(BookPOJO book : books) { | |
if((book.getYear() > 2006 && book.getYear() <= 2009) && book.getTitle().charAt(book.getTitle().length() - 2) == 'd') | |
System.out.println(book.getTitle()); | |
} | |
} | |
static void bookFourthTask() { | |
for(BookPOJO book : books) { | |
if(book.getYear() > 2000 && book.getYear() <= 2003) | |
System.out.println(book.getTitle()); | |
} | |
} | |
static void bookThirdTask() { | |
for(BookPOJO book : books) { | |
if(book.getTitle().charAt(1) == 'i' && book.getAuthor().charAt(0) == 'B') | |
System.out.println(book.getTitle()); | |
} | |
} | |
static void bookOlder2003() { | |
for(BookPOJO book : books) { | |
if(book.getYear() >= 2003) | |
System.out.println(book.getTitle()); | |
} | |
} | |
static void titleOnS() { | |
for(BookPOJO book : books) { | |
if(book.getTitle().charAt(0) == 'S') | |
System.out.println(book.getTitle()); | |
} | |
} | |
private static class BookPOJO { | |
String title = ""; | |
String binding = ""; | |
String author = ""; | |
String publisher = ""; | |
int year = 0; | |
String price = ""; | |
BookPOJO(){ } | |
// Getters and setters | |
private void setTitle(String title) { | |
this.title = title; | |
} | |
private String getTitle() { | |
return this.title; | |
} | |
private void setBinding(String binding) { | |
this.binding = binding; | |
} | |
private String getBinding() { | |
return this.binding; | |
} | |
private void setAuthor(String author) { | |
this.author = author; | |
} | |
private String getAuthor() { | |
return this.author; | |
} | |
private void setPublisher(String publisher) { | |
this.publisher = publisher; | |
} | |
private String getPublisher() { | |
return this.publisher; | |
} | |
private void setYear(int year) { | |
this.year = year; | |
} | |
private int getYear() { | |
return this.year; | |
} | |
private void setPrice(String price) { | |
this.price = price; | |
} | |
private String getPrice() { | |
return this.price; | |
} | |
public String toString() { | |
return this.title + "\n" + | |
this.binding + "\n" + | |
this.author + "\n" + | |
this.publisher + "\n" + | |
this.year + "\n" + | |
this.price + "\n"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment