
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.
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
add(novel JLabel(“Workout”));
add(novel JLabel(“Sets”));
add(novel JLabel(“Reps”));
}
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++) {
frame.add(workouts[i]);
sets[i] = novel JTextField();
frame.add(sets[i]);
reps[i] = novel JTextField();
frame.add(reps[i]);
}
// 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
abs.addActionListener(checkListener);
squat.addActionListener(checkListener);
// Append checkboxes to fabricate
frame.add(abs);
frame.add(squat);
JButton log = novel JButton(“Log”); // To log everything
// Register + originate Issue Scheduleener
log.addActionListener(novel ActionListener() {
@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 {
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);
}
}