SlideShare a Scribd company logo
Write an application containing three parallel arrays that hold 10 elements each. The first array
hold four-digit student ID numbers, the second array holds first names, and the third array holds
the students’ grade point averages. Use dialog boxes to accept a student ID number and display
the student’s first name and grade point average. If a match is not found, display an error
message that includes the invalid ID number and allow the user to search for a new ID number.
Solution
package javaapplication;
public class BoxJFrame extends javax.swing.JFrame {
/**
* Creates new form BoxJFrame
*/
private int[] studentsID = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
private String[] studentsName ={"Alan", "Cris", "Joe", "Suzzy", "Stan", "Eminem",
"Josh", "Ann", "Katy", "Ralph"};
private double[] studentsGP = {2.8, 4.1, 3.5, 4.0, 3.8, 3.75, 3.0, 4.2, 3.9, 3.6};
public BoxJFrame() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
//
//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jTextPane1 = new javax.swing.JTextPane();
jLabel1 = new javax.swing.JLabel();
jScrollPane2 = new javax.swing.JScrollPane();
jTextPane2 = new javax.swing.JTextPane();
jButton1 = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jScrollPane3 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jScrollPane1.setViewportView(jTextPane1);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Input student ID");
jScrollPane2.setViewportView(jTextPane2);
jButton1.setText("Search");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
}
);
jLabel2.setText("Result");
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane3.setViewportView(jTextArea1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(25, 25, 25)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 135,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 179,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(42, 42, 42)
.addComponent(jButton1))
.addGroup(layout.createSequentialGroup()
.addGap(226, 226, 226)
.addComponent(jLabel2)))
.addContainerGap(43, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 291,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(101, 101, 101)) );
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 30,
Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(26, 26, 26)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 31,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(51, 51, 51)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(110, Short.MAX_VALUE)) );
pack();
}
// //GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
boolean flag = false;
try{
int num = Integer.parseInt(jTextPane2.getText());
for(int i=0; i<10; i++){
if(studentsID[i]==num){
flag = true;
jTextArea1.setText("ID: " + num + " " + "Name: " + studentsName[i] + " " + "GPA: " +
studentsGP[i]);
break;
}
}
if(!flag)
jTextArea1.setText("Wrong ID! Try again!");
}
catch(Exception e){
jTextArea1.setText("Error input!");
}
}
//GEN-LAST:event_jButton1ActionPerformed
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) {
java.util.logging.Logger.getLogger(BoxJFrame.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);
}
catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(BoxJFrame.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);
}
catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(BoxJFrame.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);
}
catch (javax.swing.UnsupportedLookAndFeelException ex)
{
java.util.logging.Logger.getLogger(BoxJFrame.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);
}
//
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
new BoxJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextPane jTextPane1;
private javax.swing.JTextPane jTextPane2;
// End of variables declaration
//GEN-END:variables
}

More Related Content

