atanasovetr

Nikola

Jan 20th, 2021
862
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.00 KB | None | 0 0
  1. class Drink {
  2.     protected String name;
  3.     protected int volumeInMl;
  4.     protected String color;
  5.     protected String tempStatus;
  6.  
  7.     public Drink(){
  8.  
  9.     }
  10.  
  11.     public Drink(String name, int volumeInMl, String color, String tempStatus) {
  12.         this.name = name;
  13.         this.volumeInMl = volumeInMl;
  14.         this.color = color;
  15.         this.tempStatus = tempStatus;
  16.     }
  17.  
  18.     public void drink(int drinkedMl){
  19.         this.volumeInMl -= drinkedMl;
  20.     }
  21.  
  22.     public void spill(int spilledMl){
  23.         this.volumeInMl -= spilledMl;
  24.     }
  25.  
  26.     public void pour(int pouredMl){
  27.         this.volumeInMl += pouredMl;
  28.     }
  29.  
  30.  
  31.     public String getName() {
  32.         return name;
  33.     }
  34.  
  35.     public void setName(String name) {
  36.         this.name = name;
  37.     }
  38.  
  39.     public int getVolumeInMl() {
  40.         return volumeInMl;
  41.     }
  42.  
  43.     public void setVolumeInMl(int volumeInMl) {
  44.         this.volumeInMl = volumeInMl;
  45.     }
  46.  
  47.     public String getColor() {
  48.         return color;
  49.     }
  50.  
  51.     public void setColor(String color) {
  52.         this.color = color;
  53.     }
  54.  
  55.     public String getTempStatus() {
  56.         return tempStatus;
  57.     }
  58.  
  59.     public void setTempStatus(String tempStatus) {
  60.         this.tempStatus = tempStatus;
  61.     }
  62.  
  63.     @Override
  64.     public String toString() {
  65.         return "Your drink is " + name + ", it has volume of " + volumeInMl + "ml" + ", it has "  + color + " color" + " and it is " + tempStatus;
  66.     }
  67. }
  68.  
  69. class AlcholicDrink extends Drink{
  70.     private double alcoholPercentage;
  71.  
  72.     public AlcholicDrink(String name, int volumeInMl, String color, String tempStatus, double alcoholPercentage) {
  73.         super(name, volumeInMl, color, tempStatus);
  74.         this.alcoholPercentage = alcoholPercentage;
  75.     }
  76.  
  77.     public void makeYouDrunk(){
  78.         System.out.println("You are drunk :P");
  79.     }
  80.  
  81.     public double getAlcoholPercentage() {
  82.         return alcoholPercentage;
  83.     }
  84.  
  85.     public void setAlcoholPercentage(double alcoholPercentage) {
  86.         this.alcoholPercentage = alcoholPercentage;
  87.     }
  88.     @Override
  89.     public String toString(){
  90.         return super.toString() + ". Also it's alcoholic with " + alcoholPercentage + "% alcohol." + '\n';
  91.     }
  92. }
  93.  
  94. class NonAlcoholicDrink extends Drink{
  95.     public NonAlcoholicDrink(String name, int volumeInMl, String color, String tempStatus) {
  96.         super(name, volumeInMl, color, tempStatus);
  97.     }
  98.     @Override
  99.     public String toString(){
  100.         return super.toString() + ". Also it's non-alcoholic." + '\n';
  101.     }
  102. }
  103.  
  104. class DrinkMain{
  105.     public static void main(String[] args) {
  106.         AlcholicDrink rakiq1 = new AlcholicDrink("Grozdova", 700, "LightYellow", "Cold", 60);
  107.         rakiq1.drink(400);
  108.         rakiq1.makeYouDrunk();
  109.         System.out.println(rakiq1);
  110.  
  111.         NonAlcoholicDrink voda1 = new NonAlcoholicDrink("Devin", 200, "Transparent", "Normal");
  112.         voda1.spill(50);
  113.         voda1.drink(100);
  114.         voda1.pour(100);
  115.         System.out.println(voda1);
  116.     }
  117.  
  118. }
  119.  
Advertisement
Add Comment
Please, Sign In to add comment