its grade 10 students on a trip. The cost of the trip is $5,000.00. The school h
ID: 3891317 • Letter: I
Question
its grade 10 students on a trip. The
cost of the trip is $5,000.00.
The
school has only thirty days in which to collect the funds in order to go on the trip. Design a class
called
SchoolContribution
that
creates a contribution account. In
your design incorporate the
following:
•
A
mutator
meth
od called
totalContribution(..)
that accepts and accumulates the daily
contributions.
•
A Boolean method called
hasMoreTime()
that determines if more time is available in which to
reach the targeted amount.
•
A Boolean method called
needMoreMoney()
that determines if more contribution is
needed to meet the target.
•
A Boolean method called
metTarget()
that reports if target has been met. This must be
based on meeting the target within the time frame.
•
A method
called
getTotalContribution()
that
returns the total contribution.
•
A method called
toString()
that returns the result.
Write a test class called
TestContribution
that generates the daily contributions. It keeps asking for
contribution
s until it determines that either the targeted amount of contribution is met, or the time allotted
to collecting the amount of money expires. In either case it displays the amount of money collected each
day, and the total amount accumulated over the period
.
The assignment The XYZ School wants to take its grade 10 students on a trip. The cost of the trip is S5,000.00. The school has only thirty days in which to collect the funds in order to go on the trip. Design a class called SchoolContribution that creates a contribution account. In your design incorporate the following. A mutator method called totalContribution() that accepts and accumulates the daily contributions. A Boolean method called hasMoreTime0 that determines if more time is available in which to reach the targeted amount. A Boolean method called needMoreMoney0 that determines if more contribution is needed to meet the target. A Boolean method called metTarget0 that reports if target has been met. This must be based on meeting the target within the time frame. A method called getTotalContribution0 that returns the total contribution. A method called toString0 that returns the result Write a test class called TestContribution that generates the daily contributions. It keeps asking for contributions until it determines that either the targeted amount of contribution is met, or the time allotted to collecting the amount of money expires. In either case it displays the amount of money collected each day, and the total amount accumulated over the period. Example of a typical input screen Input Make contributionExplanation / Answer
import java.util.Scanner;
class SchoolContribution{
//static variables to store the values
public static int cost_of_trip = 5000;
public static int total_number_of_days = 30;
public static int current_money_collected = 0;
public static int current_day=0;
public static boolean hasMoreTime()
{
if(current_day<=total_number_of_days)
return true;
return false;
}
public static boolean needMoreMoney()
{
if(current_money_collected<cost_of_trip)
return true;
return false;
}
public static boolean metTarget()
{
if(current_money_collected>=cost_of_trip&¤t_day<=total_number_of_days)
return true;
return false;
}
public static int getContribution()
{
return current_money_collected;
}
public static void main(String args[]){
System.out.println("Rohn");
}
}
//Class to test the above written class
public class TestContribution
{
public static void main(String[] args) {
SchoolContribution schoolContribution = new SchoolContribution();
while(true)
{
System.out.println("Make daily contribution: ");
Scanner sc=new Scanner(System.in);
int contribution = sc.nextInt();
schoolContribution.current_day++;
schoolContribution.current_money_collected+=contribution;
if(schoolContribution.metTarget())
{
System.out.println("Hey the target is met. Go on Trip!");
break;
}
else if (schoolContribution.needMoreMoney()==true&&schoolContribution.hasMoreTime()==false)
{
System.out.println("Sorry you cannot make to the trip!");
break;
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.