DOC
Fee managment system
DOCX
Net Beans Codes for Student Portal
PDF
java stream class/java stream class/java stream class .pdf
PDF
2. Section 2. Implementing functionality in the PersonEntry. (1.5 ma.pdf
PDF
Im getting List Full when I try to add 2nd student.Driver..pdf
PDF
Java Assignment Help
DOCX
culadora cientifica en java
PDF
Java programs
Fee managment system
Net Beans Codes for Student Portal
java stream class/java stream class/java stream class .pdf
2. Section 2. Implementing functionality in the PersonEntry. (1.5 ma.pdf
Im getting List Full when I try to add 2nd student.Driver..pdf
Java Assignment Help
culadora cientifica en java
Java programs

Similar to Write an application containing three parallel arrays that hold 10 e.pdf (20)

PDF
How do I make my JTable non editableimport java.awt.; import j.pdf
PDF
PLEASE HELP ME !!IT IS Due Tonight ;(!i have to submit it before.pdf
PDF
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
PPTX
Jagriti
PDF
1. Section1.- Populating the list of persons on the person listing f.pdf
PDF
1. Section1.- Populating the list of persons on the person listing.pdf
PDF
Create a Code that will add an Add, Edi, and Delete button to the GU.pdf
TXT
Revision c odesagain
DOCX
Library management system
PDF
Module 4
PDF
How do I add a ComboBox to this, underneath Enter Student ID tha.pdf
DOCX
Student management system
PDF
Create a student record management system using linked list and queu.pdf
PDF
pbl oops complete-1-merged (1).p chd chd cdf
PDF
Java File
DOC
Project 4 1/tutorialoutlet
DOCX
20-Arid-850 Ali Haider Cheema BSSE(5A) Evening MPL Assignement 08.docx
DOCX
New microsoft office word document
TXT
Maze
PDF
student application form Java Netbeans
How do I make my JTable non editableimport java.awt.; import j.pdf
PLEASE HELP ME !!IT IS Due Tonight ;(!i have to submit it before.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
Jagriti
1. Section1.- Populating the list of persons on the person listing f.pdf
1. Section1.- Populating the list of persons on the person listing.pdf
Create a Code that will add an Add, Edi, and Delete button to the GU.pdf
Revision c odesagain
Library management system
Module 4
How do I add a ComboBox to this, underneath Enter Student ID tha.pdf
Student management system
Create a student record management system using linked list and queu.pdf
pbl oops complete-1-merged (1).p chd chd cdf
Java File
Project 4 1/tutorialoutlet
20-Arid-850 Ali Haider Cheema BSSE(5A) Evening MPL Assignement 08.docx
New microsoft office word document
Maze
student application form Java Netbeans
Ad

More from izabellejaeden956 (20)

PDF
Explain the advantages and disadvantages of misuse-based and anomaly.pdf
PDF
E. coli takes up plasmid DNA by which of the following methodsple.pdf
PDF
Consider the two genes described in Question 7. What is the probabili.pdf
PDF
A wireless technology that may someday replace barcodes through the u.pdf
PDF
The director of special events for Sun City believed that he amount o.pdf
PDF
Which type of project risk is the most relevantStand-alone risk.pdf
PDF
Which of the following is an advantage businesses have over citizens.pdf
PDF
what is the pseudoautosomal regionA. the region on the Y chromose.pdf
PDF
What is a flat file database How can it be used for forecasting.pdf
PDF
What is, in your opinion, the minimum firewall placement for a SCADA.pdf
PDF
What factor(s) do not contribute to the development of mutations tha.pdf
PDF
Urinary Tract infections commonly caused by E. Coli is a common illn.pdf
PDF
Two samples of sizes 15 and 20 are randomly and independently select.pdf
PDF
True or False The Coefficient of Determination shows the direction .pdf
PDF
Mechanical Engineer    A technology that had being since the last .pdf
PDF
The following transactions occurred for London Engineering O (Click .pdf
PDF
Regulation of prokaryotic gene expression is simpler than that in eu.pdf
PDF
Q4. We used remote port forwarding in this scenario. How does local .pdf
PDF
PYTHON Lottery Number GeneratorQuestion Design a program that ge.pdf
PDF
policy instrumens.Hi,can I get helpI choose policy instruments a.pdf
Explain the advantages and disadvantages of misuse-based and anomaly.pdf
E. coli takes up plasmid DNA by which of the following methodsple.pdf
Consider the two genes described in Question 7. What is the probabili.pdf
A wireless technology that may someday replace barcodes through the u.pdf
The director of special events for Sun City believed that he amount o.pdf
Which type of project risk is the most relevantStand-alone risk.pdf
Which of the following is an advantage businesses have over citizens.pdf
what is the pseudoautosomal regionA. the region on the Y chromose.pdf
What is a flat file database How can it be used for forecasting.pdf
What is, in your opinion, the minimum firewall placement for a SCADA.pdf
What factor(s) do not contribute to the development of mutations tha.pdf
Urinary Tract infections commonly caused by E. Coli is a common illn.pdf
Two samples of sizes 15 and 20 are randomly and independently select.pdf
True or False The Coefficient of Determination shows the direction .pdf
Mechanical Engineer    A technology that had being since the last .pdf
The following transactions occurred for London Engineering O (Click .pdf
Regulation of prokaryotic gene expression is simpler than that in eu.pdf
Q4. We used remote port forwarding in this scenario. How does local .pdf
PYTHON Lottery Number GeneratorQuestion Design a program that ge.pdf
policy instrumens.Hi,can I get helpI choose policy instruments a.pdf
Ad

Recently uploaded (20)

PPTX
Lesson notes of climatology university.
PDF
Classroom Observation Tools for Teachers
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
01-Introduction-to-Information-Management.pdf
PDF
Computing-Curriculum for Schools in Ghana
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Trump Administration's workforce development strategy
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
master seminar digital applications in india
PPTX
Pharma ospi slides which help in ospi learning
PDF
RMMM.pdf make it easy to upload and study
PDF
Yogi Goddess Pres Conference Studio Updates
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Lesson notes of climatology university.
Classroom Observation Tools for Teachers
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Orientation - ARALprogram of Deped to the Parents.pptx
O5-L3 Freight Transport Ops (International) V1.pdf
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
A systematic review of self-coping strategies used by university students to ...
01-Introduction-to-Information-Management.pdf
Computing-Curriculum for Schools in Ghana
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Trump Administration's workforce development strategy
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Microbial diseases, their pathogenesis and prophylaxis
2.FourierTransform-ShortQuestionswithAnswers.pdf
master seminar digital applications in india
Pharma ospi slides which help in ospi learning
RMMM.pdf make it easy to upload and study
Yogi Goddess Pres Conference Studio Updates
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc

Write an application containing three parallel arrays that hold 10 e.pdf

  • 1. Write an application containing three parallel arrays that hold 10 elements each. The first array hold four-digit student ID numbers, the second array holds first names, and the third array holds the students’ grade point averages. Use dialog boxes to accept a student ID number and display the student’s first name and grade point average. If a match is not found, display an error message that includes the invalid ID number and allow the user to search for a new ID number. Solution package javaapplication; public class BoxJFrame extends javax.swing.JFrame { /** * Creates new form BoxJFrame */ private int[] studentsID = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19}; private String[] studentsName ={"Alan", "Cris", "Joe", "Suzzy", "Stan", "Eminem", "Josh", "Ann", "Katy", "Ralph"}; private double[] studentsGP = {2.8, 4.1, 3.5, 4.0, 3.8, 3.75, 3.0, 4.2, 3.9, 3.6}; public BoxJFrame() { initComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() {
  • 2. jScrollPane1 = new javax.swing.JScrollPane(); jTextPane1 = new javax.swing.JTextPane(); jLabel1 = new javax.swing.JLabel(); jScrollPane2 = new javax.swing.JScrollPane(); jTextPane2 = new javax.swing.JTextPane(); jButton1 = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); jScrollPane3 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); jScrollPane1.setViewportView(jTextPane1); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setText("Input student ID"); jScrollPane2.setViewportView(jTextPane2); jButton1.setText("Search"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } } ); jLabel2.setText("Result"); jTextArea1.setColumns(20); jTextArea1.setRows(5); jScrollPane3.setViewportView(jTextArea1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(
  • 3. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(25, 25, 25) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(42, 42, 42) .addComponent(jButton1)) .addGroup(layout.createSequentialGroup() .addGap(226, 226, 226) .addComponent(jLabel2))) .addContainerGap(43, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 291, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(101, 101, 101)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(27, 27, 27) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE) .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(26, 26, 26) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)))
  • 4. .addGap(51, 51, 51) .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(110, Short.MAX_VALUE)) ); pack(); } // //GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: boolean flag = false; try{ int num = Integer.parseInt(jTextPane2.getText()); for(int i=0; i<10; i++){ if(studentsID[i]==num){ flag = true; jTextArea1.setText("ID: " + num + " " + "Name: " + studentsName[i] + " " + "GPA: " + studentsGP[i]); break; } } if(!flag) jTextArea1.setText("Wrong ID! Try again!"); } catch(Exception e){ jTextArea1.setText("Error input!"); } } //GEN-LAST:event_jButton1ActionPerformed
  • 5. 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) { java.util.logging.Logger.getLogger(BoxJFrame.class.getName()).log(java.util.logging.Level.SE VERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(BoxJFrame.class.getName()).log(java.util.logging.Level.SE VERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(BoxJFrame.class.getName()).log(java.util.logging.Level.SE VERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(BoxJFrame.class.getName()).log(java.util.logging.Level.SE VERE, null, ex); } // /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() {
  • 6. new BoxJFrame().setVisible(true); } }); } // Variables declaration - do not modify //GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JTextArea jTextArea1; private javax.swing.JTextPane jTextPane1; private javax.swing.JTextPane jTextPane2; // End of variables declaration //GEN-END:variables }