473,396 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how do i output my array and list it in a single dialog box

1).i want to list may array in a single dialog-box? i am very new to JOptionPane and arrays.

the program accept student name and grades and output it.use an array.

it also traverses the array and allow the user to perform the following processes

a) search for a particular student and his or her marks
b)find the average of all the student in the class
c)find all student with a mark below 50 and output them.

Expand|Select|Wrap|Line Numbers
  1. import javax.swing.JOptionPane;
  2. import java.util.Arrays;
  3.  
  4. public class  pdemo {
  5.     private String[] names;
  6.     private int [] grade;
  7.    public int Nos;
  8.     private String num;
  9.     public String  go  ,b,c,x;
  10.  
  11.     public pdemo()
  12.     {
  13.         num =JOptionPane.showInputDialog( null,"Welcome Enter the Number of student taking This Couse");
  14.          Nos = Integer.parseInt(num);
  15.         names = new String[Nos];
  16.         grade=new int [Nos];
  17.     }
  18.     public void inputNames() 
  19.     {int z =1;
  20.         for (int i = 0; i < names.length; i++) {
  21.           names[i] =  JOptionPane.showInputDialog("Enter name: "+z);
  22.           ++z;
  23.         }
  24.     }
  25.     public void inputGrades()
  26.     {
  27.  
  28.   for(int i=0; i<grade.length ; i++)
  29.   {int z=1;
  30.       System.out.println("Enter the grade ");
  31. num =JOptionPane.showInputDialog(null,"Enter the grade "+ z);
  32.         grade[i] =Integer.parseInt(num);
  33.         ++z;
  34.  }
  35.         }
  36.     public void trav()
  37.     {
  38.         for (int da=0;da<names.length;da++)    {
  39.       JOptionPane.showMessageDialog(null, da+ ":"+ names[da]+" :"+grade[da]);
  40. Array.sort(names);
  41.         }
  42.     }
  43.  
  44.     public void search(String name)
  45.     {
  46.        int i=0;
  47.             {
  48.    name = JOptionPane.showInputDialog ("What is the name of the student u are looking for?");
  49.             }
  50. {
  51.   for( ; i<names.length ; i++){
  52.       if( names[i].equals(name) ){
  53.            JOptionPane.showMessageDialog(null,"found " + names[i] + " at index " + i + " with grade " + grade[i]);
  54.  
  55.       }
  56.   }
  57. }
  58.  
  59.     }
  60. public void average()
  61.         {
  62.     double ave=0;
  63.      /*if (b==b)*/{
  64.          for(int i=0; i<grade.length ; i++)
  65.  {
  66.  ave+=grade[i];
  67.              }
  68.         JOptionPane.showMessageDialog(null,"The average of the total student body is:"+ ave);
  69.  
  70.      }
  71. }
  72.      public void below(){
  73.          /*if (c==c)*/{
  74.   JOptionPane.showMessageDialog(null,"The following people have a grade lower than 50");
  75.  
  76.   for(int i=0 ; i<grade.length ; i++){
  77.       if( grade[i]<50 ){
  78.            JOptionPane.showMessageDialog(null,names[i] + ": " + grade[i]);
  79.       }
  80.   }
  81. }
  82. }
  83.  
  84. }
  85. import java.io.*;
  86. public class Main {
  87. public static int n;
  88. public static String name;
  89.     /**
  90.      * @param args the command line arguments
  91.      */ 
  92.     private static BufferedReader stdin =  new BufferedReader( new InputStreamReader( System.in ) );
  93.     public static void main(String[] args)
  94.             throws IOException
  95.     {
  96.         pdemo demo = new pdemo();
  97.         demo.inputNames();
  98.         demo.inputGrades();
  99.         demo.trav();
  100.        //demo.sele();
  101.       demo.search(name);
  102.       demo.below();
  103.       demo.average();
  104.  
  105.     }
  106. }
  107.  
  108.  
Dec 8 '10 #1
0 1496

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: jonny | last post by:
Hey I need to search an array list to remove duplicate Data The list is populated by a search function that enters in a name if the it is told too This causes duplicate names to be entered...
1
by: Phenix Smith | last post by:
I am looking at coverting an application over to C#. Currently I have a global list varible that needs to be converted. I have tested different ideas to accomplish the same idea. Ths best way I...
13
by: Hrvoje Voda | last post by:
How to put a specified dataset table into an array list ? Hrcko
0
by: gerry | last post by:
I want to populating an asp list box from a simple access lookup list (single column not a table.)I don't want to create tables just for lookups as the values will be descriptive only and will...
3
by: Shawn H. Mesiatowsky | last post by:
I have an array list that I want to display to the browser. I need very precise control of the repeater, so I have function for the OnItemDataBound event for the repater, then in that function I...
11
by: Zorpiedoman | last post by:
The problem is this: I have a list box. I set an array list as the datasource. I remove an item from the array list. I set the listbox datasource to nothing. I set the listbox datasource to...
3
by: Hrvoje Voda | last post by:
DataRow drow = db.dataSetLogo.Logo.Select("LogoName = '" + cPicList.SelectedItem.ToString() + "'"); if (drow.Length > 0) { try {
2
by: hannahs | last post by:
I'll try to explain this the best I can. I have a class called book which creates books that each hold information such as author, title, ISBN code, etc. Then I have another class called...
1
by: sqldba20 | last post by:
Folks: I need help with a script. I have 4 tables with AsOfDate, Country and FactorInt columns. In each table AsOfdate and Country are the same for that date but the FACTORINT column varies. I...
22
by: Energizer100 | last post by:
Hey. I'm having some difficulty in Array lists. I have to find the average of all the numbers in an array list. That's my first task. My second one is to find the mode of all the numbers, meaning the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.