Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: am I going to use if / loops in this java work?

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.


  2. #2
    Junior Member
    Join Date
    Nov 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  3. #3
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: am I going to use if / loops in this java work?

    What confuses you? What *specific* question(s) do you have?

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: am I going to use if / loops in this java work?

    Quote Originally Posted by willc86 View Post
    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.

    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.
    Last edited by jps; November 3rd, 2012 at 12:36 PM. Reason: fixed code tag

  5. #5
    Junior Member
    Join Date
    Nov 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: am I going to use if / loops in this java work?

    thank you =) let me give it a shot

  6. #6
    Junior Member
    Join Date
    Nov 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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;

    }

  7. #7
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: am I going to use if / loops in this java work?

    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.

Similar Threads

  1. [SOLVED] I am a java newb and I am having a problem with my while loops.
    By Deaththekid in forum Loops & Control Statements
    Replies: 22
    Last Post: July 10th, 2011, 07:26 AM
  2. [SOLVED] Java assignment, concerning Arrays and Loops
    By trejorchest in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 17th, 2011, 12:59 PM
  3. Java Loops help please?
    By Sarah-Perkin in forum Loops & Control Statements
    Replies: 2
    Last Post: December 6th, 2009, 02:52 PM
  4. How to Use different Java loops
    By JavaPF in forum Java Programming Tutorials
    Replies: 1
    Last Post: August 28th, 2009, 03:10 AM
  5. How to Use different Java loops
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 1
    Last Post: August 28th, 2009, 03:10 AM