Skip to content

Commit

Permalink
inheritance and inheritance.homework packages
Browse files Browse the repository at this point in the history
  • Loading branch information
kacper-cholewinski committed Nov 20, 2024
1 parent 4c63cde commit d44fd2d
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 0 deletions.
19 changes: 19 additions & 0 deletions kodilla-basic-tests/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
plugins {
id 'java'
}

group = 'com.kodilla'
version = '1.0-SNAPSHOT'

repositories {
mavenCentral()
}

dependencies {
testImplementation platform('org.junit:junit-bom:5.10.0')
testImplementation 'org.junit.jupiter:junit-jupiter'
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.kodilla.inheritance;

public class Application {
public static void main(String[] args) {
Car car = new Car(4, 5);
car.turnOnLights();

Convertible convertible = new Convertible(4, 2);
convertible.turnOnLights();
System.out.println(convertible.getSeats());
}
}
31 changes: 31 additions & 0 deletions kodilla-basic-tests/src/main/java/com/kodilla/inheritance/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.kodilla.inheritance;

public class Car {
private int wheels;
private int seats;

public Car(int wheels, int seats) {
this.wheels = wheels;
this.seats = seats;
}

public int getWheels() {
return wheels;
}

public int getSeats() {
return seats;
}

public void turnOnLights() {
System.out.println("Lights were turned on");
}

public void openDoors() {
System.out.println("Opening 4 doors");
}

public void displayNumberOfSeats() {
System.out.println("Number of seats: " + seats);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.kodilla.inheritance;

public class Convertible extends Car {

public Convertible(int wheels, int seats) {
super(wheels, seats);
System.out.println("Convertible constructor");
}

public void openRoof() {
System.out.println("Opening roof...");
}

public void closeRoof() {
System.out.println("Closing roof...");
}

@Override
public void openDoors() {
System.out.println("Opening 2 doors");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.kodilla.inheritance.homework;

public class Application {
public static void main(String[] args) {
OperatingSystem operatingSystem = new OperatingSystem(2005);
operatingSystem.turnOn();
operatingSystem.turnOff();
operatingSystem.displayReleaseYear();

Windows10 win10 = new Windows10();
win10.turnOn();
win10.turnOff();
win10.displayReleaseYear();

Windows11 win11 = new Windows11();
win11.turnOn();
win11.turnOff();
win11.displayReleaseYear();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.kodilla.inheritance.homework;

public class OperatingSystem {
private int releaseYear;

public OperatingSystem(int releaseYear) {
this.releaseYear = releaseYear;
}

public void turnOn() {
System.out.println("turning system on...");
}

public void turnOff() {
System.out.println("turning system off...");
}

public void displayReleaseYear() {
System.out.println("this system's release year: " + releaseYear);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.kodilla.inheritance.homework;

public class Windows10 extends OperatingSystem {
public Windows10() {
super(2015);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.kodilla.inheritance.homework;

public class Windows11 extends OperatingSystem {
public Windows11() {
super(2021);
}
}

0 comments on commit d44fd2d

Please sign in to comment.