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

Write a program in a class CountPoor that counts the number of families that are

ID: 3646855 • Letter: W

Question

Write a program in a class CountPoor that counts the number of families that are considered poor. Write and use a class Family that has the attributes:
- income: a double value that is the income for the family
- size: the number of people in the family

and the following methods
- Family (income, size): a constructor that sets the attributes
isPoor (housingCost, foodCost): a method that returns true if housingCost+foodCost*size is greater than half the family income (foodCost is the average food cost for an individual, while housingCost is for the family)
- toString: a method that returns a string containing the information about the family

The program should read an integer k from the keyboard and then create an array of size k whose base type is Family. It should then create k objects of type Family and put them in the array, reading the income and size for each family from the keyboard. After reading an average housing cost and average food cost from the keyboard, it should display the families that are poor.

PLEASE PROVIDE FULL PROGRAM IN JAVA LANGUAGE FOR 5-STAR RATING.


Explanation / Answer

please rate-thanks

import java.util.*;
public class CountPoor
{public static void main(String[] args)
{Scanner in=new Scanner(System.in);
int n,i,s;
double income,housing,food;
System.out.print("How many families are there? ");
n=in.nextInt();
Family[] fam=new Family[n];
for(i=0;i<n;i++)
    {System.out.println("For family "+(i+1)+": ");
    System.out.print("Enter family size: :");
    s=in.nextInt();
    System.out.print("Enter family income: ");
    income=in.nextDouble();
    fam[i]=new Family(income,s);
    }
System.out.println("For all families");
System.out.print("Enter average housing cost: ");
housing=in.nextDouble();
System.out.print("Enter average food cost per person :");
food=in.nextDouble();
System.out.println("The poor families are: ");
for(i=0;i<n;i++)
   if(fam[i].isPoor(housing,food))
          System.out.println("Family "+(i+1)+" "+fam[i].toString());
}
}

-----------------------------------

public class Family
{
private double income;
private int size;

public Family(double i, int s)
{income=i;
size=s;

}
public boolean isPoor(double house, double food)
{if((house+food*size)>income/2.)
      return true;
else
      return false;
}
public String toString()
{
return ("Income" + income + " Family size: "+size);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote