Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Ital {
- protected double mennyiség;
- protected boolean alkoholmentes;
- public Ital(double mennyiség, boolean alkoholmentes) {
- this.mennyiség = mennyiség;
- this.alkoholmentes = alkoholmentes;
- System.out.println("Új ital: " + this);
- }
- public Ital(double mennyiség) {
- this(mennyiség, false);
- }
- public Ital kever(Ital i) {
- boolean alkMent = alkoholmentes && i.alkoholmentes;
- System.out.println("I + I: " + this + " + " + i);
- return new Ital(mennyiség + i.mennyiség, alkMent);
- }
- }
- class AlkoholMentes extends Ital {
- public AlkoholMentes(double mennyiség) {
- super(mennyiség, true);
- System.out.println("Új alkoholmentes ital: " + this);
- }
- @Override
- public Ital kever(Ital i) {
- System.out.println("M + I: " + this + " + " + i);
- return new Ital(mennyiség + i.mennyiség, i.alkoholmentes);
- }
- public Ital kever(AlkoholMentes a) {
- System.out.println("M + M: " + this + " + " + a);
- return new AlkoholMentes(mennyiség + a.mennyiség);
- }
- }
- public class ItalFeladat {
- public static void main(String[] args) {
- Ital ii = new Ital(0.1);
- Ital mi = new AlkoholMentes(0.3);
- AlkoholMentes mm = new AlkoholMentes(0.5);
- System.out.println(mi.kever(mm));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement