
Below is a simplified example using Java Swing for the GUI and a simple data structure for storing runner information. Note that this is a basic mockup that I made but I still need to improve on.
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; public class RunnerGUI extends JFrame {
private List<Runner> runners = new ArrayList<>();
private JTextField nameField, distanceField, timeField;
private DefaultListModel<String> listModel;
public RunnerGUI() {
// Set up JFrame setTitle("Runner Information");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create components nameField = new JTextField(20);
distanceField = new JTextField(10);
timeField = new JTextField(10); listModel = new DefaultListModel<>();
JList<String> listView = new JList<>(listModel);
JButton addButton = new JButton("Add Runner");
JButton sortButton = new JButton("Sort List");
JButton saveButton = new JButton("Save to CSV");
// Add components to the frame setLayout(new BorderLayout());
JPanel inputPanel = new JPanel(); inputPanel.add(new JLabel("Name:"));
inputPanel.add(nameField);
inputPanel.add(new JLabel("Distance:"));
inputPanel.add(distanceField);
inputPanel.add(new JLabel("Time:"));
inputPanel.add(timeField);
inputPanel.add(addButton); inputPanel.add(sortButton);
inputPanel.add(saveButton);
add(inputPanel, BorderLayout.NORTH);
add(new JScrollPane(listView), BorderLayout.CENTER);
// Add ActionListener for buttons
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { addRunner();
}
});
sortButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { sortList();
}
});
saveButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
saveToCSV();
}
});
}
private void addRunner()
{
String name = nameField.getText();
double distance = Double.parseDouble(distanceField.getText());
double time = Double.parseDouble(timeField.getText());
double pace = time / distance;
Runner runner = new Runner(name, distance, time, pace);
runners.add(runner);
updateListView();
clearFields(); }
private void sortList()
{
// Implement sorting based on radio button selection
// For simplicity, let's sort by name in ascending order Collections.sort(runners, Comparator.comparing(Runner::getName));
updateListView();
}
private void saveToCSV() { try (BufferedWriter writer = new BufferedWriter(new FileWriter("finalProjectRunners.txt")))
{
for (Runner runner : runners) { String line = String.format("%s,%.2f,%.2f,%.2f", runner.getName(), runner.getDistance(), runner.getTime(), runner.getPace());
writer.write(line);
writer.newLine(); } JOptionPane.showMessageDialog(this, "Data saved to CSV file."); } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, "Error saving to CSV file."); } } private void updateListView() { listModel.clear();
for (Runner runner : runners) { String displayText = String.format("Name: %s, Distance: %.2f, Time: %.2f, Pace: %.2f", runner.getName(), runner.getDistance(), runner.getTime(), runner.getPace()); listModel.addElement(displayText); } } private void clearFields() { nameField.setText(""); distanceField.setText(""); timeField.setText("");
}
public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new RunnerGUI().setVisible(true);
}
});
}
}
class Runner
{
private String name;
private double distance;
private double time;
private double pace; public Runner(String name, double distance, double time, double pace) { this.name = name; this.distance = distance;
this.time = time; this.pace = pace;
}
public String getName()
{
return name;
}
public double getDistance() {
return distance;
}
public double getTime() {
return time;
}
public double getPace() {
return pace;
}
}
With this code, can you please improve on it and see what can be fixed. Thank you!



Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 2 images

