SlideShare a Scribd company logo
1 of 6
Download to read offline
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

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

In Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdfIn Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdf
flashfashioncasualwe
 
New microsoft office word document
New microsoft office word documentNew microsoft office word document
New microsoft office word document
nidhileena
 
Java Program I keep receiving the following error in my code- Can you.pdf
Java Program I keep receiving the following error in my code- Can you.pdfJava Program I keep receiving the following error in my code- Can you.pdf
Java Program I keep receiving the following error in my code- Can you.pdf
RyanF2PLeev
 
Ejemplos Interfaces Usuario 3
Ejemplos Interfaces Usuario 3Ejemplos Interfaces Usuario 3
Ejemplos Interfaces Usuario 3
martha leon
 
ObjectiveCreate a graphical database for a library IN JAVA. It sh.pdf
ObjectiveCreate a graphical database for a library IN JAVA. It sh.pdfObjectiveCreate a graphical database for a library IN JAVA. It sh.pdf
ObjectiveCreate a graphical database for a library IN JAVA. It sh.pdf
ezzi97
 
Functions and Objects in JavaScript
Functions and Objects in JavaScript Functions and Objects in JavaScript
Functions and Objects in JavaScript
Dhananjay Kumar
 
Assignment #4 will be the construction of 2 new classes and a driver program/...
Assignment #4 will be the construction of 2 new classes and a driver program/...Assignment #4 will be the construction of 2 new classes and a driver program/...
Assignment #4 will be the construction of 2 new classes and a driver program/...
hwbloom3
 
Manual tecnico
Manual tecnicoManual tecnico
Manual tecnico
481200601
 

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

In Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdfIn Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdf
 
write a java program to accept the names of three items and their pric.docx
write a java program to accept the names of three items and their pric.docxwrite a java program to accept the names of three items and their pric.docx
write a java program to accept the names of three items and their pric.docx
 
Write a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdfWrite a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdf
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
 
Programa simulacion de ventas de aeropuerto
Programa simulacion de ventas de aeropuertoPrograma simulacion de ventas de aeropuerto
Programa simulacion de ventas de aeropuerto
 
New microsoft office word document
New microsoft office word documentNew microsoft office word document
New microsoft office word document
 
CMSC 350 HOMEWORK 1
CMSC 350 HOMEWORK 1CMSC 350 HOMEWORK 1
CMSC 350 HOMEWORK 1
 
Student management system
Student management systemStudent management system
Student management system
 
java
javajava
java
 
WD programs descriptions.docx
WD programs descriptions.docxWD programs descriptions.docx
WD programs descriptions.docx
 
Java Program I keep receiving the following error in my code- Can you.pdf
Java Program I keep receiving the following error in my code- Can you.pdfJava Program I keep receiving the following error in my code- Can you.pdf
Java Program I keep receiving the following error in my code- Can you.pdf
 
Ejemplos Interfaces Usuario 3
Ejemplos Interfaces Usuario 3Ejemplos Interfaces Usuario 3
Ejemplos Interfaces Usuario 3
 
(ArrayIndexOutOfBoundsException) Modifythe program from the code bel.docx
(ArrayIndexOutOfBoundsException) Modifythe program from the code bel.docx(ArrayIndexOutOfBoundsException) Modifythe program from the code bel.docx
(ArrayIndexOutOfBoundsException) Modifythe program from the code bel.docx
 
ObjectiveCreate a graphical database for a library IN JAVA. It sh.pdf
ObjectiveCreate a graphical database for a library IN JAVA. It sh.pdfObjectiveCreate a graphical database for a library IN JAVA. It sh.pdf
ObjectiveCreate a graphical database for a library IN JAVA. It sh.pdf
 
JNI 使用淺談
JNI 使用淺談JNI 使用淺談
JNI 使用淺談
 
Functions and Objects in JavaScript
Functions and Objects in JavaScript Functions and Objects in JavaScript
Functions and Objects in JavaScript
 
College management system.pptx
College management system.pptxCollege management system.pptx
College management system.pptx
 
Assignment #4 will be the construction of 2 new classes and a driver program/...
Assignment #4 will be the construction of 2 new classes and a driver program/...Assignment #4 will be the construction of 2 new classes and a driver program/...
Assignment #4 will be the construction of 2 new classes and a driver program/...
 
jrubykaigi2010-lt-rubeus
jrubykaigi2010-lt-rubeusjrubykaigi2010-lt-rubeus
jrubykaigi2010-lt-rubeus
 
Manual tecnico
Manual tecnicoManual tecnico
Manual tecnico
 

More from izabellejaeden956

Mechanical Engineer    A technology that had being since the last .pdf
Mechanical Engineer    A technology that had being since the last .pdfMechanical Engineer    A technology that had being since the last .pdf
Mechanical Engineer    A technology that had being since the last .pdf
izabellejaeden956
 
The following transactions occurred for London Engineering O (Click .pdf
The following transactions occurred for London Engineering O (Click .pdfThe following transactions occurred for London Engineering O (Click .pdf
The following transactions occurred for London Engineering O (Click .pdf
izabellejaeden956
 
Regulation of prokaryotic gene expression is simpler than that in eu.pdf
Regulation of prokaryotic gene expression is simpler than that in eu.pdfRegulation of prokaryotic gene expression is simpler than that in eu.pdf
Regulation of prokaryotic gene expression is simpler than that in eu.pdf
izabellejaeden956
 
policy instrumens.Hi,can I get helpI choose policy instruments a.pdf
policy instrumens.Hi,can I get helpI choose policy instruments a.pdfpolicy instrumens.Hi,can I get helpI choose policy instruments a.pdf
policy instrumens.Hi,can I get helpI choose policy instruments a.pdf
izabellejaeden956
 

More from izabellejaeden956 (20)

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

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Recently uploaded (20)

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 

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 }