Write a
- 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 housingcoat + foodCost + size is greater than half the family income (foodCoat 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.
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Additional Engineering Textbook Solutions
Modern Database Management
Starting Out With Visual Basic (8th Edition)
Computer Science: An Overview (12th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Programming in C
Concepts Of Programming Languages
- Give Solutionarrow_forwardModify the Car class example and add the following: A default constructor that initializes strings to “N/A” and numbers to zero. An overloaded constructor that takes in initial values to set your fields (6 parameters). accel() method: a void method that takes a double variable as a parameter and increases the speed of the car by that amount. brake() method: a void method that sets the speed to zero. To test your class, you will need to instantiate at least two different Car objects in the main method in the CarDemo class. Each of your objects should use a different constructor. For the object that uses the default constructor, you will need to invoke the mutator methods to assign values to your fields. Invoke the displayFeatures() method for both objects and display the variables. Demonstrate the use of the accessor method getColor() by accessing the color of each car and printing it to the console. Use the method accel to increase the speed of the first car by 65 mph. Use…arrow_forwardCreate a Class Pet with the following data members Identification: String species : String (e.g. cat, dog, fish etc) breed: String Age (in days): int Weight: float Dead: boolean 1. Provide a constructor with parameters for all instance variables. 2. Provide getters for all and setters for only breed, and weight 3. Provide a method growOld() that increases the age of the pet by one day. A dead pet wont grow old 4. Provide a method growHealthy(float w) that increases the weight of the pet by the given amount w. A dead pet cannot grow healthy. 5. Provide a method fallSick(float w) that reduces the weight of the pet by the given amount. The least weight a pet can have is 0 which will mean that the pet has died. If the value of weigh is 10 kg and the method is called with an argument of 11 kg then you will set it to 0 and set the dead to an appropriate value to mark the death of the pet 6. Provide a toString method that shows an appropriate well formatted string…arrow_forward
- Modify the Date class below by adding a new method called nextDay() that increments the Date by 1 when called and returns a new Date object. This method should properly increment the Date across Month boundary (i.e from the last day of the month to the first day of the next month). //Date class declaration public class Date { private int month; // 1-12 private int day; // 1-31 based on month private int year; // any year private static final int [] daysPerMonth = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //constructor: confirm proper value for month and day given the year public Date (int month, int day, int year) { //check if month in range if (month <=0 II month > 12) { throw new IllegalArgumentException( “month (“ + month + “) must be 1-12”); } //check if day in range for month if…arrow_forwardModify the Date class below by adding a new method called nextDay() that increments the Date by 1 when called and returns a new Date object. This method should properly increment the Date across Month boundary (i.e from the last day of the month to the first day of the next month). //Date class declaration public class Date { private int month; // 1-12 private int day; // 1-31 based on month private int year; // any year private static final int [] daysPerMonth = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //constructor: confirm proper value for month and day given the year public Date (int month, int day, int year) { //check if month in range if (month <=0 II month > 12) { throw new IllegalArgumentException( “month (“ + month + “) must be 1-12”); } //check if day in range for month if…arrow_forwardWrite in python language thank youarrow_forward
- Write a program that test methods in the class. • Hint: the employee deserved retirement if he has year of Service >25 or his age >=65. 5. Design a class named MyInteger. The class contains: • An int data field named value(int) Methods isEven() and respectively. Write a program that test methods in the class. isOdd() that return true if the value is even or odd.arrow_forwardMake a class that represents an average of test scores. Make the class take an unlimited number of scores and calculate the number of tests taken along with the average. Class name: TestScores Fields: - name : String - totalScore : double - numScores : int Methods: + TestScores(name : String) + addTestScore(earned : double) : void + getNumTestsTaken() : int + getAverage() : double Write in java and use test case 1 as an referencearrow_forwardWrite a program that test methods in the class. • Hint: the employee deserved retirement if he has year of Service >25 or his age >=65. 5. Design a class named MyInteger. The class contains: • An int data field named value(int) ● Methods isEven() and respectively. Write a program that test isOdd() that return true if the value is even or odd. methods in the class.arrow_forward
- Give source code and output alsoarrow_forwardPlease help me with this using java. Make it simplearrow_forwardFor the following class: 1. write a toString method to return a String that represents the information stored in a Person object including name, lastName, and age. //2 points 2. write an equals(Object obj) to return false if the passed object is null or not a Person. The method equal returns false, if one of name, lastName, and age of the object which it is applied to is not equal to name, lastName, and age of the object that is passed as argument. Otherwise, the method returns true. //3 points public class Person { private String name; private String lastName; private int age; public Person (String name, String lastName, int age) { this.name = name; this.lastName = lastName; this.age age; }arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education