1. Exercise 2: Create a class building that has the public member floors,area, and occupants and a method areaperperson()respectively that display the area per person for building. In the main() method create two instance of building called house and office and display the area per person by division of area/occupants
package building;
public class Building {
public int floors,area,occupants;
public void areaperperson(){
System.out.println("Area per person is: \n"+area/occupants);
}
public static void main(String[] args) {
Building house = new Building();
Building office = new Building();
house.area = 40;
house.occupants = 5;
house.areaperperson();
office.area = 80;
office.occupants = 2;
office.areaperperson();
}
}
Comments
Leave a comment