- Please discuss the differences between bagging and boosting and give an applicationalexample for each (please choose a specific method, such as AdaBoost or XGBoost, whendiscussing the boosting examples)arrow_forwardCreate a UML class diagram of the application illustrating class hierarchy, collaboration, and the content of each class. There is only one class. There is a main method that calls four methods. I am not sure if I made the UML Class diagram correct. import java.util.Random; // import Random packageimport java.util.Scanner; // import Scanner Package public class SortArray{ // class name public static void main(String[] args) { //main method Scanner scanner = new Scanner(System.in); // creates object of the Scanner classint[] array = initializeArray(scanner); System.out.print("Array of randomly generated values: ");displayArray(array); // Prints unsorted array sortDescending(array); // sort the array in descending orderSystem.out.print("Values in desending order: ");displayArray(array); // prints the sorted array, should be in descending ordersortAscending(array); // sort the array in ascending orderSystem.out.print("Values in asending order: ");displayArray(array); // prints the…arrow_forwardfinal big report project for java. 1.Problem Description Student information management system is used to input, display student information records. The GUI interface for inputing ia designed as follows : The top part are the student imformation used to input student information,and the bottom part are four buttonns, each button meaning : (2) Total : add java score and C++ score ,and display the result; (3) Save: save student record into file named student.dat; (4) Clear : set all fields on GUI to empty string; (5) Close : close the winarrow_forward
- Write in Java! Write the Widget class. a. A widget has a name and price. b. The default for name should be “widget” c. Write a constructor (not the no-args), all getters and setters. d. Add a toString method. e. Create an object of type Widget.arrow_forwardWe already have the address and vehicle class for the system below. We will need a CarShow class with IsSanctioned() method, Owner class with IsOwner method and a main class that creates objects and implements all our existing classes. Use the class diagrams. Make sure to include respective attributes, setters, getters and constructors in your code Explain your code in a few words.arrow_forwardImplement the following in the .NET Console App. Write the Bus class. A Bus has a length, a color, and a number of wheels. a. Implement data fields using auto-implemented Properies b. Include 3 constructors: default, the one that receives the Bus length, color and a number of wheels as input (utilize the Properties) and the Constructor that takes the Bus number (an integer) as input.arrow_forward
- I know it is a lot but can someone explain (with comments) line by line what is happening in the below Java program. It assists in my learning/gives me a deeper understanding. Please and thank you! Source code: import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.SwingUtilities; class ProductCalculator { public static int calculateProduct(int[] numbers, int index) { if (index == numbers.length - 1) { return numbers[index]; } else { return numbers[index] * calculateProduct(numbers, index + 1); } }} class RecursiveProductCalculatorView extends JFrame { private JTextField[] numberFields; private JButton calculateButton; private JLabel resultLabel; public RecursiveProductCalculatorView() { setTitle("Recursive Product Calculator"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new GridLayout(7, 1)); numberFields =…arrow_forwardPlease help me fix the errors in the java program below. There are two class AnimatedBall and BouncingBall import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;public class AnimatedBall extends JFrame implements ActionListener{private Button btnBounce; // declare a button to playprivate TextField txtSpeed; // declare a text field to enterprivate Label lblDelay;private Panel controls; // generic panel for controlsprivate BouncingBall display; // drawing panel for ballContainer frame;public AnimatedBall (){// Set up the controls on the appletframe = getContentPane();btnBounce = new Button ("Bounce Ball");//create the objectstxtSpeed = new TextField("10000", 10);lblDelay = new Label("Enter Delay");display = new BouncingBall();//create the panel objectscontrols = new Panel();setLayout(new BorderLayout()); // set the frame layoutcontrols.add (btnBounce); // add controls to panelcontrols.add (lblDelay);controls.add…arrow_forwardImplement a simple e-mail messaging system. I have already designed a Message class and a Mailbox/MailboxTest class. A message has a recipient, a sender, and a message text. A Mailbox can store and manipulate messages and tell the user how many they have. Supply a number of mailboxes for different users and a user interface(GUI) for the user to login, send messages to other users, read their own messages, and log out. Please explain each thing you do. Here is my Message class: publicclass Message { private String recipient; private String sender; private String messageBody; public Message(Stringsender, String recipient) { this.sender =sender; this.recipient =recipient; this.messageBody =""; } public void append(String text) { this.messageBody +=text +"\n"; } public String toString() { return "From: " + this.sender+ "\n" + "To: " + this.recipient + "\n" + "Message: " + this.messageBody; } } Here is Mailbox class: import java.util.ArrayList; publicclass Mailbox{ private…arrow_forward
- I need help creating a Java code package in a pyramid with 3 sides (pyramid3) and pyramid with 4 sides (pyramid4) classes as described in the image below package objectsPackage; import interfacePackage.ShapesInterface; public class Pyramid3 implements ShapesInterface { @Override publicdouble getArea() { // TODO Auto-generated method stub return 0; } @Override publicdouble getVolume() { // TODO Auto-generated method stub return 0; } @Override publicvoid displayArea() { // TODO Auto-generated method stub } @Override publicvoid displayVolume() { // TODO Auto-generated method stub } }arrow_forwardPlease help using javaarrow_forwardPlease help me with this using java. A starters code is provided (I created a starters code). For more info refer to the image provided. Please ensure tge code works Starter code:import javax.swing.*; import java.applet.*; import java.awt.event.*; import java.awt.*;public class halloween extends Applet implements ActionListener{ int hallow[] [] = ? int rows = 4; int cols = 3; JButton pics[] = new JButton [rows * cols]; public void init () { Panel grid = new Panel (new GridLayout (rows, cols)); int m = 0; for (int i = 0 ; i < rows ; i++) { for (int j = 0 ; j < cols ; j++) { pics [m] = new JButton (createImageIcon ("back.png")); pics [m].addActionListener (this); pics [m].setActionCommand (m + ""); pics [m].setPreferredSize (new Dimension (128, 128)); grid.add (pics [m]); } }m++; }}add (grid); }public void actionPerformed (ActionEvent…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





