Question

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 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");
  

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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");
  

Add a comment
Know the answer?
Add Answer to:
Please correct the comments on the java program below jtxtRanking.setText("Invalid marks"); JOptionPane.showMessageDialog(null, "Marks should be between 0-100", "Error", JOptio...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 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"; F...

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

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

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

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

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

  • Java programming help My program wont run. could someone tell me why. everything seems correct to...

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

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

  • Hello everyone. I have a bankers algorithm written in java that gets inputs from a .txt...

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

  • I need help with this code This is what I need to do: Implement the Stack...

    I need help with this code This is what I need to do: Implement the Stack Class with an ArrayList instead of an array, including the following functions: • empty • push • peek • pop • overrided toString( ) function which returns all of the stack’s contents Things to note: • You no longer need a size. • You no longer need to define a constant DEFAULT_CAPACITY. Since ArrayLists grow dynamically. • Whenever possible, use ArrayList functions instead of...

  • In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program...

    In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program to create a database of dogs of your own. You will also include File I/O with this program. You will create 3 classes for this assignment. The first class: Create a Class representing the information that is associated with one item (one dog) of your database. Name this class Dog. Using Lab 3, this will include the information in regard to one dog. The...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT