Jump to content

separate class help in java

- - - - -

  • Please log in to reply
2 replies to this topic

#1
jun71178

jun71178

    Newbie

  • Members
  • PipPip
  • 17 posts
Gud day to all...

can someone help me with this code of mine.. how can i separate these code to different class of student names and subject..

import javax.swing.*;
public class activity{
public static void main (String args[]){
int intchoice;

String strFirstName="";
String strSecondName="";
String strLastName="";
String strMiddleName="";
String strSubject="";

String strchoice=JOptionPane.showInputDialog("\nMenu:\n\n1: Student Record\n\n2: Subject\n\n");
intchoice=Integer.parseInt(strchoice);


if(intchoice==1){
strFirstName=JOptionPane.showInputDialog("Enter First Name:");

strSecondName=JOptionPane.showInputDialog("Enter Second Name:");

strLastName=JOptionPane.showInputDialog("Enter Last Name:");

strMiddleName=JOptionPane.showInputDialog("Enter Middle Name:");

JOptionPane.showMessageDialog(null,"\nStudent Record\n\nFirst Name: "+strFirstName+"\n\nSecond Name: "+strSecondName+"\n\nLast Name: "+strLastName+"\n\nMiddle Name: "+strMiddleName+"\n\nSuccessfully Recorded !\n\n");
JOptionPane.showMessageDialog(null,"Please proceed to Subject Menu to Enter Records of Student\n");

}

strchoice=JOptionPane.showInputDialog("\nMenu:\n\n1: Student Record\n\n2: Subject\n\n");
intchoice=Integer.parseInt(strchoice);

if(intchoice==2){
strSubject=JOptionPane.showInputDialog("\nEnter Subject\n");
String strChoice=JOptionPane.showInputDialog("\n1: First Prelim\n2: Midterm\n3: Prefinals\n4: Finals\n");
intchoice2=Integer.parseInt(strChoice);

}
}
}

thank you for your attention.........!!!!

#2
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP
Try creating a separate class named Student. Then give this student class the appropriate field variables. (firstname, lastname, etc);
After this, you can now create an object named Student and assign appropriate values to these variables.

View this for reference:
Declaring Classes (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

#3
jun71178

jun71178

    Newbie

  • Members
  • PipPip
  • 17 posts
thank you very much master lethalwire.... finally....i found some ways on how i will do it... here is what ive done already.....


import javax.swing.*;
public class Menu {
public static void main(String[] args) {
String sel=JOptionPane.showInputDialog(null," MENU\n"
+" 1.Student Record \n"
+" 2.Subject \n"
+"_Enter your Choice Here_:");
int ch=Integer.parseInt(sel);



if(ch==1){
StudentRecord name = new StudentRecord();
name.methclass();}
else {
ClassSubject grade = new ClassSubject();
grade.methclass();
}
}
}




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users