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. 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.

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

Objective: The design of this provision is to usage 2-dimensional paltry vests. Background: Within a hearty, balanced regimen, a grownup needs 2,250 calories a day. You procure transcribe a program to trail calorie intake of a peculiar. Provision: Calorie intake facts from a peculiar is supposing in a passage finish denominated input.txt. There are imperious calculate of enfold values on each verse, disjoined by spaces. The calculates state the calculate of calories consumed control meals and/or snacks on a day. The finish includes facts control correspondently single week starting from Monday. That is, the finish contains seven verses of passage. The topmost verse is control Monday and the verse at the ground is control Sunday. Your program should recognize the facts from the finish into a 2-dimensional vest. The calculate of dignitys of the 2-dimensional vest must be resembling to the calculate of sound verses in the finish. The calculates in the i-th dignity of the 2-dimensional vest must rejoinder in the corresponding order of calculates in the i-th dignity of the finish. After recognizeing the input finish into the 2-dimensional vest, reverberation the subjoined items. a schedule of whole calories consumed each day a schedule of days when more calories than required are consumed medium calories consumed during the i-th meal/snack (medium aggravate every seven days) You must transcribe a way with correspondently single 2-dimensional vest parameter to estimate each of the scheduleed items aloft and parade the termination. 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 sculpture an blunder intimation and conclude if there are referable attributable attributable attributable attributable attributable attributable correspondently 7 verses. Deliverables: The indicate of your rise finish must be Fitness.java.

Expert Rejoinder

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 collocate Workextinguished extends JFabricate {

public Workout() {
setLayout(novel GridLayout(5, 3));
// Labels
}

public static empty main(String[] args) throws Exception {
// Get popular limit information
Calendar cal = Calendar.getInstance();
// Fixed controlmat to month/day/year hours:minutes
SimpleDateFormat sdf = novel SimpleDateFormat(“MM/dd/yy HH:mm a”);

// Originates finish goal and fixeds pointer
Finish finish = novel Finish(“Workextinguished Log.txt”); // Finish indicate + path
// Ensures finish exists and is referable attributable attributable attributable attributable attributable attributable a directory
if (!file.exists() || finish.isDirectory()) {
PrintWriter transcriber = novel SculptureWriter(“Workextinguished Log.txt”, “UTF-8”);
writer.close();
}

// Transcribe to finish extraneously aggravatewriting popular contents
final SculptureWriter extinguishedput = novel SculptureWriter(novel FinishWriter(file, penny));
output.println(“n” + sdf.format(cal.getTime())); // Append limit to finish
// Originate Fabricate
JFabricate fabricate = novel Workout();
frame.setTitle(“My Workextinguished Trailer”);
/* Commented extinguished control CR
frame.setIconImage(novel ImageIcon(“Images/Muscle.png”).getImage()); */

// workout, fixed, and rep fields control facts
final JTextField[] workouts = {
novel JTextField(“Push ups”),
novel JTextField(“Dumbell Presses”),
novel JTextField(“Dumbell Curls”)
};
final JTextField[] fixeds = novel JTextField[3];
final JTextField[] reps = novel JTextField[3];

// append passagefield pointers + append passagefields to fabricate
control (int i = 0; i < 3; i++) {
sets[i] = novel JTextField();
reps[i] = novel JTextField();
}

// Originate checkboxes
final JCheckBox abs = novel JCheckBox(“Abs?”);
final JCheckBox squat = novel JCheckBox(“Squats?”);
// Originate Scheduleener
ActionListener checkListener = novel ActionListener() {
@Override
public empty actionPerformed(ActionIssue 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 scheduleener with checkboxes
// Append checkboxes to fabricate
JButton log = novel JButton(“Log”); // To log everything
// Register + originate Issue Scheduleener
@Override
public empty actionPerformed(ActionIssue e) {
control (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 {
}
catch (InterruptedException i) {
i.printStackTrace();
}
System.exit(0);
}
});