I need help with basic java for my assignment- these are the instructions. write
ID: 3577182 • Letter: I
Question
I need help with basic java for my assignment- these are the instructions.
write a program for a charity organization containing 4 classes. One class will be for the main class called YourName.java. The remaining will be for a parent class and child classes.
- program must have a menu with a quit/exit menu item that will allow the user to exit.
-Write a class called Person that contains – first name, last name, city, state, zip code, and phone number. Write the appropriate set and get methods for private variables.
-Write a class called Employee that inherits from the Person Class. The Employee class contains-- employee number, employee hourly rate, hire, date. Write the appropriate set and get methods.
-Write a class called Donor that inherits from the Person class. The Donor class contains-- donation amount, donation date, donor status type. Write the appropriate set and get methods.
-Employee info: allow the user to add and/or delete as many employees as they wish. Use an Arraylist. Ask for name, city, state, zip, phone number, employee number, hourly rate, and hire date. Also, calculate a weekly salary for the employee of 40 hrs. (hourly salary rate x weekly salary ). Display the Employee info immediately after updates, including the calculated weekly salary.
-Donor info: allow the user to add and/or delete as many donors as they wish. create and Arraylist. Ask for name, city, state, phone number, donation amount, and donation date. Include the type of donor status from next step. Display the donor info immediately after updates, including the donation status.
-Donation Status: display the status of the donor. if the donation is over 100000 they are a "founding member", if the donation is between 100000 and 50000 they are a "chartermember", if the donation is between 50000 and 10000 they are a "friend member", if 10000 or less they are a "contributor" - set the donor status for the donor.
-Calculate future interest earnings of donation using simple interest: ask for an interest rate and a time in years. display the result.
-write a method in your assignment class, or create a new class with a method that will write the list of donors data to a file called donorlist.txt. write code to create a directory. write code to create the file: donorlist.txt. ask the user for filename. write the following items to the file: first and last name, city, state, zip, phone number, donation date, donation status. use a comma delimiter to separate the data fields.
Thank you - help is much appreciated
Explanation / Answer
MAINCLASS
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
public class YourName {
static ArrayList<Employee1> employees = new ArrayList<Employee1>();
static ArrayList<Donor> donors = new ArrayList<Donor>();
static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
while (true) {
System.out.println("Menu");
System.out.println("1:Add an Employee");
System.out.println("2:Remove an Employee");
System.out.println("3:Print Employee Details");
System.out.println("4:Add Donor");
System.out.println("5:Remove Donor");
System.out.println("6:Print Donor Details");
System.out.println("7:Calculate future interest");
System.out.println("8:Exit");
System.out.println("Enter your option:");
int option = in.nextInt();
switch (option) {
case 1:
add_employee();
break;
case 2:
removeEmployee();
break;
case 3:
displayEmployee();
break;
case 4:
add_donor();
break;
case 5:
removeDonor();
break;
case 6:
displayDonors();
break;
case 7:
futureInterestDonors();
break;
case 8:
System.exit(0);
break;
}
}
}
public static void displayEmployee() {
for (Employee1 e : employees) {
System.out.println(e.toString());
}
}
public static void displayDonors() {
for (Donor e : donors) {
System.out.println(e.toString());
}
}
public static void futureInterestDonors() {
System.out.println("Enter interest rate");
double r = in.nextDouble();
System.out.println("Enter number of years");
int t = in.nextInt();
for (Donor e : donors) {
System.out.println(e.first_name + " " + (e.getDonation_amount() * t * r / 100));
}
}
public static void removeEmployee() {
boolean flag = false;
System.out.println("Enter employee id of Employee to be removed");
int emp_id = in.nextInt();
int index = 0;
for (Employee1 e : employees) {
if (e.getEmployee_num() == emp_id) {
flag = true;
employees.remove(index);
break;
}
index++;
}
if (flag == false)
System.out.println("Employee doesnt exist!");
}
public static void removeDonor() {
boolean flag = false;
System.out.println("Enter first name of donor to be removed");
String fn = in.next();
System.out.println("Enter last name of donor to be removed");
String ln = in.next();
int index = 0;
for (Donor d : donors) {
if (d.getFirst_name().equals(fn) && d.getLast_name().equals(ln)) {
flag = true;
donors.remove(index);
break;
}
index++;
}
if (flag == false)
System.out.println("Donor doesnt exist!");
}
public static void add_employee() {
Employee1 e = new Employee1();
System.out.println("Enter first name");
e.setFirst_name(in.next());
System.out.println("Enter last name");
e.setLast_name(in.next());
System.out.println("Enter city");
e.setCity(in.next());
System.out.println("Enter state");
e.setState(in.next());
System.out.println("Enter Pincode");
e.setPin_code(in.nextInt());
System.out.println("Enter Phone Number");
e.setPhone_num(in.nextInt());
System.out.println("Enter Employee Number");
e.setEmployee_num(in.nextInt());
System.out.println("Enter Hourly Rate");
e.setHourly_rate(in.nextDouble());
System.out.println("Enter Hire Date");
e.setHire_date(in.next());
employees.add(e);
}
public static void add_donor() {
Donor e = new Donor();
System.out.println("Enter first name");
e.setFirst_name(in.next());
System.out.println("Enter last name");
e.setLast_name(in.next());
System.out.println("Enter city");
e.setCity(in.next());
System.out.println("Enter state");
e.setState(in.next());
System.out.println("Enter Pincode");
e.setPin_code(in.nextInt());
System.out.println("Enter Phone Number");
e.setPhone_num(in.nextInt());
System.out.println("Enter Donation Amount");
e.setDonation_amount(in.nextInt());
System.out.println("Enter Donation Date");
e.setDonation_date(in.next());
if (e.getDonation_amount() > 100000)
e.setDonar_status_type("founding member");
else if (e.getDonation_amount() > 50000)
e.setDonar_status_type("chartermember");
else if (e.getDonation_amount() > 10000)
e.setDonar_status_type("friend membe");
else
e.setDonar_status_type("contributor");
donors.add(e);
}
}
DONOR CLASS
public class Donor extends Person1 {
int donation_amount;
String donation_date;
String donar_status_type;
public int getDonation_amount() {
return donation_amount;
}
public void setDonation_amount(int donation_amount) {
this.donation_amount = donation_amount;
}
public String getDonation_date() {
return donation_date;
}
public void setDonation_date(String donation_date) {
this.donation_date = donation_date;
}
public String getDonar_status_type() {
return donar_status_type;
}
public void setDonar_status_type(String donar_status_type) {
this.donar_status_type = donar_status_type;
}
public Donor(String first_name, String last_name, String city, String state, int pin_code, int phone_num,
int donation_amount, String donation_date, String donar_status_type) {
super(first_name, last_name, city, state, pin_code, phone_num);
this.donation_amount = donation_amount;
this.donation_date = donation_date;
this.donar_status_type = donar_status_type;
}
public Donor() {
super();
}
@Override
public String toString() {
return "Donor [donation_amount=" + donation_amount + ", donation_date=" + donation_date + ", donar_status_type="
+ donar_status_type + ", first_name=" + first_name + ", last_name=" + last_name + ", city=" + city
+ ", state=" + state + ", pin_code=" + pin_code + ", phone_num=" + phone_num + "]";
}
}
Person class
public class Person1 {
String first_name;
String last_name;
String city;
String state;
int pin_code;
int phone_num;
public String getFirst_name() {
return first_name;
}
public void setFirst_name(String first_name) {
this.first_name = first_name;
}
public String getLast_name() {
return last_name;
}
public void setLast_name(String last_name) {
this.last_name = last_name;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public int getPin_code() {
return pin_code;
}
public void setPin_code(int pin_code) {
this.pin_code = pin_code;
}
public int getPhone_num() {
return phone_num;
}
public void setPhone_num(int phone_num) {
this.phone_num = phone_num;
}
public Person1() {
super();
}
public Person1(String first_name, String last_name, String city, String state, int pin_code, int phone_num) {
super();
this.first_name = first_name;
this.last_name = last_name;
this.city = city;
this.state = state;
this.pin_code = pin_code;
this.phone_num = phone_num;
}
}
EMPLOYEE CLASS
import java.util.Date;
public class Employee1 extends Person1 {
int employee_num;
double hourly_rate;
String hire_date;
public int getEmployee_num() {
return employee_num;
}
public void setEmployee_num(int employee_num) {
this.employee_num = employee_num;
}
public double getHourly_rate() {
return hourly_rate;
}
public void setHourly_rate(double hourly_rate) {
this.hourly_rate = hourly_rate;
}
public String getHire_date() {
return hire_date;
}
public void setHire_date(String hire_date) {
this.hire_date = hire_date;
}
public Employee1(String first_name, String last_name, String city, String state, int pin_code, int phone_num,
int employee_num, double hourly_rate, String hire_date) {
super(first_name, last_name, city, state, pin_code, phone_num);
this.employee_num = employee_num;
this.hourly_rate = hourly_rate;
this.hire_date = hire_date;
}
public Employee1() {
super();
}
@Override
public String toString() {
return "Employee1 [employee_num=" + employee_num + ", hourly_rate=" + hourly_rate + ", hire_date=" + hire_date
+ ", first_name=" + first_name + ", last_name=" + last_name + ", city=" + city + ", state=" + state
+ ", pin_code=" + pin_code + ", phone_num=" + phone_num + "]";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.