Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test {
- public static void main(String[] args) {
- TVs tv = new TVs("Sony", "X7000G 49", 15, "1", 3000);
- Book book = new Book("Walter Isaacson","Steve Jobs",40, "2");
- tv.discountTV(9);
- book.discountBook(15);
- tv.powerConsummation(5);
- }
- }
- public class Stocks {
- String id;
- double price;
- public Stocks() {
- this.id = id;
- this.price = price;
- }
- public Stocks(String id, double price) {
- this.id = id;
- this.price = price;
- }
- public String getId() {
- return this.id;
- }
- public void setId(String id) {
- this.id = id;
- }
- public double getPrice() {
- return this.price;
- }
- public void setPrice(double price){
- this.price = price;
- }
- }
- public class TVs extends Stocks {
- String brand;
- String model;
- double power;
- public TVs() {
- super();
- this.brand = brand;
- this.model = model;
- this.power = 0;
- }
- public TVs(String brand, String model, double power, String id, double price) {
- super(id, price);
- this.brand = brand;
- this.model = model;
- this.power = power;
- }
- public String getBrand() {
- return this.brand;
- }
- public void setBrand(String brand) {
- this.brand = brand;
- }
- public String getModel() {
- return this.model;
- }
- public void setModel(String model) {
- this.model = model;
- }
- public double getPower() {
- return this.power;
- }
- public void setPower(double power) {
- this.power = power;
- }
- public void discountTV(double discount){
- double price = this.price;
- double finalprice = price;
- finalprice = price - (finalprice * discount / 100);
- System.out.println(finalprice);
- }
- public void powerConsummation(double hours) {
- double power = this.power;
- double consummation = power * (hours / 1000);
- System.out.println("Power consumed per day: " + consummation);
- }
- }
- public class Book extends Stocks {
- String author;
- String title;
- public Book() {
- super();
- this.author = author;
- this.title = title;
- }
- public Book(String author, String title, double price, String id) {
- super(id, price);
- this.author = author;
- this.title = title;
- }
- public void setAuthor(String author) {
- this.author = author;
- }
- public String getAuthor() {
- return this.author;
- }
- public void setTitle(String title) {
- this.title = title;
- }
- public String getTitle() {
- return this.title;
- }
- public void discountBook(double discount){
- double price = this.price;
- double finalprice = price;
- finalprice = price - (finalprice * discount / 100);
- System.out.println(finalprice);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement