The class’s needed are:
- A Donor class that has class attributes of a donor’s name, hometown, and a charitable point scale (this is a number between 0 and 4). This is a normal regular object that you should know how to create by now.
- A Charity class that has class attributes of a charity name, its acronym, an arraylist or array of Donor’s, and probably a Decimal Formatter. Depending on how you write your code, you may need another variable or two.
Methods needed but not limited to:
Setters and getters
A method to create a Donor and add it to your arraylist or array.
A method to output the all of data of a Donor including overall
charitable point scale and number of Donors.
A method to calculate the Charities overall charitable point scale.
A method that uses either the Merge or Quick sort to sort the
Donors in a Charity in descending order by charitable point scale.
A method that will output all of the Charities that qualify for the
“Golden Goose” award which is based on Charities that have an
overall charitable point scale of 3.00 or higher.
A method that will output all of the Charities that qualify for the
“Feels Great to Give” award based on the Charities that have an
overall charitable point scale of 2.00 up to 3.00.
A method that will output all of the Charities that qualify for the
“Happy to Help” award based on the Charities that have an overall
charitable point scale 1.00 up to 2.00.
A method that will output all of the Charities that qualify for the
“Something’s Better than Nothing” award based on the Charities
that have an overall charitable point scale 0.00 up to 1.00.
A method to write each Charity and its Donors data to a file.
Screenshot
Program
Donor.java
//Create a class Donor
public class Donor {
//Attributes
private String name;
private String homeTown;
private double points;
//Constructor
public Donor(String name,String town,double scale)
{
this.name=name;
this.homeTown=town;
if(scale<0 || scale>4)
{
System.out.println("Set default!!!");
points=0;
}
else {
points=scale;
}
}
//Getters and setters
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getHomeTown() {
return homeTown;
}
public void setHomeTown(String homeTown) {
this.homeTown = homeTown;
}
public double getPoints() {
return points;
}
public void setPoints(double points) {
if(points<0 || points>4)
{
System.out.println("Set default!!!");
this.points=0;
}
else {
this.points=points;
}
}
}
Charity.java
import java.io.FileWriter;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Scanner;
//Create a class Charity
public class Charity {
//Attributes
private String name;
private ArrayList<Donor> donors;
private Scanner sc=new Scanner(System.in);
private DecimalFormat df=new
DecimalFormat(".##");
//Constructor
public Charity(String name) {
if(name.length()>5) {
System.out.println("Take first 5 letler as name!!");
this.name=name.substring(0,5);
this.name=this.name.toUpperCase();
}
else {
this.name=name;
}
donors=new
ArrayList<Donor>();
}
//Setters and getters
public String getName() {
return name;
}
public void setName(String name) {
if(name.length()>5) {
System.out.println("Take first 5 letler as name!!");
this.name=name.substring(0,5);
this.name=this.name.toUpperCase();
}
else {
this.name=name;
}
}
public ArrayList<Donor> getDonors() {
return donors;
}
public void setDonors(ArrayList<Donor> donors)
{
this.donors = donors;
}
//A method to create a Donor and add it to your
arraylist
public void addDonor() {
System.out.print("Enter donor name:
");
String name=sc.nextLine();
System.out.print("Enter donor
hometown: ");
String town=sc.nextLine();
System.out.print("Enter charity
points(0-4): ");
int points=sc.nextInt();
sc.nextLine();
Donor donor=new
Donor(name,town,points);
donors.add(donor);
}
//A method to output the all of data of a Donor
including overall
//charitable point scale and number of
Donors.
public void displayDetails() {
System.out.println("Charity Trust
"+name+"'s Donor's Details:-");
System.out.println("Donor
name
Hometown
Charity points");
for(int i=0;i<donors.size();i++)
{
System.out.printf("%-20s%-18s
%.2f\n",donors.get(i).getName(),donors.get(i).getHomeTown(),donors.get(i).getPoints());
}
System.out.println("\nTotal
donors="+donors.size());
System.out.println("Total
points="+getOverallPoints());
System.out.println();
}
//A method to calculate the Charities overall
charitable point scale.
public int getOverallPoints() {
int totPoints=0;
for(int i=0;i<donors.size();i++)
{
totPoints+=donors.get(i).getPoints();
}
return totPoints;
}
//Sort using quicksort
protected ArrayList<Donor> quickSort(
ArrayList<Donor> donors)
{
if (donors.size() <=
1)
return donors; // Already sorted
ArrayList<Donor>
sorted = new ArrayList<Donor>();
ArrayList<Donor> lesser
= new ArrayList<Donor>();
ArrayList<Donor>
greater = new ArrayList<Donor>();
int pivot = (donors.size())-1; //
Use last Vehicle as pivot
for (int i = 0; i <
donors.size()-1; i++)
{
//int
order = list.get(i).compareTo(pivot);
if
(donors.get(i).getPoints()>donors.get(pivot).getPoints() )
lesser.add(donors.get(i));
else
greater.add(donors.get(i));
}
lesser =
quickSort(lesser);
greater =
quickSort(greater);
lesser.add(donors.get(pivot));
lesser.addAll(greater);
sorted = lesser;
return sorted;
}
//A method that will output all of the Charities that
qualify for the
//“Golden Goose” award which is based on
Charities that have an
//overall charitable point scale of 3.00 or
higher.
public void getGoldenGoose() {
System.out.println("Charity Trust
"+name+"'s Golde Goose Awarded Donor's Details:-");
System.out.println("Donor
name
Hometown
Charity points");
for(int i=0;i<donors.size();i++)
{
if(donors.get(i).getPoints()>=3.0) {
System.out.printf("%-20s%-18s
%.2f\n",donors.get(i).getName(),donors.get(i).getHomeTown(),donors.get(i).getPoints());
}
}
System.out.println();
}
//A method that will output all of the Charities
that qualify for the
//“Feels Great to Give” award based on the Charities
that have an
//overall charitable point scale of 2.00 up to
3.00.
public void getFeelGreat() {
System.out.println("Charity Trust
"+name+"'s Feel Great Awarded Donor's Details:-");
System.out.println("Donor
name
Hometown
Charity points");
for(int i=0;i<donors.size();i++)
{
if(donors.get(i).getPoints()>=2.0 &&
donors.get(i).getPoints()<3.0) {
System.out.printf("%-20s%-18s
%.2f\n",donors.get(i).getName(),donors.get(i).getHomeTown(),donors.get(i).getPoints());
}
}
System.out.println();
}
//A method that will output all of the Charities that
qualify for the
//“Happy to Help” award based on the Charities that
have an overall
//charitable point scale 1.00 up to 2.00.
public void getHappyToHelp() {
System.out.println("Charity Trust
"+name+"'s Happy to Help Awarded Donor's Details:-");
System.out.println("Donor
name
Hometown
Charity points");
for(int i=0;i<donors.size();i++)
{
if(donors.get(i).getPoints()>=1.0 &&
donors.get(i).getPoints()<2.0) {
System.out.printf("%-20s%-18s
%.2f\n",donors.get(i).getName(),donors.get(i).getHomeTown(),donors.get(i).getPoints());
}
}
System.out.println();
}
//A method that will output all of the Charities that
qualify for the
//“Something’s Better than Nothing” award based on the
Charities
//that have an overall charitable point scale 0.00 up
to 1.00.
public void getSomething() {
System.out.println("Charity Trust
"+name+"'s Something’s Better than Nothing Awarded Donor's
Details:-");
System.out.println("Donor
name
Hometown
Charity points");
for(int i=0;i<donors.size();i++)
{
if(donors.get(i).getPoints()>=0.0 &&
donors.get(i).getPoints()<1.0) {
System.out.printf("%-20s%-18s
%.2f\n",donors.get(i).getName(),donors.get(i).getHomeTown(),donors.get(i).getPoints());
}
}
System.out.println();
}
//A method to write each Charity and its Donors data
to a file.
public void writeData() {
try{
FileWriter fw=new
FileWriter("CharityFile.txt",true);
for(int
i=0;i<donors.size();i++) {
fw.write(donors.get(i).getName()+","+donors.get(i).getHomeTown()+","+donors.get(i).getPoints()+System.lineSeparator());
}
fw.close();
}catch(Exception e){System.out.println(e);}
System.out.println("File append Success...");
}
}
CharityTest.java
public class CharityTest {
public static void main(String[] args) {
//Create a charity trust
Charity ch=new
Charity("ATMS");
//Add donors
for(int i=0;i<3;i++) {
ch.addDonor();
}
//Different method test
ch.displayDetails();
ch.setDonors(ch.quickSort(ch.getDonors()));
ch.displayDetails();
ch.getGoldenGoose();
ch.writeData();
}
}
-----------------------------------
Output
Enter donor name: Millis
Enter donor hometown: manmar
Enter charity points(0-4): 4
Enter donor name: Mark
Enter donor hometown: Malli
Enter charity points(0-4): 1
Enter donor name: Jack
Enter donor hometown: Japan
Enter charity points(0-4): 3
Charity Trust ATMS's Donor's Details:-
Donor name
Hometown
Charity points
Millis
manmar
4.00
Mark
Malli
1.00
Jack
Japan
3.00
Total donors=3
Total points=8
Charity Trust ATMS's Donor's Details:-
Donor name
Hometown
Charity points
Millis
manmar
4.00
Jack
Japan
3.00
Mark
Malli
1.00
Total donors=3
Total points=8
Charity Trust ATMS's Golde Goose Awarded Donor's Details:-
Donor name
Hometown
Charity points
Millis
manmar
4.00
Jack
Japan
3.00
File append Success...
----------------------------------------
Charityfile.txt
Millis,manmar,4.0
Jack,Japan,3.0
Mark,Malli,1.0
The class’s needed are: - A Donor class that has class attributes of a donor’s name,...
Write a class that encapsulates the concept of a baseball player with the important attributes (name, position, hits, at bats, batting average). The class will have the following methods: Two constructors (a default and a constructor with all parameters) Accessors, mutators, toString, and equals methods The batting average property will not have a public setter, it will be updated any time the hits and/or at bats is set. The getter will round to three digits (.315 or .276, etc.) All...
1. Do the following a. Write a class Student that has the following attributes: - name: String, the student's name ("Last, First" format) - enrollment date (a Date object) The Student class provides a constructor that saves the student's name and enrollment date. Student(String name, Date whenEnrolled) The Student class provides accessors for the name and enrollment date. Make sure the class is immutable. Be careful with that Date field -- remember what to do when sharing mutable instance variables...
Create a java project and create Student class. This class should have the following attributes, name : String age : int id : String gender : String gpa : double and toString() method that returns the Student's detail. Your project should contain a TestStudent class where you get the student's info from user , create student's objects and save them in an arralist. You should save at least 10 student objects in this arraylist using loop statement. Then iterate through...
JAVA PROGRAMMING PLEASE This lab has three parts: Create an ArrayList class. Create a LinkedList class. Print out the results after testing each of the methods in both of the classes and solving a simple problem with them. Task 1 – ArrayList Class Create an ArrayList class. This is a class that uses an internal array, but manipulates the array so that the array can be dynamically changed. This class should contain a default and overloaded constructor, where the default...
Write you code in a class named HighScores, in file named HighScores.java. Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look approximately like this: Enter the name for score #1: Suzy Enter the score for score #1: 600 Enter the name for score...
C++ HELP! Create a class and name it Payslip. This class should have the following attributes or properties: name, pay grade, basic salary, overtime hours, overtime pay, gross pay, net pay and withholding tax. Define the accessors and mutators of the Payslip class based on its attributes or properties. This class should also have the following methods: determinePayGradeAndTaxRate and computePay. Create another class and name it Employee. This class will contain the main method. In the main method, instantiate an...
*in Java 1. Create a card class with two attributes, suit and rank. 2.In the card class, create several methods: a. createDeck – input what type of deck (bridge or pinochle) is to be created and output an array of either 52 or 48 cards. b.shuffleDeck – input an unshuffled deck array and return a shuffled one. + Create a swap method to help shuffle the deck c. countBridgePoints – inputs a 13-card bridge ‘hand’-array and returns the number of...
In java netbean8.1 or 8.2 please. The class name is Stock. It has 5 private attributes (name, symbol, numberOfShares, currentPrice and boughtPrice)and one static private attribute (numberOfStocks). All attributes must be initialized (name and symbol to “No name/ symbol yet” and numberOfShares, currentPrice and boughtPrice to 0. Create two constructors, one with no arguments and the other with all the attributes. (However, remember to increase the numberOfStocks in both constructors. Write the necessary mutators and accessors (getters and setters) for...
Assignment W3-2 This programming assignment addresses: •Compiling and Executing an App with more than 1 class •Initializing Objects using Constructors •Software Engineering with Private Instances Variables and Public Set/Get Methods •Uses Methods inside classes Description: You are asked to write a program to process two students’ scores. Each student will have scores for 3 tests, the user will input each student’s full name followed by their three scores. When the data for the two students are read from the keyboard,...
In Java: Executable Class create an array of Employee objects. You can copy the array you made for Chapter 20. create an ArrayList of Employee objects from that array. use an enhanced for loop to print all employees as shown in the sample output. create a TreeMap that uses Strings for keys and Employees as values. this TreeMap should map Employee ID numbers to their associated Employees. process the ArrayList to add elements to this map. print all employees in...