Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, I need help with the asignment below. It has to do with Utilizing loops i

ID: 3909265 • Letter: H

Question

Hello, I need help with the asignment below. It has to do with Utilizing loops in Java programming

.

This is what i have so far, but it does not let me input information like the image above asks me to.

package schoolcontribution;

public class SchoolContribution {

double total = 0.0;
static int days = 30;
double day[] = new double[30];
int dayNumber = 1;


public SchoolContribution()
{
total = 0.0;
}

public void contribute(double amount, int currentDay)
{
dayNumber = currentDay;
day[--currentDay] = amount + day[currentDay];
}

public boolean hasMoreTime()
{
return (dayNumber <= 30)?true:false; // if and else return
}

public boolean needMoreMoney()
{
return (total < 5000)?true:false;
}
public double totalContribution()
{
for (int dayCounter = 0; dayCounter < 30; dayCounter++ )
{
total = total + day[dayCounter];
}

return total;

}
public String toString()
{
return String.valueOf(total);
}
}

package schoolcontribution;

public class TestContribution {

public static void main(String[] args) {

SchoolContribution object1 = new SchoolContribution();
object1.contribute(200, 1);
object1.contribute(400, 2);
object1.contribute(200, 2);
object1.contribute(50, 1);
object1.contribute(23, 6);
object1.contribute(47, 4);
object1.contribute(80, 10);

System.out.println(object1.totalContribution());
}
}

COP2250 Assignment 6 Purpose of assignment Purpose of this assignment is for you to u nderstand (a) Looping in general, (b) The while loop in particular (c) Nested for loop The assignment The XYZ School wants to take 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 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 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 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 nput Make contribution OKCancel

Explanation / Answer

here is your program : ---------->>>>>>>>>

public class SchoolContribution {
double total = 0.0;
static int days = 30;
double day[] = new double[30];
int dayNumber = 1;

public SchoolContribution()
{
total = 0.0;
for(int i = 0;i<30;i++)
day[i] = 0.0;
}
public void contribute(double amount, int currentDay)
{
dayNumber = currentDay;
day[--currentDay] = amount + day[currentDay];
}
public boolean hasMoreTime()
{
return (dayNumber <= 30)?true:false; // if and else return
}
public boolean needMoreMoney()
{
return (total < 5000)?true:false;
}
public double totalContribution()
{
total = 0;
for (int dayCounter = 0; dayCounter < 30; dayCounter++ )
{
total = total + day[dayCounter];
}
return total;
}
public String toString()
{
return String.valueOf(total);
}
}

----------------------------------------------------------------

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.awt.Dimension;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;

public class TestContribution {
public static void main(String[] args) {
  SchoolContribution object1 = new SchoolContribution();
  double contri = 0.0;
  int st = 0;
  double[] arr1 = new double[30];
  double[] arr2 = new double[30];
  int count = 0;
  for(int i = 1;i <= 30;i++){
   for(int j = 0;j<3;j++){
    contri = Double.parseDouble(JOptionPane.showInputDialog("Make Contribution "));
    object1.contribute(contri,i);
    arr2[i-1] = arr2[i-1] + contri;
    if(object1.totalContribution() >= 5000.0){
     st = 1;
     break;
    }
   }
   count++;
   arr1[i-1] = object1.totalContribution();
   if(object1.totalContribution() >= 5000.0){
     st = 1;
     break;
   }
  }

  String s = "Day                      DayContribution                  TotalContribution";
  for(int i = 0;i<count;i++){
   s += " "+(i+1)+"                                 $"+String.format("%6.2f",arr2[i])+"                                $"+String.format("%6.2f",arr1[i]);
  }

  if(st == 0){
   s += " we did not make the Target. Sorry, we can not go on the trip.";
  }else{
   s += " Congrats,you made it.";
  }

  JPanel panel = new JPanel();
  panel.setPreferredSize(new Dimension(300, 300));
  JTextArea area = new JTextArea();
  area.setText(s);
  area.setEditable(false);
  JScrollPane scrollPane = new JScrollPane(area,
                   JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                   JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        scrollPane.setPreferredSize(new Dimension(300,300));
        panel.add(scrollPane);

        int result = JOptionPane.showConfirmDialog(null, panel,
                "School Contribution", JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.PLAIN_MESSAGE);

        if (result == JOptionPane.YES_OPTION) {
            //System.out.println(txtName.getText() + ", " + txtAddress.getText());
        } else {
            //System.out.println("Canceled");
            System.exit(0);
        }

}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote