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

I do not understand how to place this within an array to make it work properly .

ID: 3771550 • Letter: I

Question

I do not understand how to place this within an array to make it work properly . Please help
Part 2 Part 3 Each line of the data file will still contain an identifier and a number T number of tickets sold D -donations E- expenses The number following the D and E identifiers will still be dollar and cents amounts. But the number following the T identifier will now be an integer number of tickets sold Sample data file lines would be: T 25 E 210.99 T1 D 500.00 E 134.67 Program Requirements 1) Modify the Event class as follows a) Modify the private data properties in the Event class. Add a static constant to hold the maximum number of donations the array can hold (200) Instead of a donation total property, create a donation array (that can hold up to 200 individual donation amounts). Add a number of donations property to keep track of the number of donation amounts stored in the array Instead of a total ticket sale income property, create two separate properties: the single ticket price o the total number of tickets sold o . The expenses property will still hold the total of all expenses for an event. b) Replace the constructor in the Event class to be a constructor with a parameter for the ticket price, used to initialize the single ticket price property All other properties should be initialized to 0

Explanation / Answer


package arrayevents;
import java.io.*;
import java.util.Scanner;
public class MainEvent {
        public static char readLetter (){
        Scanner keyboard = new Scanner(System.in);
        System.out.print("Enter new type (T/D/E): ");
        char letter = keyboard.next().charAt(0);
        while ((letter != 'T') && (letter != 'D') && (letter != 'E') &&
                (letter != 't') && (letter != 'd') && (letter != 'e')) {
            System.out.println(" Error - new type must be 'T' 'D' or 'E'");
            System.out.print("Enter new type (T/D/E): ");
            letter = keyboard.next().charAt(0);
        }
        return Character.toUpperCase(letter);
    }
        public static double readAmount (){
        Scanner keyboard = new Scanner(System.in);
        System.out.print("Enter type amount: ");
        double amount = keyboard.nextDouble();
        while (amount <= 0) {
            System.out.println(" Error - new must more than 0");
            System.out.print("Enter type amount: ");
            amount = keyboard.nextDouble();
        }
        return amount;
    }
  
    public static void main(String[] args) {
        System.out.println("This program will read data from a charity event" +
                " and display the events income, donations and expenses ");
      
    
        MainEvent event = new MainEvent();
      
        //set initial value
        int lineNumber = 0;
        String line = null;
        double number = 0;
        char letter = 'y';
        char response = 'y';
      
        //try catch to open file and read data
        try {
            BufferedReader in = new BufferedReader(new FileReader("Event.txt"));
            while ((line = in.readLine()) != null) {
            lineNumber++;
            letter = line.charAt(0);
            String amount = line.substring(line.indexOf(" ") + 1, line.length());
            number = Double.parseDouble(amount);
            event.addToo(letter, number);
            }
            in.close();
        } catch (FileNotFoundException ex) {
                System.out.println(ex.getMessage() + " File was not found");
        } catch (IOException ex) {
            System.out.println(ex.getMessage() + " Data not found");
        }
        //displays how many lines are read from data
        System.out.println("There are " + lineNumber + " valid lines of data");
      
        System.out.printf(" Donations = %.2f", event.getDonations());
        System.out.printf(" Expenses = %.2f", event.getExpenses());
        System.out.printf(" Income = %.2f ", event.getSales());
      
      
        do {
            Scanner keyboard = new Scanner(System.in);
            System.out.print(" Would you like to add more data?" +
                    "(Enter (Y/N): ");
            response = keyboard.next().charAt(0);
      
            while((response != 'Y') && (response != 'y') && (response != 'N') &&
                    (response != 'n')) {
                System.out.println(" Error, answer must be 'Y' or 'N'.");
                System.out.print("Would you like to enter more data? ");
                response = keyboard.next().charAt(0);
            }
      
            if (response == 'Y' || response == 'y') {
                letter = readLetter();
                number = readAmount();
                event.addToo(letter, number);
            }
        } while (response == 'Y' || response == 'y');
      
      
        event.display();
}
}

package arrayevents;
import java.io.*;
import java.util.Scanner;
public class ArrayEvent {
    //set private properties
    private double eventIncome;
    private double eventDonations;
    private double eventExpenses;
  
    //initialize constructors
    public ArrayEvent () {
        eventIncome = 0;
        eventDonations = 0;
        eventExpenses = 0;
    }
  
    //returns current income
    public double getSales(){
        return eventIncome;
    }
  
    //returns current donations
    public double getDonations(){
        return eventDonations;
    }
  
    //returns current expenses
    public double getExpenses(){
        return eventExpenses;
    }
  
  
    public void addToo (char type, double amount){
        if (amount <= 0) {
            throw new IllegalArgumentException("addToo(): bad argument " +
            "Amount must be positive");
        }
        if ((type != 'T') && (type != 'D') && (type != 'E')) {
            throw new IllegalArgumentException("addToo(): bad argument " +
            "Character must be 'T', 'D' or 'E'");
        }
        if (type == 'T') {
            eventIncome = eventIncome + amount;
        }
        else if (type == 'D') {
            eventDonations = eventDonations + amount;
        }
        else {
            eventExpenses = eventExpenses + amount;
        }
      
    }
  

    public double display () {
        double income = eventIncome + eventDonations;
        double profits = income - eventExpenses;
        System.out.printf(" Event Overall Outcome: " +
            " Total ticket sales: %.2f Total donations: %.2f + " +
            " -------- Total income: %.2f " +
            "Total expenses: %.2f - -------- " +
            "Event profits: %.2f ", eventIncome, eventDonations, income,
            eventExpenses, profits);
      
        return profits;
    }
}

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