written 8.2 years ago by
krrish
• 360
|
|
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author 4g3nt_47
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Tree {
int code, height, base, time, ucode, uheight, ubase, utime;
Tree(int c, int h, int b, int t)
{
code=c;
height=h;
base=b;
time=t;
}
void display()
{
System.out.println("Tree Code is: "+code);
System.out.println("Tree height is: "+height+" feet.");
System.out.println("Tree base is: "+base+" cm wide.");
System.out.println("amount of time spent so far on the tree is: "+time+" hours");
}
void update() throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter updated Tree Code");
ucode=Integer.parseInt(br.readLine());
System.out.println("Enter updated Tree Height");
uheight=Integer.parseInt(br.readLine());
System.out.println("Enter updated Tree base");
ubase=Integer.parseInt(br.readLine());
System.out.println("Enter updated time spent on a tree");
utime=Integer.parseInt(br.readLine());
code=ucode;
height=uheight;
base=ubase;
time=utime;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author 4g3nt_47
*/
public class Mango extends Tree {
int yeild;
public Mango(int c, int h, int b, int t, int y) {
super(c, h, b, t);
yeild=y;
}
@Override
void display()
{
System.out.println("Mango Tree Code is: "+code);
System.out.println("Mango Tree height is: "+height+" feet.");
System.out.println("Mango Tree base is: "+base+" cm wide.");
System.out.println("amount of time spent so far on the mango tree is: "+time+" hours");
System.out.println("Yeild of the Mango Tree is: "+yeild+" fruits.");
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author 4g3nt_47
*/
/*import java.io.BufferedReader;
import java.io.InputStreamReader;
*/
import java.io.*;
public class Garden {
public static void main(String[] args) throws IOException{
Tree t=new Tree(10,130,150,20);
Mango m=new Mango(15,150,170,20,200);
System.out.println("Information of the Tree is:");
System.out.println("\n");
t.display();
System.out.println("\n");
System.out.println("Information of the Mango Tree is:");
System.out.println("\n");
m.display();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String input;
System.out.println("press y to update and print the updated tree information");
input=br.readLine();
if(input.equals("y"))
{
t.update();
System.out.println("\n");
System.out.println("updated tree information is: ");
System.out.println("\n");
t.display();
}
}
}
OUTPUT
run: Information of the Tree is:
Tree Code is: 10 Tree height is: 130 feet. Tree base is: 150 cm wide.
amount of time spent so far on the tree is: 20 hours
Information of the Mango Tree is:
Mango Tree Code is: 15 Mango Tree height is: 150 feet. Mango Tree base
is: 170 cm wide. amount of time spent so far on the mango tree is: 20
hours Yeild of the Mango Tree is: 200 fruits. press y to update and
print the updated tree information y Enter updated Tree Code 20 Enter
updated Tree Height 180 Enter updated Tree base 200 Enter updated time
spent on a tree 25
updated tree information is:
Tree Code is: 20 Tree height is: 180 feet. Tree base is: 200 cm wide.
amount of time spent so far on the tree is: 25 hours BUILD SUCCESSFUL
(total time: 39 seconds)