Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lec 13 Writing an Instantiable Class II. Agenda Adding to our Balloon Class demo: – default Constructor method – inflate method that takes a parameter.

Similar presentations


Presentation on theme: "Lec 13 Writing an Instantiable Class II. Agenda Adding to our Balloon Class demo: – default Constructor method – inflate method that takes a parameter."— Presentation transcript:

1 Lec 13 Writing an Instantiable Class II

2 Agenda Adding to our Balloon Class demo: – default Constructor method – inflate method that takes a parameter (amount) – pop method – volume method

3 Recall Structure of an Instantiable Class class Balloon size color Balloon inflate getSize getColor setColor pop Class Name Instance Varbls Methods Constructor method same name as class

4 Method Overloading We can add methods to Balloon with same names – as long as have different parameters – the Constructor we made in our Balloon class – A second "Default" constructor with no parameters

5 Which one is used? Balloon myBal = new Balloon(10,Color.RED); Balloon yrBal = new Balloon(); default constructor automatically – sets size to 0 – sets color to Color.WHITE

6 Now we'll begin BalloonDemo2 start with BalloonDemo from last time add default constructor add inflate method that takes an amount add pop method – modify both inflate methods add volume method – should return 0 if balloon has been popped

7 More Dairy.java make Lab13DairyFarm folder Copy, Dairy.java file from Lab12 folder, then add – default Constructor – addCow takes a number – calcMllkProfit takes a price/gallon – calcButterProfit takes a price/pound Create a new class Farm.java that – tests your new Dairy class by constructing a dairy farm, adding cows and printing the number of cows – And printing profit from selling milk or butter


Download ppt "Lec 13 Writing an Instantiable Class II. Agenda Adding to our Balloon Class demo: – default Constructor method – inflate method that takes a parameter."

Similar presentations


Ads by Google