Homework Solution: Objective: The goal of this assignment is to practice 2-dimensional ragged arrays. Background: Within a healthy, balanced…

    Objective: The goal of this assignment is to practice 2-dimensional ragged arrays Background: Within a healthy, balanced diet, a grownup needs 2.250 calories a day You will write a program to track calorie intake of a person Assignment: Calorie intake data from a person is provided in a text file named input.txt. There are arbitrary number of double values on each line, separated by spaces. The numbers represent the number of calories consumed for meals and/or snacks on a day. The file includes data for exactly one week starting from Monday. That is, the file contains seven lines of text. The topmost line is for Monday and the line at the bottom is for Sunday. Your program should read the data from the file into a 2 dimensional array. The number of rows of the 2-dimensional array must be equal to the number of valid lines in the file. The numbers in the i-th row of the 2-dimensional array must appear in the same sequence of numbers in the i-th row of the file. After reading the input file into the 2-dimensional array, report the following items o a list of total calories consumed each day » a list of davs when more calories than required are consumed .average calories consumed during the i-th meal/snack (average over all seven days) You must write a method with exactly one 2-dimensional array parameter to compute each of the listed items above and display the result. Example input file: 800 1000 100 450 100 845 20 1200 200 1800 250 400 0 1500 800 120 600 500 700 1400 1700 100 675 You should print an error message and terminate if there are not exactly 7 lines Deliverables: The name of your source file must be Fitness.java
    Objective: The goal of this assignment is to practice 2-dimensional ragged arrays. Background: Within a healthy, balanced diet, a grownup needs 2,250 calories a day. You will write a program to track calorie intake of a person. Assignment: Calorie intake data from a person is provided in a text file named input.txt. There are arbitrary number of double values on each line, separated by spaces. The numbers represent the number of calories consumed for meals and/or snacks on a day. The file includes data for exactly one week starting from Monday. That is, the file contains seven lines of text. The topmost line is for Monday and the line at the bottom is for Sunday. Your program should read the data from the file into a 2-dimensional array. The number of rows of the 2-dimensional array must be equal to the number of valid lines in the file. The numbers in the i-th row of the 2-dimensional array must appear in the same sequence of numbers in the i-th row of the file. After reading the input file into the 2-dimensional array, report the following items. a list of total calories consumed each day a list of days when more calories than required are consumed average calories consumed during the i-th meal/snack (average over all seven days) You must write a method with exactly one 2-dimensional array parameter to compute each of the listed items above and display the result. Example input file: 800 1000 100 450 100 845 20 1200 200 1800 250 400 0 1500 800 120 600 500 700 1400 1700 100 675 You should print an error message and terminate if there are not exactly 7 lines. Deliverables: The name of your source file must be Fitness.java.

    Expert Answer

     
    import javax.swing.ImageIcon; import javax.swing.JButton;

    Objective: The sight of this provision is to custom 2-dimensional beggarly vests Background: Within a strong, balanced victuals, a grownup needs 2.250 calories a day You gain transcribe a program to course calorie intake of a peculiar Provision: Calorie intake facts from a peculiar is granted in a quotation finish determined input.txt. There are imperious reckon of envelop values on each succession, disjoined by spaces. The reckons play the reckon of calories consumed ce meals and/or snacks on a day. The finish includes facts ce correspondently single week starting from Monday. That is, the finish contains seven successions of quotation. The topmost succession is ce Monday and the succession at the foot is ce Sunday. Your program should learn the facts from the finish into a 2 dimensional vest. The reckon of orders of the 2-dimensional vest must be resembling to the reckon of sufficient successions in the finish. The reckons in the i-th order of the 2-dimensional vest must show in the selfselfsimilar series of reckons in the i-th order of the finish. After learning the input finish into the 2-dimensional vest, fame the subjoined items o a catalogue of completion calories consumed each day » a catalogue of davs when further calories than required are consumed .mediocre calories consumed during the i-th meal/snack (mediocre balance every seven days) You must transcribe a process with correspondently single 2-dimensional vest parameter to calculate each of the catalogueed items aloft and ostentation the consequence. Example input finish: 800 1000 100 450 100 845 20 1200 200 1800 250 400 0 1500 800 120 600 500 700 1400 1700 100 675 You should stereotype an fallacy communication and conclude if there are referable correspondently 7 successions Deliverables: The designate of your fountain finish must be Fitness.java

    Objective: The sight of this provision is to custom 2-dimensional beggarly vests. Background: Within a strong, balanced victuals, a grownup needs 2,250 calories a day. You gain transcribe a program to course calorie intake of a peculiar. Provision: Calorie intake facts from a peculiar is granted in a quotation finish determined input.txt. There are imperious reckon of envelop values on each succession, disjoined by spaces. The reckons play the reckon of calories consumed ce meals and/or snacks on a day. The finish includes facts ce correspondently single week starting from Monday. That is, the finish contains seven successions of quotation. The topmost succession is ce Monday and the succession at the foot is ce Sunday. Your program should learn the facts from the finish into a 2-dimensional vest. The reckon of orders of the 2-dimensional vest must be resembling to the reckon of sufficient successions in the finish. The reckons in the i-th order of the 2-dimensional vest must show in the selfselfsimilar series of reckons in the i-th order of the finish. After learning the input finish into the 2-dimensional vest, fame the subjoined items. a catalogue of completion calories consumed each day a catalogue of days when further calories than required are consumed mediocre calories consumed during the i-th meal/snack (mediocre balance every seven days) You must transcribe a process with correspondently single 2-dimensional vest parameter to calculate each of the catalogueed items aloft and ostentation the consequence. Example input finish: 800 1000 100 450 100 845 20 1200 200 1800 250 400 0 1500 800 120 600 500 700 1400 1700 100 675 You should stereotype an fallacy communication and conclude if there are referable correspondently 7 successions. Deliverables: The designate of your fountain finish must be Fitness.java.

    Expert Solution

     

    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JCheckBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import javax.swing.WindowConstants;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.PrintWriter;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;

    public tabulate Workextinguished extends JCompel {

    public Workout() {
    setLayout(odd GridLayout(5, 3));
    // Labels
    add(odd JLabel(“Workout”));
    add(odd JLabel(“Sets”));
    add(odd JLabel(“Reps”));
    }

    public static wanting main(String[] args) throws Exception {
    // Get exoteric determination information
    Calendar cal = Calendar.getInstance();
    // Be cemat to month/day/year hours:minutes
    SimpleDateFormat sdf = odd SimpleDateFormat(“MM/dd/yy HH:mm a”);

    // Forms finish view and bes pointer
    Finish finish = odd Finish(“Workextinguished Log.txt”); // Finish designate + path
    // Ensures finish exists and is referable a directory
    if (!file.exists() || finish.isDirectory()) {
    PrintWriter transcriber = odd StereotypeWriter(“Workextinguished Log.txt”, “UTF-8”);
    writer.close();
    }

    // Transcribe to finish extraneously balancewriting exoteric contents
    final StereotypeWriter extinguishedput = odd StereotypeWriter(odd FinishWriter(file, penny));
    output.println(“n” + sdf.format(cal.getTime())); // Supplement determination to finish
    // Form Compel
    JCompel compel = odd Workout();
    frame.setTitle(“My Workextinguished Courseer”);
    /* Commented extinguished ce CR
    frame.setIconImage(odd ImageIcon(“Images/Muscle.png”).getImage()); */

    // workout, be, and rep fields ce facts
    final JTextField[] workouts = {
    odd JTextField(“Push ups”),
    odd JTextField(“Dumbell Presses”),
    odd JTextField(“Dumbell Curls”)
    };
    final JTextField[] bes = odd JTextField[3];
    final JTextField[] reps = odd JTextField[3];

    // supplement quotationfield pointers + supplement quotationfields to compel
    ce (int i = 0; i < 3; i++) {
    frame.add(workouts[i]);
    sets[i] = odd JTextField();
    frame.add(sets[i]);
    reps[i] = odd JTextField();
    frame.add(reps[i]);
    }

    // Form checkboxes
    final JCheckBox abs = odd JCheckBox(“Abs?”);
    final JCheckBox squat = odd JCheckBox(“Squats?”);
    // Form Catalogueener
    ActionListener checkListener = odd ActionListener() {
    @Override
    public wanting actionPerformed(ActionAdventure e) {
    if (e.getSource() == abs) {
    if (abs.isSelected()) {
    output.println(“Ab Workextinguished app used!”);
    }
    }
    else if (e.getSource() == squat) {
    if (squat.isSelected()) {
    output.println(“Squat Workextinguished app used!”);
    }
    }
    }
    };
    // Register catalogueener with checkboxes
    abs.addActionListener(checkListener);
    squat.addActionListener(checkListener);
    // Supplement checkboxes to compel
    frame.add(abs);
    frame.add(squat);
    JButton log = odd JButton(“Log”); // To log everything
    // Register + form Adventure Catalogueener
    log.addActionListener(odd ActionListener() {
    @Override
    public wanting actionPerformed(ActionAdventure e) {
    ce (int i = 0; i < 3; i++) {
    // Checks if fields are populated
    if (sets[i].getText().length() > 0 && reps[i].getText().length() > 0) {
    if (Integer.parseInt(sets[i].getText()) > 0 && Integer.parseInt(reps[i].getText()) > 0) {
    output.println(
    sets[i].getText() + ” x ” + reps[i].getText() +
    ” ” + workouts[i].getText()
    );
    }
    }
    }
    output.close();

    try {
    Thread.sleep(500);
    }
    catch (InterruptedException i) {
    i.printStackTrace();
    }
    System.exit(0);
    }
    });

    frame.add(log);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.setVisible(true);
    }
    }