am I going to use if / loops in this java work?
hi i have an assignment but I am way ahead in class, so i usually jump ahead but I am not sure what I going to be doing here
this is the assignment. I tried looking in my notes, but cant manage to figure out what to do. Maybe osmeone can tell me what ill be using here ( i know booleans ill be using) but I am just trying to use my notes as a guide
_____________________________
The XYZ School wants to carry 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. Incorporate the following:
• A method 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 toString() that returns the result.
Write a test class called TestContribution that generates the daily contributions. It keeps making contribution 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.
Re: am I going to use if / loops in this java work?
if it helps this is the link for class note java 1
COP2250 - Java Programming
Re: am I going to use if / loops in this java work?
What confuses you? What *specific* question(s) do you have?
Re: am I going to use if / loops in this java work?
Quote:
Originally Posted by
willc86
hi i have an assignment but I am way ahead in class, so i usually jump ahead but I am not sure what I going to be doing here
this is the assignment. I tried looking in my notes, but cant manage to figure out what to do. Maybe osmeone can tell me what ill be using here ( i know booleans ill be using) but I am just trying to use my notes as a guide
_____________________________
The XYZ School wants to carry 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. Incorporate the following:
• A method 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 toString() that returns the result.
Write a test class called TestContribution that generates the daily contributions. It keeps making contribution 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.
So you have a description of the problem to solve, and some requirements for the solution.
Code :
public class //Design a class called SchoolContribution that creates a contribution account.
A method 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 toString() that returns the result.{
}
}
See how the steps are pseudo code if you just organize them... Take one method at a time and break it down into more steps. Consider the first method, totalContribution(..)
A method called totalContribution(..) that accepts and accumulates the daily contributions.
-method must accept numeric type
-must keep track of a numeric type between method calls in order to accumulate each individual value into a total
Get this method, or which ever method you choose to do first, working before worrying about the other methods. Get the class to compile and run and test the method. When it is working, move to the next one. It is hard to offer much advice without seeing how far you can get on your own. See what you can get and ask more questions when you get stuck.
Re: am I going to use if / loops in this java work?
thank you =) let me give it a shot
Re: am I going to use if / loops in this java work?
urgh cant figure it out for the first step.
what or what do i use for the method to get total contribution this is what i have what clue or maybe an example?
public class SchoolContribution
{
private double moneyCollected;
private double totalCollected;
private double totalContribution;
private Boolean hasMoreTime;
public SchoolContribution(double totalContribution)
{
this.totalContribution = totalContribution;
}
Re: am I going to use if / loops in this java work?
Code java:
public SchoolContribution(double totalContribution)
{
this.totalContribution = totalContribution;
}
I think you misunderstood the concept of the method. In a variable, say totalContribution, you would store the total. The method is supposed to accept and accumulate the daily contributions, not the totalContribution. The daily contributions need to be added to the totalContribution every time there is a single donation.
Really plan out what will need to happen in each step.