Skip to content

Commit

Permalink
Notebook class
Browse files Browse the repository at this point in the history
  • Loading branch information
kacper-cholewinski committed Nov 14, 2024
1 parent 89abd48 commit 5f5e58f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
17 changes: 11 additions & 6 deletions kodilla-intro/src/main/java/FirstClass.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
public class FirstClass { // [1]
public static void main(String[] args) { // [2]
System.out.println("Hello from FirstClass!"); // [3]

String greeting = "Hello from FirstClass!";
System.out.println(greeting);
public class FirstClass {
public static void main(String[] args) {
Notebook notebook = new Notebook(600, 1000);
System.out.println(notebook.weight + " " + notebook.price);
notebook.checkPrice();
Notebook heavyNotebook = new Notebook(2000, 1500);
System.out.println(heavyNotebook.weight + " " + heavyNotebook.price);
heavyNotebook.checkPrice();
Notebook oldNotebook = new Notebook(1600, 500);
System.out.println(oldNotebook.weight + " " + oldNotebook.price);
oldNotebook.checkPrice();
}
}
16 changes: 16 additions & 0 deletions kodilla-intro/src/main/java/Notebook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class Notebook {
int weight;
int price;
public Notebook(int weight, int price) {
this.weight = weight;
this.price = price;
}

public void checkPrice() {
if (price < 900) {
System.out.println("This notebook is cheap");
} else {
System.out.println("This notebook is quite expensive");
}
}
}

0 comments on commit 5f5e58f

Please sign in to comment.