Please correct the comments on the java program below
jtxtRanking.setText("Invalid marks");
JOptionPane.showMessageDialog(null, "Marks should be between
0-100", "Error", JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
//The DefaultTableModel can be acessed through the getModel
method
DefaultTableModel model = (DefaultTableModel)
jTable.getModel();
//Add a row
model.addRow(new Object []{
// receive datas from the following and display it on the
table
jtxtStudentID.getText(),
jcmbCourseCode.getSelectedItem(),
jtxtAverage.getText(),
jtxtRanking.getText(),
});
try {
FileReader fr = new FileReader(file); // read data from the
file
BufferedReader br = new BufferedReader(fr); // instantiate
BufferedReader object
DefaultTableModel model =
(DefaultTableModel)jTable.getModel();
Object[] lines = br.lines().toArray(); // read the file and convert
to an array
for(int i = 0; i < lines.length; i++){
/* The data stored on the database will be splitted
between each column by 1 space */
String[] row = lines[i].toString().split(" ");
model.addRow(row); // add the row to the table from database
}
try {
FileWriter fw = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fw);
// read data from the table's rows and columns
for(int i = 0; i < jTable.getRowCount(); i++){ //rows
for(int j = 0; j < jTable.getColumnCount(); j++){
//columns
// write and store the data from the table to the database
bw.write(jTable.getValueAt(i, j).toString()+" ");
}
bw.newLine(); // create new line in the database
}
bw.close(); // closing BufferedReader object
fw.close(); // closing FileWriter object
// show "Data Exported" dialog message after completion of storing
data
JOptionPane.showMessageDialog(null, "Data Exported");
jtxtRanking.setText("Invalid marks");
JOptionPane.showMessageDialog(null, "Marks should be between
0-100", "Error", JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
//The DefaultTableModel can be acessed through the getModel
method
// creating 'model' fetching by method getModel()
DefaultTableModel model = (DefaultTableModel)
jTable.getModel();
//Add a row
// receives data like(ID, Code, Average, ranking) from records and display it on the table
model.addRow(new Object []{
jtxtStudentID.getText(),
jcmbCourseCode.getSelectedItem(),
jtxtAverage.getText(),
jtxtRanking.getText(),
});
try {
// create object to read data from the file
FileReader fr = new FileReader(file);
// instantiate BufferedReader object using file object
BufferedReader br = new BufferedReader(fr);
DefaultTableModel model = (DefaultTableModel)jTable.getModel();
// read the file and convert it to an array
Object[] lines = br.lines().toArray();
/* By following code, the data stored on the database will be
splited
between each column by 1 space */
for(int i = 0; i < lines.length; i++)
{
String[] row = lines[i].toString().split(" ");
// adding the row to the table from database
model.addRow(row);
}
try {
FileWriter fw = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fw);
// this loop will read data from the table's rows and columns
for(int i = 0; i < jTable.getRowCount(); i++)
{
//for rows
for(int j = 0; j < jTable.getColumnCount(); j++)
{
//for columns
// write and store the data from the table to the database
bw.write(jTable.getValueAt(i, j).toString()+" ");
}
// create new line in the database
bw.newLine();
}
// closing BufferedReader object
bw.close();
// closing FileWriter object
fw.close();
// show "Data Exported" dialog message after completion of storing
data
JOptionPane.showMessageDialog(null, "Data Exported");
Please correct the comments on the java program below jtxtRanking.setText("Invalid marks"); JOptionPane.showMessageDialog(null, "Marks should be between 0-100", "Error", JOptio...
Please give me an explanation from the JAVA code below which
functions is to export data from JTable to database in .txt file
(text form).
String filePath"/Users/maestro Desktop/table.txt"; File file new File (filePath) // create a file object try t I/ Try execute codes that may encounter errors/exceptions FileWriter fw = new FileWriter(file); BufferedWriter bwnew Bufferedwriter (fw) // this loop will read data from the table's rows and columns for(int i = 0; 1くjTable.getRowCount(); 1++){ //for rows for(int j-0;j <...
I'm working with Java and I have a error message 1 error Error: Could not find or load main class Flowers. This is the problem: Instructions Make sure the source code file named Flowers.java is open. Declare the variables you will need. Write the Java statements that will open the input file, flowers.dat, for reading. Write a while loop to read the input until EOF is reached. In the body of the loop, print the name of each flower and where...
package Lab11; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Lab10 { public static void main (String [] args) { // ============================================================ // Step 2. Declaring Variables You Need // These constants are used to define 2D array and loop conditions final int NUM_ROWS = 4; final int NUM_COLS = 3; String filename = "Input.txt"; // A String variable used to save the lines read from input...
Step 1: Getting Started Create a new .java file named Lab12.java. At the beginning of this file, include your assignment documentation code block. After the documentation block, you will need several import statements. import java.util.Scanner; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; Next, declare the Lab12 class and define the main function. public class Lab12 { public static void main (String [] args) { Step 2: Declaring Variables For this section of the lab, you will need to declare...
This is a java homework for my java class. Write a program to perform statistical analysis of scores for a class of students.The class may have up to 40 students.There are five quizzes during the term. Each student is identified by a four-digit student ID number. The program is to print the student scores and calculate and print the statistics for each quiz. The output is in the same order as the input; no sorting is needed. The input is...
Having trouble with my code, it keeps giving me an error every time I run it. Can someone please help me understand what I'm doing wrong? *********CODE*************** // Java program to read the file contents, sort it and output the sorted content to another file import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; public class Datasort { public static void main(String[] args) throws IOException { File fin = new File("input.txt");...
Java programming help My program wont run. could someone tell me why. everything seems correct to me... giving me the error: Exception in thread "main" java.lang.NumberFormatException: For input string: "Stud" at java.base/java.lang.NumberFormatException.forInputString(Unknown Source) at java.base/java.lang.Integer.parseInt(Unknown Source) at java.base/java.lang.Integer.parseInt(Unknown Source) at Util.readFile(Util.java:35) at Driver.main(Driver.java:8) _________________________________________________________________________________________________________________________ Program Prompt: Write a program to perform statistical analysis of scores for a class of students.The class may have up to 40 students.There are five quizzes during the term. Each student is identified by a four-digit...
I have this program that works but not for the correct input file. I need the program to detect the commas Input looks like: first_name,last_name,grade1,grade2,grade3,grade4,grade5 Dylan,Kelly,97,99,95,88,94 Tom,Brady,100,90,54,91,77 Adam,Sandler,90,87,78,66,55 Michael,Jordan,80,95,100,89,79 Elon,Musk,80,58,76,100,95 output needs to look like: Tom Brady -------------------------- Assignment 1: A Assignment 2: A Assignment 3: E Assignment 4: A Assignment 5: C Final Grade: 82.4 = B The current program: import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class main { public static void main(String[]...
Java : Please help me correct my code: create a single class (Program11.java) with a main method and some auxiliary methods to input a 2-D array from a disk file, input some “transactions” to change the 2-D array and output the changed 2-D array to another file. Your main method will be minimal (see below). Most of the work will go on in your methods. In main, declare (but do not instantiate) 2-D array. Then call the three methods. The...
Hello everyone. I have a bankers algorithm written in java that gets inputs from a .txt file. The file has 7 processes and 5 resources however, when the program runs, it doesn't sum the resource columns correctly. The program runs correctly for smaller matricies (4 processes, 3 resources), not sure what the issue is and have been looking over the code for awhile so maybe another set of eyes would help...thanks BankersAlgorithm.java /** * This program implements Bankers algorithm which...