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

Write a program to manage Cost Plus membership list. Assume that the names, phon

ID: 3721506 • Letter: W

Question

Write a program to manage Cost Plus membership list.

Assume that the names, phone numbers, membership type, total cash back amount in 2017 of all members are stored in the text file members.txt

Part of the file is as follows (however, as a programmer, you do not know the exact number of members in this text file):

Judy Langley

301-141-1902

Gold

190.23

Fred Morgan

301-215-2972

Silver

90.88

Mike Nixon

301-903-3413

Gold

387.03

Herbert Norton

301-220-4444

Silver

32.52

Carol Preiss

301-895-2355

Gold

280.78

(25 points) In Member.java, define a class Member. This class should have the following private data members, getter and setter methods for each data member:

private String name;

private String phone;

private String type;

private double cashBack2017;

It also has a constructor that has the following method header:

public Member(String n, String p, String t, double amt2017)

In MemberManager.java,

(5 points) declare a static array of type Member. The name of this array is MemberArray. Assume there are no more than 100 members. Also declare a static integer variable numMembers to keep track of the actual number of members stored in the array.

public class MemberManager {

            static Member[] memberArray = new Member[100];

   static int numMembers = 0;

(20 points) Write a static method readDataFromFile. This method will read each member’s information from members.txt into the array MemberArray.

(Hint: inside a while loop

read and store each member’s information including name, phone number, membership type, total cash back amount in 2017

create a Member object by calling the appropriate constructor and passing the member’s information to the constructor

add this object to MemberArray

increment the counter variable numMembers)

public static void readDataFromFile()

(15 points) Write a static method displayAllMembers. This method will use printf statements to display the information about each member in the array MemberArray.

(15 points) Write a static method viewMembersByType. Given a specific membership type, the method will display the information about members with matching membership type. The method header is as follows:

public static void viewMembersByType(String mType)

(15 points) Write a static method computeCashBackStatistic. This method will compute and display the total amount, the maximum amount, the minimum amount, and the average amount of the members’ cash back in 2017. The method header is:

public static void computeCashBackStatistic()

(5 points) In MemberManager.java, write a main method that displays a menu with the 4 choices shown below. When the user enters a number, call the appropriate method.

Explanation / Answer


Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you
NOTE: Please make sure you place your input file in the correct folder. If using eclipse, the file should be in the project directly and NOT INSIDE src folder.

members.txt
------------
Judy Langley
301-141-1902
Gold
190.23
Fred Morgan
301-215-2972
Silver
90.88
Mike Nixon
301-903-3413
Gold
387.03
Herbert Norton
301-220-4444
Silver
32.52
Carol Preiss
301-895-2355
Gold
280.78


Member.java
-------------

public class Member {
private String name;
private String phone;
private String type;
private double cashBack2017;
public Member(String n, String p, String t, double amt2017)
{
name = n;
phone = p;
type = t;
cashBack2017 = amt2017;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public double getCashBack2017() {
return cashBack2017;
}
public void setCashBack2017(double cashBack2017) {
this.cashBack2017 = cashBack2017;
}


}


MemberManager.java
-------------------
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class MemberManager {
static Member[] memberArray = new Member[100];
static int numMembers = 0;

public static void readDataFromFile() throws FileNotFoundException
{
Scanner infile = new Scanner(new File("members.txt"));
while(infile.hasNext())
{
Member m = new Member(infile.nextLine(), infile.nextLine(), infile.nextLine(), infile.nextDouble());
memberArray[numMembers] = m;
numMembers++;
if(infile.hasNext())
infile.nextLine(); //get rid of newline before reading name
}
infile.close();
}
  
public static void displayAllMembers()
{
System.out.printf("%-30s %-15s %-15s %-15s ", "Name", "Phone", "Type", "Cashback");
for(int i = 0; i < numMembers; i++)
System.out.printf("%-30s %-15s %-15s %-15.2f ",
memberArray[i].getName(), memberArray[i].getPhone(),memberArray[i].getType(),
memberArray[i].getCashBack2017());
System.out.println();
}
  
public static void viewMembersByType(String mType)
{
System.out.printf("%-30s %-15s %-15s %-15s ", "Name", "Phone", "Type", "Cashback");
for(int i = 0; i < numMembers; i++)
{
if(memberArray[i].getType().equalsIgnoreCase(mType))
System.out.printf("%-30s %-15s %-15s %-15.2f ",
memberArray[i].getName(), memberArray[i].getPhone(),memberArray[i].getType(),
memberArray[i].getCashBack2017());
}
System.out.println();
}
public static void computeCashBackStatistic()
{
double total = 0, min = memberArray[0].getCashBack2017();
double max = memberArray[0].getCashBack2017(), avg ;
for(int i = 0; i < numMembers; i++)
{
total = total + memberArray[i].getCashBack2017();
if(memberArray[i].getCashBack2017() > max)
max = memberArray[i].getCashBack2017();
else if(memberArray[i].getCashBack2017() < min)
min = memberArray[i].getCashBack2017();
}

avg = total / numMembers;

System.out.printf("Total cash back: %.2f ", total);
System.out.printf("Average cash back: %.2f ", avg);
System.out.printf("Minimum cash back: %.2f ", min);
System.out.printf("Maximum cash back: %.2f ", max);
System.out.println();

}
  
public static void main(String[] args) {
int choice = 0;
Scanner keyboard = new Scanner(System.in);
try {
readDataFromFile();
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
System.exit(1);
}

while(choice != 4)
{
System.out.println("1. Display all members");
System.out.println("2. Display by type");
System.out.println("3. Compute statistics");
System.out.println("4. Quit");
System.out.print("Enter your choice: ");
choice = keyboard.nextInt();
if(choice == 1)
displayAllMembers();
else if(choice == 2)
{
String type;
System.out.print("Enter the member type to search: ");
type = keyboard.next();
viewMembersByType(type);
}
else if(choice == 3)
{
computeCashBackStatistic();
}
else if(choice != 4)
{
System.out.println("Invalid menu choice!");
}

System.out.println();
}
}
  
}


output
-=---
1. Display all members
2. Display by type
3. Compute statistics
4. Quit
Enter your choice: 1
Name Phone Type Cashback
Judy Langley 301-141-1902 Gold 190.23
Fred Morgan 301-215-2972 Silver 90.88   
Mike Nixon 301-903-3413 Gold 387.03
Herbert Norton 301-220-4444 Silver 32.52   
Carol Preiss 301-895-2355 Gold 280.78


1. Display all members
2. Display by type
3. Compute statistics
4. Quit
Enter your choice: 2
Enter the member type to search: Gold
Name Phone Type Cashback
Judy Langley 301-141-1902 Gold 190.23
Mike Nixon 301-903-3413 Gold 387.03
Carol Preiss 301-895-2355 Gold 280.78


1. Display all members
2. Display by type
3. Compute statistics
4. Quit
Enter your choice: 2
Enter the member type to search: Silver
Name Phone Type Cashback
Fred Morgan 301-215-2972 Silver 90.88   
Herbert Norton 301-220-4444 Silver 32.52   


1. Display all members
2. Display by type
3. Compute statistics
4. Quit
Enter your choice: 3
Total cash back: 981.44
Average cash back: 196.29
Minimum cash back: 32.52
Maximum cash back: 387.03


1. Display all members
2. Display by type
3. Compute statistics
4. Quit
Enter your choice: 4

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