Use the following files: Qualifiable.java Student.java Code the following files:
ID: 3774139 • Letter: U
Question
Use the following files:
Qualifiable.java
Student.java
Code the following files:
/**
* models a person with a name and an annualIncome
*/
public class Person
{
private String name;
private double monthlyIncome;
public Person(String theName, double income)
{
name = theName;
monthlyIncome = income;
}
public String getName()
{
return name;
}
public double getMonthlyIncome()
{
return monthlyIncome;
}
}
public class Runner
{
public static void main(String[] args)
{
Qualifiable[] candidates = new Qualifiable[5];
candidates[0] = new Person("Susan", 2000.0);
candidates[1] = new Person("Fred", 1961.99 );
candidates[2] = new Person("Jack", 1962.00);
candidates[3] = new Person("Amy", 1200.00 );
candidates[4] = new Student("Thong", 3.6 );
for (Qualifiable c : candidates)
{
System.out.println(c.qualifies());
}
}
}
Explanation / Answer
***************************************Runner.java**********************************************************
package runner;
public class Runner {
public static void main(String[] args) {
Qualifiable[] candidates = new Qualifiable[5];
candidates[0] = new Person("Susan", 2000.0);
candidates[1] = new Person("Fred", 1961.99 );
candidates[2] = new Person("Jack", 1962.00);
candidates[3] = new Person("Amy", 1200.00 );
candidates[4] = new Student("Thong", 3.6 );
//the following loop outputs the names for calFresh Program
System.out.println("The names eligible for CalFresh program are as follow: ");
for(int i=0;i<5;i++){
candidates[i].qualifies();
}
}
}
**********************************************Student.java****************************************************
package runner;
/**
* Describes a Student with a name and grade point.
*
*/
public class Student implements Qualifiable
{
private String name;
private double gpa;
private double QUALIFYING_GPA = 3.54;
/**
* Creates a student
* @param theName the name of this student
* @param theGpa the gpa of this student
*/
public Student(String theName, double theGpa)
{
name = theName;
gpa = theGpa;
}
/**
* Gets the name of this student
* @return the name of this student
*/
public String getName()
{
return name;
}
/**
* Gets the GPA of this student
* @return the GPA of this student
*/
public double getGPA()
{
return gpa;
}
public boolean qualifies()
{
return gpa >= QUALIFYING_GPA;
}
}
********************************************Person.java*****************************************
package runner;
public class Person implements Qualifiable
{
private String name;
private double monthlyIncome;
public Person(String theName, double income)
{
name = theName;
monthlyIncome = income;
}
public String getName()
{
return name;
}
public double getMonthlyIncome()
{
return monthlyIncome;
}
//defining the qualifies method of Qualifiable Interface
@Override
public boolean qualifies() {
//checking condition for CalFresh Program
if(monthlyIncome<1962){
System.out.println("Name:"+name); //Printing name eligible for calFresh program
return true;
}
else
return false;
}
}
******************************************************Qualifiable.java******************************************************
package runner;
public interface Qualifiable
{
boolean qualifies();
}
******************************************************Program output****************************************
run:
The names eligible for CalFresh program are as follow:
Name:Fred
Name:Amy
BUILD SUCCESSFUL (total time: 0 seconds)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.