Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CS Project import java.util.ArrayList; public class Campaign { private String candidateName; private ArrayList donors; public Campaign(String name) { //TODO Initialize all of the instance data

CS Project

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

import java.util.ArrayList;

public class Campaign {

private String candidateName; private ArrayList donors; public Campaign(String name) { //TODO Initialize all of the instance data } public String getCandidateName() { //TODO Complete the accessor return null; // stub }

public String getDonors() { String result = candidateName + " "; result += donors.toString(); return result; } public double getAllDonations() { double sum = 0.0; for (int i=0; i

return 0.0; // stub } public String getDonationList(String donor) { for (int i=0; i

return "No donor with that name was found"; } public void addDonation(String donorName, double donation) { // TODO Complete this method } }

import java.util.ArrayList;

public class Donor { private String name; private ArrayList donations; public Donor(String name) { this.name = name; this.donations = new ArrayList(); }

public Donor (String name, double donation) { this(name); donations.add(donation); } public String getName() { return name; } public double getTotalDonations() { double sum = 0.0; for (int i=0; i

import java.util.Scanner;

/** This class runs a campaign for Donald Duck. * * @author Deborah A. Trytten * */ public class Fall2016 {

// These constants are used for a menu system private static final int ADD_DONOR = 1; private static final int DONATION = 2; private static final int SUM_DONATIONS = 3; private static final int SINGLE_DONOR_DETAILS = 4; private static final int QUIT = 5; public static void main(String[] args) { Campaign candidate = new Campaign("Donald Duck"); Scanner keyboard = new Scanner(System.in); int menuChoice = 0; while (menuChoice != QUIT) { menuChoice = menu(keyboard); if (menuChoice == ADD_DONOR) addDonor(keyboard, candidate); else if (menuChoice == DONATION) addDonation(keyboard, candidate); else if (menuChoice == SUM_DONATIONS) sumDonations(candidate); else if (menuChoice == SINGLE_DONOR_DETAILS) singleDonorDetails(keyboard, candidate); else if (menuChoice == QUIT) System.out.println("Goodbye"); else System.out.println("Unanticipated case"); } }

private static final int menu(Scanner keyboard) { System.out.println("Enter your choice below"); System.out.println(ADD_DONOR + ": add new donor"); System.out.println(DONATION + ": make donation"); System.out.println(SUM_DONATIONS + ": find total donations"); System.out.println(SINGLE_DONOR_DETAILS + ": single donor details"); System.out.println(QUIT + ": quit"); int value = keyboard.nextInt(); keyboard.nextLine(); if (value QUIT) { System.out.println(value + " is not in the legal range. Please re-enter"); return menu(keyboard); // this is a cool trick called recursion } else // it was legal { return value; } } private static void addDonor(Scanner keyboard, Campaign candidate) { System.out.println("Enter the name of the donor"); String name = keyboard.nextLine(); candidate.addDonor(name); } private static void addDonation(Scanner keyboard, Campaign candidate) { //TODO Fill in this method } private static void sumDonations(Campaign candidate) { System.out.println(candidate.getCandidateName() + " has $" + candidate.getAllDonations() + " of donations"); } private static void singleDonorDetails(Scanner keyboard, Campaign candidate) { //TODO Fill in this method

} }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions

Question

Know the three main dimensions of the service environment.

Answered: 1 week ago