This is my current output for my program.
I am trying to get the output to look like
This is my program
Student.java
import java.awt.GridLayout;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JFileChooser;
public class Student extends javax.swing.JFrame {
BufferedWriter outWriter;
StudentA s[];
public Student() {
StudentGUI();
}
private void StudentGUI() {
jScrollPane3 = new
javax.swing.JScrollPane();
inputFileChooser = new
javax.swing.JButton();
outputFileChooser = new
javax.swing.JButton();
sortFirtsName = new
javax.swing.JButton();
sortLastName = new
javax.swing.JButton();
sortGPA = new
javax.swing.JButton();
textArea = new
javax.swing.JTextArea();
sortCredit = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new
java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent close) {
formWindowClosing(close);
}
});
inputFileChooser.setText("Input File");
inputFileChooser.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent input)
{
inputFileChooserActionPerformed(input);
}
});
outputFileChooser.setText("Output File");
outputFileChooser.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent output)
{
outputFileChooserActionPerformed(output);
}
});
sortFirtsName.setText("Sort by First Name");
sortFirtsName.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent Fname)
{
sortFirtsNameActionPerformed(Fname);
}
});
sortLastName.setText("Sort by last Name");
sortLastName.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent Lname)
{
sortLastNameActionPerformed(Lname);
}
});
sortGPA.setText("Sort
by GPA");
sortGPA.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent gpa) {
sortGPAActionPerformed(gpa);
}
});
sortCredit.setText("Sort
by Credit");
sortCredit.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent Credit)
{
sortGPAActionPerformed(Credit);
}
});
this.getContentPane().setLayout(new GridLayout(2, 2));
this.add(jScrollPane3);
this.add(textArea);
this.add(inputFileChooser);
this.add(outputFileChooser);
this.add(sortFirtsName);
this.add(sortLastName);
this.add(sortGPA);
this.add(sortCredit);
pack();
}// //GEN-END:StudentGUI
private void inputFileChooserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inputFileChooserActionPerformed
File
file=null;
JFileChooser
chooser = new JFileChooser();
chooser.setDialogTitle("Load which file?");
int
result = chooser.showOpenDialog(null);
if (result
== JFileChooser.APPROVE_OPTION) {
file =
chooser.getSelectedFile();
}
String fileName=null;
try{
fileName =
file.getCanonicalPath();
StudentA.inputFile(fileName);
s=
StudentA.makeRandom(12);
for (StudentA m:
s)
textArea.append(m+"\n");
}catch(IOException e)
{
System.out.println("Input ouput Exception ");
System.exit(1);
}
}//GEN-LAST:event_inputFileChooserActionPerformed
private void
sortFirtsNameActionPerformed(java.awt.event.ActionEvent evt)
{
textArea.append("-------------------------- SORTED First
-------------------------\n");
StudentA.sortBy =
StudentA.SORTBY.FIRST;
java.util.Arrays.sort (s);
for
(StudentA m: s)
textArea.append(m+"\n");
}
private void
sortLastNameActionPerformed(java.awt.event.ActionEvent evt)
{//GEN-FIRST:event_sortLastNameActionPerformed
textArea.append("------------------------ SORTED Last
--------------------------\n");
StudentA.sortBy =
StudentA.SORTBY.LAST;
java.util.Arrays.sort (s);
for
(StudentA m: s)
textArea.append(m+"\n");
}
private void
sortGPAActionPerformed(java.awt.event.ActionEvent evt) {
textArea.append("------------------------ SORTED GPA
--------------------------\n");
StudentA.sortBy =
StudentA.SORTBY.GPA;
java.util.Arrays.sort
(s);
for (StudentA m:
s)
textArea.append(m+"\n");
}
private void
sortCreditActionPerformed(java.awt.event.ActionEvent evt) {
textArea.append("------------------------ SORTED CREDIT
--------------------------\n");
StudentA.sortBy =
StudentA.SORTBY.CREDITS;
java.util.Arrays.sort
(s);
for (StudentA m:
s)
textArea.append(m+"\n");
}
private void
outputFileChooserActionPerformed(java.awt.event.ActionEvent evt)
{
File
file=null;
JFileChooser
chooser = new JFileChooser();
chooser.setDialogTitle("Load which file?");
int
result = chooser.showOpenDialog(null);
if (result
== JFileChooser.APPROVE_OPTION) {
file =
chooser.getSelectedFile();
}
String fileName=null;
try{
fileName =
file.getCanonicalPath();
outWriter=new
BufferedWriter(new FileWriter(fileName));
}catch(IOException e)
{
System.out.println("Input ouput Exception ");
System.exit(1);
}
}
private void
formWindowClosing(java.awt.event.WindowEvent evt) {
try {
outWriter.write(textArea.getText());
outWriter.close();
} catch (Exception e)
{
}
}
public static void main(String args[])
{
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch
(ClassNotFoundException ex) {
} catch (InstantiationException ex) {
} catch (IllegalAccessException ex) {
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
}
//
/* Create and display
the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Student().setVisible(true);
}
});
}
// Variables declaration - do not
modify//GEN-BEGIN:variables
private javax.swing.JButton
inputFileChooser;
private javax.swing.JScrollPane
jScrollPane3;
private javax.swing.JButton
outputFileChooser;
private javax.swing.JButton sortCredit;
private javax.swing.JButton sortFirtsName;
private javax.swing.JButton sortGPA;
private javax.swing.JButton sortLastName;
private javax.swing.JTextArea textArea;
// End of variables
declaration//GEN-END:variables
}
StudentA.java
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;
import java.util.ArrayList;
class StudentA implements Comparable {
static java.util.Random randomNum = new java.util.Random ();
static ArrayList firstNames = new ArrayList <>();
static ArrayList lastNames = new ArrayList <>();
static ArrayList Major= new ArrayList <>();
static SORTBY sortBy = SORTBY.LAST;
static int nextUID = 1;
String first, last,branch;
double gpa = 0,percentage=0;
boolean pass=false;
int credits = 0,semester=1;
int uid = 0;
public static void inputFile(String inputFile)
{
try {
Major.add("Computer");
Major.add("Electrical");
Major.add("Electronics");
Major.add("Mathematics");
Major.add("Mechanical");
Scanner input=new Scanner(new File(inputFile));
int numberofentries=input.nextInt();
for(int i=0;i {
firstNames.add (input.next());
lastNames.add ( input.next());
}
}
catch (java.io.FileNotFoundException e) {
System.out.println (e);
}
}
enum SORTBY {LAST,FIRST,CREDITS,GPA};
public StudentA (Scanner sc) {
uid = nextUID++;
first = sc.next();
last = sc.next();
branch=sc.next();
semester=sc.nextInt();
credits = sc.nextInt();
gpa = sc.nextDouble();
pass=true;
} // end Scanner constructor
public StudentA ()
{
uid = nextUID++;
}
public int compareTo (StudentA x) {
switch (sortBy) {
case LAST : return last.compareTo (x.last);
case FIRST : return first.compareTo (x.first);
case CREDITS: return credits - x.credits;
case GPA : return (gpa > x.gpa)? 1 : -1;
} // end switch
return 0;
} // end compareTo for Comparable interface
@Override
public String toString () {
String passStatus="";
if(pass==true)
passStatus="Pass";
else
passStatus="Fail";
return String.format ("%d %15s, %10s: %10s %10d %10d %10.2f
\t"+passStatus, uid, last, first,branch,semester,credits, gpa);
} // end method toString
public static StudentA [] makeRandom (int m) {
StudentA [] sa = new StudentA [m];
for (int i = 0; i < sa.length; i++) {
sa[i] = new StudentA ();
sa[i].first = firstNames.get (i); //no random number
sa[i].last = lastNames.get (i); // //no random number
sa[i].branch=Major.get(randomNum.nextInt(Major.size()));
sa[i].credits = randomNum.nextInt (120);
sa[i].gpa = randomNum.nextDouble () * 4.0;
sa[i].semester=randomNum.nextInt(8)+1;
if(sa[i].gpa>=1.5)
sa[i].pass=true;
} // end for each student to instantiate
return sa;
} // end method makeRanom
public static void writeOutput(StudentA [] s,String outFile)
{
try {
BufferedWriter output=new BufferedWriter(new
FileWriter(outFile));
for(int i=0;i {
output.write(s[i]+"\n");
}
output.close();
} catch (Exception e) {
}
}
} // end class StudentAFG
We need at least 10 more requests to produce the answer.
0 / 10 have requested this problem solution
The more requests, the faster the answer.
This is my current output for my program. I am trying to get the output to...
I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label; import java.awt.TextArea; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Fall_2017 { public TextArea courseInput; public Label textAreaLabel; public JButton addData; public Dialog confirmDialog; HashMap<Integer, ArrayList<String>> students; public Fall_2017(){ courseInput = new TextArea(20, 40); textAreaLabel = new Label("Student's data:"); addData = new JButton("Add...
In Java Swing, in my ButtonHandler class, I need to have 2 different showDialog messages show when my acceptbutton1 is pressed. One message is if the mouse HAS been dragged. One is if the mouse HAS NOT been dragged. /// I tried to make the Points class or the Mouse Dragged function return a boolean of true, so that I could construct an IF/THEN statement for the showDialog messages, but my boolean value was never accepted by ButtonHandler. *************************ButtonHandler class************************************...
With the Code below, how would i add a "Back" Button to the bottom of the history page so that it takes me back to the main function and continues to work? import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextField; public class RecipeFinder { public static void main(String[]...
I have currently a functional Java progam with a gui. Its a simple table of contacts with 3 buttons: add, remove, and edit. Right now the buttons are in the program but they do not work yet. I need the buttons to actually be able to add, remove, or edit things on the table. Thanks so much. Here is the working code so far: //PersonTableModel.java import java.util.List; import javax.swing.table.AbstractTableModel; public class PersonTableModel extends AbstractTableModel { private static final int...
Problem: Use the code I have provided to start writing a program that accepts a large file as input (given to you) and takes all of these numbers and enters them into an array. Once all of the numbers are in your array your job is to sort them. You must use either the insertion or selection sort to accomplish this. Input: Each line of input will be one item to be added to your array. Output: Your output will...
Help! Not sure how to create this java program to run efficiently. Current code and assignment attached. Assignment :Write a class Movies.java that reads in a movie list file (movies.txt). The file must contain the following fields: name, genre, and time. Provide the user with the options to sort on each field. Allow the user to continue to sort the list until they enter the exit option. ---------------------------------------------------------- import java.util.*; import java.io.*; public class Movies { String movieTitle; String movieGenre;...
Swing File Adder: Build a GUI that contains an input file, text box and Infile button. It also must contain and output file, text box and Outfile button. Must also have a process button must read the infile and write to the outfile if not already written that is already selected and clear button. It must pull up a JFile chooser that allows us to brows to the file and places the full path name same with the output file. Program...
Can you please help me to run this Java program? I have no idea why it is not running. import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.DecimalFormat; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.ListSelectionModel; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; @SuppressWarnings({"unchecked", "rawtypes"}) public class SmartPhonePackages extends JFrame { private static final long serialVersionID= 6548829860028144965L; private static final int windowWidth = 400; private static final int windowHeight = 200; private static final double SalesTax = 1.06; private static JPanel panel;...
Below I have my 3 files. I am trying to make a dog array that aggerates with the human array. I want the users to be able to name the dogs and display the dog array but it isn't working. //Main File import java.util.*; import java.util.Scanner; public class Main { public static void main(String[] args) { System.out.print("There are 5 humans.\n"); array(); } public static String[] array() { //Let the user...
I want to extend this GUI application in java language. Thanks for the help in advance. import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JButton; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class FormWindow { private JFrame frame; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { FormWindow window = new FormWindow(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application. */ public FormWindow() { initialize(); ...