Problem1: Write a class called Sphere. Sphere is characterized with radius (shou
ID: 3667754 • Letter: P
Question
Problem1: Write a class called Sphere. Sphere is characterized with radius (should be float). Add constructor, getter and setter. Add methods to computer area and volume. Also, add a class method that creates a single Sphere by combining two spheres (hint: combine the volumes and get the radius for the new volume). Show these methods in a main method. Problem 2: You are to design class called Employee whose members are as given below: Data memebrs: name ID A constructor // intitialize data memebrs to the values passed to the constructor Methods: setPerson (name, id) //allows user to set information for each person A function called Print () that prints the data attributes of the class. Show the working of class in a driver program (one with main).
Explanation / Answer
1)
import Java.io.*;
2)
class Employee
{
String name;
int id;
//constructor 1
Employee()
{
}
//constructor 2
Employee(String inputValue)
{
name = inputValue;
}
//constructor 3
Employee(String inputName, int inputId)
{
name = inputName;
id = inputId;
}
//Methods in this class (getters and setters)
public String getName() {
return name;
}
public void setName(String name)
{
this.name = name;
}
public int getId()
{
return id;
}
public void setId(int id) {
this.id = id;
}
}
class Employee
{
String name;
int id;
//constructor 1
Employee()
{
}
//constructor 2
Employee(String inputValue)
{
name = inputValue;
}
//constructor 3
Employee(String inputName, int inputId)
{
name = inputName;
id = inputId;
}
//Methods in this class (getters and setters)
public String getName() {
return name;
}
public void setName(String name)
{
this.name = name;
}
public int getId()
{
return id;
}
public void setId(int id) {
this.id = id;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.