-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ru.j4j.pojo; | ||
|
||
public class Book { | ||
private final String nameBook; | ||
private final int countPages; | ||
|
||
public Book(String nameBook, int countPages) { | ||
this.nameBook = nameBook; | ||
this.countPages = countPages; | ||
} | ||
|
||
public String getNameBook() { | ||
return nameBook; | ||
} | ||
|
||
public int getCountPages() { | ||
return countPages; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ru.j4j.pojo; | ||
|
||
public class Library { | ||
public static void main(String[] args) { | ||
Book one = new Book("Clean code", 800); | ||
Book two = new Book("Java", 1600); | ||
Book three = new Book("PMBOK", 1200); | ||
Book four = new Book("SCRUM", 15200); | ||
|
||
Book[] books = new Book[4]; | ||
books[0] = one; | ||
books[1] = two; | ||
books[2] = three; | ||
books[3] = four; | ||
|
||
for (Book book : books) { | ||
System.out.printf("Book: %s, pages: %s;" + System.lineSeparator(), book.getNameBook(), book.getCountPages()); | ||
} | ||
System.out.println("Replace book with index 0 and 3"); | ||
Book temp = books[0]; | ||
books[0] = books[3]; | ||
books[3] = temp; | ||
|
||
for (Book book : books) { | ||
System.out.printf("Book: %s, pages: %s" + System.lineSeparator(), book.getNameBook(), book.getCountPages()); | ||
} | ||
System.out.println("Find book \"Clean code\""); | ||
for (Book book : books) { | ||
if (book.getNameBook().equals("Clean code")) { | ||
System.out.printf("Book: %s, pages: %s" + System.lineSeparator(), book.getNameBook(), book.getCountPages()); | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ru.j4j.pojo; | ||
|
||
public class Product { | ||
private final String name; | ||
private final int count; | ||
|
||
public Product(String name, int count) { | ||
this.name = name; | ||
this.count = count; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public int getCount() { | ||
return count; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package ru.j4j.pojo; | ||
|
||
public class Store { | ||
public static void main(String[] args) { | ||
Product milk = new Product("Milk", 10); | ||
Product bread = new Product("Bread", 4); | ||
Product egg = new Product("Egg", 19); | ||
|
||
Product[] prods = new Product[3]; | ||
prods[0] = milk; | ||
prods[1] = bread; | ||
prods[2] = egg; | ||
|
||
for (Product pr : prods) { | ||
System.out.println(pr.getName() + " - " + pr.getCount()); | ||
} | ||
System.out.println("Replace milk to oil."); | ||
Product oil = new Product("Oil", 11); | ||
prods[0] = oil; | ||
for (Product pr : prods) { | ||
System.out.println(pr.getName() + " - " + pr.getCount()); | ||
} | ||
System.out.println("Shown only product.count > 10"); | ||
for (Product pr : prods) { | ||
if (pr.getCount() > 10) { | ||
System.out.println(pr.getName() + " - " + pr.getCount()); | ||
} | ||
} | ||
} | ||
} |