OOP exercise. Simple commerce system

Very basic OOP exercise.
Creating Product class, that will be the base for further inheritance, and which can not be instantiated. This class is inherited by two classes that represent specific groups of products: Chocolate and Wine. 
Each product has certain properties. Also, each product also has a method for calculating the price, which is calculated by increasing the basic price by the amount of the tax. Tax (VAT) for each product is 20% and this is a data that is constant and will not change.
However, products from the wine group have an additional tax as they belong to the group alcoholic beverages and it amounts to 10% of the price already increased for the amount of VAT. And this is it data that is constant and will not change. Because of this, it is necessary to redefine the method for calculating the price only in the Wine class. In addition, the Wine class should have an attribute that defines volume of the bottles, and the class Chocolate attribute that defines weight.
In Chocolate and Wine classes, it is necessary to make parametrizations Constructors for creating objects.
It is also necessary to redefine the toString method in all classes.
In the end it is necessary to create one object of these classes in the Test class and to output product information, as well as the amount of the final price defined through the method for calculating the price. For a basic price to take
Arbitrary amount.
 


Created on: Dec 26, 2016 

Product.java
1:  public abstract class Product {  
2:      
3:    String productName;  
4:    String barKod;  
5:    double basicPrice;  
6:      
7:      
8:    double racunCene() {  
9:        
10:      final double TAX = 20 * basicPrice / 100;   
11:      return basicPrice + TAX;   
12:        
13:    }  
14:      
15:  }  




Wine.java
1:  public class Wine extends Product {  
2:      
3:    double bottleVolume;  
4:      
5:    Wine ( String productName, String barKod, double basicPrice,   
6:        double bottleVolume ) {  
7:        
8:      this.productName = productName;  
9:      this.barKod = barKod;  
10:      this.basicPrice = basicPrice;  
11:      this.bottleVolume = bottleVolume;  
12:        
13:    }  
14:      
15:    @Override  
16:    public String toString() {  
17:        
18:      return "Wine " + productName + " - " + barKod + " - " +   
19:        "Bottle volume: " + bottleVolume + " l" + " - ";  
20:        
21:    }  
22:      
23:    @Override  
24:    double racunCene() {  
25:        
26:      final double TAX = 20 * basicPrice / 100;  
27:      double price = basicPrice + TAX;  
28:      return price + price / 10;             
29:        
30:    }    
31:      
32:  }  

Chocolate.java
1:  public class Chocolate extends Product {  
2:      
3:    double weight;  
4:      
5:      
6:    Chocolate( String productName, String barKod, double basicPrice,  
7:        double weight ) {  
8:        
9:      this.productName = productName;  
10:      this.barKod = barKod;  
11:      this.basicPrice = basicPrice;  
12:      this.weight = weight;  
13:        
14:    }  
15:      
16:    @Override  
17:    public String toString(){  
18:        
19:      return "Chocolate " + productName + " - " + barKod + " - " +   
20:          "Weight: " + weight + " gr." + " - ";  
21:        
22:    }  
23:      
24:  }  

Test.java
1:  /**  
2:   * @author Djordje Gavrilovic  
3:   * Dec 26, 2016  
4:   */  
5:    
6:  public class Test {  
7:    
8:    public static void main(String[] args) {  
9:        
10:      Chocolate choco = new Chocolate ( "Milka", "0123444589", 270.90, 300.00 );  
11:      System.out.print ( choco.toString() );  
12:      System.out.println ( " Price: " + choco.racunCene() + " din." );  
13:        
14:      Wine vince = new Wine ( "Medjas", "6745362718", 320.99, 0.75 );  
15:      System.out.print ( vince.toString() );  
16:      System.out.println ( " Price: " + vince.racunCene() + " din." );  
17:        
18:    }  
19:      
20:  }  

 

Comments

  1. Watch A Caucasian Asian Girl Video - Videodl.cc
    Find out more about Asian Girl's YouTube youtube mp3 channel. Find great videos and the best ones at VideoL.cc. Watch original videos.

    ReplyDelete

Post a Comment