Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

answer please Create a java program that consists of a new class called \"Tree\"

ID: 3859409 • Letter: A

Question


answer please

Create a java program that consists of a new class called "Tree". In "main" method create 2 objects of class "Tree" one with name of "Orange" and another is "Apple". The output should be as the following. Output First Object: - Name: Orange Height: 2 meter Second object: - Name: Apple Height: 5 meter Create a class called Employee that includes three fields-a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each field. If the monthly salary is not positive, do not set its value. Write a test application (driver class) named EmployeeTest that should do the following: Create two Employee objects. Display each object's yearly salary. Give each Employee a 10% raise. Display each Employee's yearly salary again.

Explanation / Answer

1)

import java.util.*;
import java.io.*;


class Tree// Tree class
{
String name;// name field
double height; // height field
  
Tree(String name_, double height_)// constructor
{
name = name_;
height = height_;
}
}
  
class Test
{
public static void main(String[] args)
{
Tree t1 = new Tree("Orange", 2);// make a object for orange tree
Tree t2 = new Tree("Apple", 5);// make a object for apple tree
System.out.println("First Object:-");
System.out.println("Name: " + t1.name);
System.out.println("Height: " + t1.height);
System.out.println();
System.out.println("Second Object:-");
System.out.println("Name: " + t2.name);
System.out.println("Height: " + t2.height);
}
  
}

Sample output:

First Object:-
Name: Orange
Height: 2.0

Second Object:-
Name: Apple
Height: 5.0

2)

import java.util.*;
import java.io.*;


class Employee// Tree class
{
private
String firstName;// firstname field
String lastName;// lastname field
double salary; // salary field
  
public
Employee(String firstName_, String lastName_, double salary_)// constructor
{
firstName = firstName_;
lastName = lastName_;
salary = salary_;
}
  
void setFirstName(String name)
{
firstName = name;
}
  
String getFirstName()
{
return firstName;
}
  
void setLastName(String name)
{
lastName = name;
}
  
String getLastName()
{
return lastName;
}
  
void setSalary(double salary_)
{
if (salary > 0)// only positive salary
salary = salary_;
}
  
double getSalary()
{
return salary;
}
  
}
  
class EmployeeTest
{
public static void main(String[] args)
{
Employee e1 = new Employee("Bill", "Gates", 10);// first object
Employee e2 = new Employee("Mark", "Zuckerburg", 5);// 2nd object
System.out.println("First Object salary: " + e1.getSalary() * 12); // yearly multiply by 12
System.out.println("Second Object salary: " + e2.getSalary() * 12);
  
e1.setSalary((e1.getSalary() * 110) / 100);// 10% raise
e2.setSalary((e2.getSalary() * 110) / 100);// 10% raise
  
System.out.println("First Object salary: " + e1.getSalary() * 12); // yearly multiply by 12
System.out.println("Second Object salary: " + e2.getSalary() * 12);
}
  
}

Sample output

First Object salary: 120.0
Second Object salary: 60.0
First Object salary: 132.0
Second Object salary: 66.0