KEMBAR78
Core Java Lab Instructions N Assignments | PDF
0% found this document useful (0 votes)
19 views2 pages

Core Java Lab Instructions N Assignments

The document outlines a programming assignment focused on object-oriented concepts such as inheritance, polymorphism, and encapsulation using a fruit hierarchy. It includes tasks like creating a Fruit class with specific properties and methods, implementing subclasses for Apple, Mango, and Orange, and developing a FruitBasket application to manage a collection of fruits. The assignment emphasizes user interaction for adding fruits, displaying details, and invoking specific functionalities based on user input.

Uploaded by

kapojoy655
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

Core Java Lab Instructions N Assignments

The document outlines a programming assignment focused on object-oriented concepts such as inheritance, polymorphism, and encapsulation using a fruit hierarchy. It includes tasks like creating a Fruit class with specific properties and methods, implementing subclasses for Apple, Mango, and Orange, and developing a FruitBasket application to manage a collection of fruits. The assignment emphasizes user interaction for adding fruits, displaying details, and invoking specific functionalities based on user input.

Uploaded by

kapojoy655
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

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

You might also like