Advertisement
virtualideaz

Household.java

Mar 26th, 2015
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. create a java class name Household that includes data fields for the number of occupants and the annual income, as well as method names setOccupants, setIncome(), getOccupants() and getIncome() that set and return those values respectiveliy. Also create a constructor that requires no arguments and automatically sets the occupants field to 1 and the income field to 0. Name the program Household.java
  2.  
  3. Source code :
  4.  
  5.  
  6. import java.util.Scanner;
  7. public class Household  {
  8.     static Scanner sc = new Scanner (System.in);
  9.     public static void main(String [] args) {
  10.        
  11.         //input needed data
  12.             int border;
  13.                 System.out.print("Enter number of occupants : ");
  14.                 border = sc.nextInt();
  15.             double annual;
  16.                 System.out.print("Enter income : ");
  17.                 annual = sc.nextDouble();
  18.        
  19.         //method getOccupants()
  20.             int tenant = getOccupants(border);
  21.         //method setOccupants()
  22.             int renter = setOccupants(border);
  23.         //method getIncome()
  24.             double income = getIncome(annual);
  25.         //method for setIncome()
  26.             double incomeAgain = 12;
  27.             double incomeComputation = setIncome(income, incomeAgain);
  28.             System.out.println("Annual income : " + incomeComputation);
  29.     }
  30.     public static int getOccupants(int border) {
  31.         return border;
  32.     }
  33.     public static int setOccupants(int border) {
  34.         return border;
  35.     }
  36.     public static double getIncome(double annual) {
  37.         return annual;
  38.     }
  39.     public static double setIncome(double income, double incomeAgain) {
  40.         return income*incomeAgain;
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement