Day 1
1. import day1.1 , in your workspace to revise exception handling
2.
To revise inheritance , run time polymorphism m up casting , down casting n
abstraction (using abstract class ) with array of references
Hands on
Read complete assignment n then only solve.
2.1 Can you arrange Fruit,Apple,Orange,Mango in inheritance hierarchy ?
Use tight encapsulation.
2.2 Properties (instance variables) : color : String , weight : double ,
name:String, fresh : boolean
2.3 Add suitable constructor
2.4 Override toString correctly to return state of all fruits (return only : name
,color , weight )
2.5 Add a taste() method : public String taste()
For Fruit : Can you identify taste of any general fruit ? NO
So add a taste() with this definition : returns "no specific taste"
OR is there any BETTER solution ????
Apple : should return "sweet n sour"
Mango : should return "sweet"
Orange : should return "sour"
2.6 Add specific functionality , in the sub classes
In Mango : public void pulp() {Display name n color of the fruit + a mesg creating
pulp!}
In Orange : public void juice() {Display name n weight of the fruit + a mesg
extracting juice!}
In Apple : public void jam() {Display name of the fruit + a mesg making jam!}
2.7 Add all of above classes under the package "com.app.fruits"
2.8 Create java application FruitBasket , with main method , as a tester
2.9 Prompt user for the basket size n create suitable data structure
2.10 Supply options
1. Add Mango
2. Add Orange
3. Add Apple
NOTE : You will be ALWAYS adding a fresh fruit in the basket , in all of above
options.
2. Display names of all fruits in the basket.
5. Display name,color,weight , taste of all fresh fruits , in the basket.
6. Mark a fruit in a basket , as stale(=not fresh)
i/p : index
o/p : error message (in case of invalid index) or mark it stale
7. Mark all sour fruits stale
Hint : Use equals() method of the String class.
8. Invoke fruit specific functionality (pulp / juice / jam)
i/p : index
Invoke correct functionality (pulp / juice / jam)
9. Exit