Computing.Net > Forums > Programming > Help in JAVA program

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Help in JAVA program

Reply to Message Icon

Name: Paulo
Date: October 19, 2001 at 19:06:20 Pacific
Comment:

I am a newbie in Java, I need help in using Vector class in this assignment

import javax.swing.*;

public class Main
{


public static void main (String[] args)
{
Info studentinfo[]= new Info[5];
int counter=0;
int option;

String more="";
String add="";
String ss="";
String name="";
String g1,g2,g3,g4,g5,input;

int gr[]=new int[5];

for (int y=0;y<5;y++)
{
studentinfo[y]=new Info();
}


do // starting menu //
{


input=JOptionPane.showInputDialog(null, "1.Enter student info" + "\n"
+ "2.Enter Course grades" + "\n"
+ "3. View Total and Average" + "\n"
+ "4. View GPA" + "\n"
+ "5. Summary" + "\n"
+ "6. Exit" + "\n", "Choose option", JOptionPane.PLAIN_MESSAGE);


option=Integer.parseInt(input);


switch(option) // menu options //
{
case 1:

if (counter<=5)
{

do{
int index;
boolean find=false;
ss=JOptionPane.showInputDialog("Enter Social Security"); // checking for Social security //
for (int i=0;i {
if ((studentinfo[i].SS).equals(ss))
{
find=true;
index =i;
break;
}
}
if (!find) // If SS found, then continue else prompt user
{
name=JOptionPane.showInputDialog("Enter your name");
add= JOptionPane.showInputDialog("Enter your address");

studentinfo[counter].setName(name); // getting student information //

studentinfo[counter].setAddress(add);
studentinfo[counter].setSS(ss);
counter++;
}
else
JOptionPane.showMessageDialog(null, "Social security exists,Try again","Error", JOptionPane.PLAIN_MESSAGE);

more=JOptionPane.showInputDialog("Do you want more(y/n)");
}
while(((more.equals("Y"))||(more.equals("y"))) &&(counter<5)); // continue 5 more times for 5 students
}
break;


case 2:
int index=0;
boolean find=false;
if (counter<1)
{
JOptionPane.showMessageDialog(null, "Database Empty", "Choose again", JOptionPane.ERROR_MESSAGE); // check to see if information exits //
}
else
{
ss=JOptionPane.showInputDialog("Enter Social Security"); // checking for SS, if exists, continue, else prompted //
for (int i=0;i {
if ((studentinfo[i].SS).equals(ss))
{
find=true;
index =i;
break;
}
}
if (find)
{
g1= JOptionPane.showInputDialog("Enter marks for Course 1");
g2= JOptionPane.showInputDialog("Enter marks for Course 2");
g3= JOptionPane.showInputDialog("Enter marks for Course 3");
g4= JOptionPane.showInputDialog("Enter marks for Course 4");
g5= JOptionPane.showInputDialog("Enter marks for Course 5");
gr[0]= Integer.parseInt(g1); // getting the course marks//
gr[1]= Integer.parseInt(g2);
gr[2]= Integer.parseInt(g3);
gr[3]= Integer.parseInt(g4);
gr[4]= Integer.parseInt(g5);

studentinfo[index].setGrades(gr);
}
else
JOptionPane.showMessageDialog(null, "Social security doesnt exist, Try again ","Error", JOptionPane.PLAIN_MESSAGE);
}

break;
case 3:

index=0;
find=false;
if (counter<1)
{
JOptionPane.showMessageDialog(null, "Database Empty", "Choose again", JOptionPane.ERROR_MESSAGE); // checking if information exists//
}
else
{
ss=JOptionPane.showInputDialog("Enter Social Security");
for (int i=0;i {
if ((studentinfo[i].SS).equals(ss))
{
find=true;
index =i;
break;
}
}
if (find)
{

JOptionPane.showMessageDialog(null, "Name=" +studentinfo[index].name+"\n" + "Total" +" "+ studentinfo[index].tot+"/"+"500"+"\n" +" "+ "Average=" +studentinfo[index].ave+"\n", "Arif's little helper", JOptionPane.PLAIN_MESSAGE); // displaying info //
}
else
JOptionPane.showMessageDialog(null, "Social security doesnt exist, Try again", "Error",JOptionPane.PLAIN_MESSAGE); // displaying info //
}
break;


case 4:

index=0;
find=false;
if (counter<1)
{
JOptionPane.showMessageDialog(null, "Database Empty", "Choose again", JOptionPane.ERROR_MESSAGE);
}
else
{
ss=JOptionPane.showInputDialog("Enter Social Security"); // checking for SS, if exists, continue, else prompted //
for (int i=0;i {
if ((studentinfo[i].SS).equals(ss))
{
find=true;
index =i;
break;
}
}
if (find)
{
JOptionPane.showMessageDialog(null, "Name=" +studentinfo[index].name+"\n" + "GPA=" + studentinfo[index].GPA + "\n" // displaiyng gpa//
, "Arif's little helper", JOptionPane.PLAIN_MESSAGE);
}
else
JOptionPane.showMessageDialog(null, "Social security doesnt exist, try again","Error", JOptionPane.PLAIN_MESSAGE);
}
break;


case 5:
if (counter<1)
{
JOptionPane.showMessageDialog(null, "Database Empty", "Choose again", JOptionPane.ERROR_MESSAGE);
}
else
{
for (int x=0;x {

JOptionPane.showMessageDialog(null, "Name=" + studentinfo[x].name // showing summary //
+ "\n" + "Social Security=" + studentinfo[x].SS
+ "\n" + "Address=" + studentinfo[x].address
+ "\n" + "\n" + "\n"
+ "SUMMARY"
+ "\n"
+ "Total=" + studentinfo[x].tot + "/500"
+ "\n" + "Average=" + studentinfo[x].ave
+ "\n" + "GPA=" + studentinfo[x].GPA
+ "\n" + "Your grade is" + " " + studentinfo[x].Grade , "Arif's little helper", JOptionPane.PLAIN_MESSAGE);
}
}
break;
case 6: //exiting program//
JOptionPane.showMessageDialog(null, "Thanks for using this program", "Bye", JOptionPane.PLAIN_MESSAGE);
System.exit(0);
break;
default:
JOptionPane.showMessageDialog(null, "Selection error", "Choose again", JOptionPane.ERROR_MESSAGE);

break;

}
}
while (option!=6); // end menu//



}
}


I also have a class of Info.

Now instead of the arrays i need to use vectors so i can have unlimited students, can anyone help. Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: luko
Date: October 19, 2001 at 20:04:10 Pacific
Reply:

Umm...if you're using JDK 1.3, I think you'll need to use ArrayLists, not Vectors. Aren't vectors fossils now?


0

Response Number 2
Name: freemann123
Date: November 13, 2001 at 16:34:23 Pacific
Reply:

The main difference between vector and arrays besides the dynamic size is that vector can store any data types. What this means for you is that you have to type cast the data when you retrieve from the vector.

For more info I advise you to read the java docs for methods.



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Help in JAVA program

need help w/ java programming www.computing.net/answers/programming/need-help-w-java-programming/9632.html

Need help in java www.computing.net/answers/programming/need-help-in-java/8082.html

Please help with java program. www.computing.net/answers/programming/please-help-with-java-program/14834.html