Advertisement
Boyan5

OOP 4

Nov 2nd, 2021
689
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.00 KB | None | 0 0
  1. public class Test {
  2.     public static void main(String[] args) {
  3.         TVs tv = new TVs("Sony", "X7000G 49", 15, "1", 3000);
  4.         Book book = new Book("Walter Isaacson","Steve Jobs",40, "2");
  5.         tv.discountTV(9);
  6.         book.discountBook(15);
  7.         tv.powerConsummation(5);
  8.  
  9.     }
  10. }
  11.  
  12. public class Stocks {
  13.     String id;
  14.     double price;
  15.  
  16.     public Stocks() {
  17.         this.id = id;
  18.         this.price = price;
  19.     }
  20.  
  21.     public Stocks(String id, double price) {
  22.         this.id = id;
  23.         this.price = price;
  24.     }
  25.  
  26.  
  27.     public String getId() {
  28.         return this.id;
  29.     }
  30.  
  31.     public void setId(String id) {
  32.         this.id = id;
  33.     }
  34.  
  35.     public double getPrice() {
  36.         return this.price;
  37.     }
  38.  
  39.     public void setPrice(double price){
  40.         this.price = price;
  41.     }
  42. }
  43.  
  44.  
  45. public class TVs extends Stocks {
  46.     String brand;
  47.     String model;
  48.     double power;
  49.  
  50.     public TVs() {
  51.         super();
  52.         this.brand = brand;
  53.         this.model = model;
  54.         this.power = 0;
  55.     }
  56.  
  57.     public TVs(String brand, String model, double power, String id, double price) {
  58.         super(id, price);
  59.         this.brand = brand;
  60.         this.model = model;
  61.         this.power = power;
  62.     }
  63.  
  64.     public String getBrand() {
  65.         return this.brand;
  66.     }
  67.  
  68.     public void setBrand(String brand) {
  69.         this.brand = brand;
  70.     }
  71.  
  72.     public String getModel() {
  73.         return this.model;
  74.     }
  75.  
  76.     public void setModel(String model) {
  77.         this.model = model;
  78.     }
  79.  
  80.     public double getPower() {
  81.         return this.power;
  82.     }
  83.  
  84.     public void setPower(double power) {
  85.         this.power = power;
  86.     }
  87.  
  88.     public void discountTV(double discount){
  89.         double price = this.price;
  90.         double finalprice = price;
  91.         finalprice = price - (finalprice * discount / 100);
  92.         System.out.println(finalprice);
  93.     }
  94.  
  95.     public void powerConsummation(double hours) {
  96.         double power = this.power;
  97.         double consummation = power * (hours / 1000);
  98.         System.out.println("Power consumed per day: " + consummation);
  99.     }
  100. }
  101.  
  102.  
  103. public class Book extends Stocks {
  104.     String author;
  105.     String title;
  106.  
  107.     public Book() {
  108.         super();
  109.         this.author = author;
  110.         this.title = title;
  111.     }
  112.  
  113.     public Book(String author, String title, double price, String id) {
  114.         super(id, price);
  115.         this.author = author;
  116.         this.title = title;
  117.     }
  118.  
  119.     public void setAuthor(String author) {
  120.         this.author = author;
  121.     }
  122.  
  123.     public String getAuthor() {
  124.         return this.author;
  125.     }
  126.  
  127.     public void setTitle(String title) {
  128.         this.title = title;
  129.     }
  130.  
  131.     public String getTitle() {
  132.         return this.title;
  133.     }
  134.  
  135.     public void discountBook(double discount){
  136.         double price = this.price;
  137.         double finalprice = price;
  138.         finalprice = price - (finalprice * discount / 100);
  139.         System.out.println(finalprice);
  140.     }
  141. }
  142.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement