Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Zadanie 1
- import java.util.ArrayList;
- import java.util.List;
- class Product {
- private double price;
- public Product(double price) {
- this.price = price;
- }
- double calculateBargainPrice() {
- return price;
- }
- public double getPrice() {
- return price;
- }
- public void setPrice(double price) {
- this.price = price;
- }
- }
- class Vehicle extends Product {
- private String brand;
- private String model;
- public Vehicle(String brand, String model, double price) {
- super(price);
- this.brand = brand;
- this.model = model;
- }
- @Override
- public double calculateBargainPrice() {
- return super.calculateBargainPrice() * .95f;
- }
- @Override
- public String toString() {
- return "Vehicle{" +
- "brand='" + brand + '\'' +
- ", model='" + model + '\'' +
- '}';
- }
- }
- class Car extends Vehicle {
- private String carBody;
- public Car(String brand, String model, double price, String carBody) {
- super(brand, model, price);
- this.carBody = carBody;
- }
- @Override
- public double calculateBargainPrice() {
- return super.calculateBargainPrice() * 0.85f;
- }
- public String getCarBody() {
- return carBody;
- }
- public void setCarBody(String carBody) {
- this.carBody = carBody;
- }
- }
- class Motorcyce extends Vehicle {
- private String typeOfDriver;
- public Motorcyce(String brand, String model, double price, String typeOfDriver) {
- super(brand, model, price);
- this.typeOfDriver = typeOfDriver;
- }
- @Override
- public double calculateBargainPrice() {
- return super.calculateBargainPrice() * .9f;
- }
- public String getTypeOfDriver() {
- return typeOfDriver;
- }
- public void setTypeOfDriver(String typeOfDriver) {
- this.typeOfDriver = typeOfDriver;
- }
- }
- public class Main {
- public static void main(String[] args) {
- List<Product> list = new ArrayList<>();
- list.add(new Vehicle("Brand", "Model", 10333));
- list.add(new Car("Brand", "Model", 10333, "CarBody"));
- list.add(new Motorcyce("Brand", "Model", 10333, "TypeOfDriver"));
- list.forEach(System.out::print);
- }
- }
- Zadanie 2
- import java.util.ArrayList;
- import java.util.List;
- import java.util.function.Supplier;
- abstract class Product {
- private double price;
- public Product(double price) {
- this.price = price;
- }
- abstract double calculateBargainPrice();
- public double getPrice() {
- return price;
- }
- public void setPrice(double price) {
- this.price = price;
- }
- }
- abstract class Vehicle extends Product {
- private String brand;
- private String model;
- public Vehicle(String brand, String model, double price) {
- super(price);
- this.brand = brand;
- this.model = model;
- }
- @Override
- public String toString() {
- return "Vehicle{" +
- "brand='" + brand + '\'' +
- ", model='" + model + '\'' +
- '}';
- }
- }
- class Car extends Vehicle {
- private String carBody;
- public Car(String brand, String model, double price, String carBody) {
- super(brand, model, price);
- this.carBody = carBody;
- }
- @Override
- double calculateBargainPrice() {
- return calculateBargainPrice() * 0.85f;
- }
- public String getCarBody() {
- return carBody;
- }
- public void setCarBody(String carBody) {
- this.carBody = carBody;
- }
- }
- class Motorcyce extends Vehicle {
- private String typeOfDriver;
- public Motorcyce(String brand, String model, double price, String typeOfDriver) {
- super(brand, model, price);
- this.typeOfDriver = typeOfDriver;
- }
- @Override
- double calculateBargainPrice() {
- return calculateBargainPrice() * 0.9f;
- }
- public String getTypeOfDriver() {
- return typeOfDriver;
- }
- public void setTypeOfDriver(String typeOfDriver) {
- this.typeOfDriver = typeOfDriver;
- }
- }
- public class Main {
- public static void main(String[] args) {
- List<Product> list = new ArrayList<>();
- list.add(new Vehicle("Brand", "Model", 10333) {
- @Override
- double calculateBargainPrice() {
- return 1000;
- }
- });
- list.add(new Car("Brand", "Model", 10333, "CarBody"));
- list.add(new Motorcyce("Brand", "Model", 10333, "TypeOfDriver"));
- list.forEach(System.out::print);
- }
- }
- Zadanie 3
- import java.util.ArrayList;
- import java.util.List;
- class Product implements ProductInterface {
- private double price;
- public Product(double price) {
- this.price = price;
- }
- @Override
- public double calculateBargainPrice() {
- return price;
- }
- public double getPrice() {
- return price;
- }
- public void setPrice(double price) {
- this.price = price;
- }
- }
- class Vehicle extends Product implements VehicleInterface {
- private String brand;
- private String model;
- public Vehicle(String brand, String model, double price) {
- super(price);
- this.brand = brand;
- this.model = model;
- }
- @Override
- public double calculateBargainPrice() {
- return super.calculateBargainPrice() * .95f;
- }
- @Override
- public String toString() {
- return "Vehicle{" +
- "brand='" + brand + '\'' +
- ", model='" + model + '\'' +
- '}';
- }
- @Override
- public String getBrand() {
- return brand;
- }
- @Override
- public String getModel() {
- return model;
- }
- }
- class Car extends Vehicle {
- private String carBody;
- public Car(String brand, String model, double price, String carBody) {
- super(brand, model, price);
- this.carBody = carBody;
- }
- @Override
- public double calculateBargainPrice() {
- return super.calculateBargainPrice() * 0.85f;
- }
- public String getCarBody() {
- return carBody;
- }
- public void setCarBody(String carBody) {
- this.carBody = carBody;
- }
- }
- class Motorcyce extends Vehicle {
- private String typeOfDriver;
- public Motorcyce(String brand, String model, double price, String typeOfDriver) {
- super(brand, model, price);
- this.typeOfDriver = typeOfDriver;
- }
- @Override
- public double calculateBargainPrice() {
- return super.calculateBargainPrice() * .9f;
- }
- public String getTypeOfDriver() {
- return typeOfDriver;
- }
- public void setTypeOfDriver(String typeOfDriver) {
- this.typeOfDriver = typeOfDriver;
- }
- }
- interface ProductInterface {
- double calculateBargainPrice();
- double getPrice();
- void setPrice(double price);
- }
- interface VehicleInterface extends ProductInterface {
- String getBrand();
- String getModel();
- }
- public class Main {
- public static void main(String[] args) {
- List<ProductInterface> list = new ArrayList<>();
- list.add(new Vehicle("Brand", "Model", 10333));
- list.add(new Car("Brand", "Model", 10333, "CarBody"));
- list.add(new Motorcyce("Brand", "Model", 10333, "TypeOfDriver"));
- list.forEach(System.out::print);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement