//main this is where the program starts off getting the user to enter 1 for instructor or 2 for student.
//the do while will keep them in the if, else if, if. Our teacher wants the data for instructor in MAIN.
//the data for student must be in the constructor for student.
//currently the program runs fine, but I hve no clue how to instantiate an object to get into the student //constructor. I hope you understand and can help. I have never asked for help before today.
//main follows
package unit05lab;
import javax.swing.*;
/**
*
* @author impaler
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int iWork;
Student Name = new Student();
boolean correctInput = false;
do
{ correctInput = false;
String getPerson = JOptionPane.showInputDialog(
" Please Select 1 for Instructor or 2 for Student: ");
if(getPerson.equals ("1"))
{
Instructor Teacher = new Instructor();
//Instructor Teacher = new Instructor(int setYears);
String getInstructorFirstName = JOptionPane.showInputDialog(" Please Enter the Teachers last Name: ");
String getInstructorLastName = JOptionPane.showInputDialog(" Please Enter the Teachers Last Name: ");
Teacher.setName( getInstructorFirstName, getInstructorLastName);
JOptionPane.showMessageDialog(null, " Thank You " + Teacher.getFirstName() + " " + Teacher.getLastName() +
" for making the world a beter place ");
String getYearInTeaching = JOptionPane.showInputDialog( "Please Enter the number of years" + " " + Teacher.getFirstName()+ " " +
Teacher.getLastName() + " has been teaching ");
//String getYearInTeaching = JOptionPane.showInputDialog( " PLease Enter the amount of years you have been teaching:");
iWork = Integer.parseInt(getYearInTeaching);
Teacher.setYears(iWork);
JOptionPane.showMessageDialog(null, "Thank you " + Teacher.getFirstName() + " " + Teacher.getLastName() +
" for donating " + Teacher.getYearInTeaching()+ " years to teaching ");
}
else if (getPerson.equals ("2"))
{
//Student Name = new Student();
// String getStudentFirstName = JOptionPane.showInputDialog(" Please Enter the Students First Name: ");
// String getStudentLastName = JOptionPane.showInputDialog(" Pleae Enter the Students last Name: ");
// Name.setName(getStudentFirstName, getStudentLastName);
// JOptionPane.showMessageDialog(null, " " + Name.getFirstName() + " " + Name.getLastName() + " is a Student! ");
// String getYearsInSchool = JOptionPane.showInputDialog( " Please enter the years you ahve been a student " + Name.getFirstName() +
// " " + Name.getLastName() + " " ) ;
// iSchool = Integer.parseInt(getYearsInSchool);
}
else
{
correctInput = true;
JOptionPane.showMessageDialog(null, " You did not inter a correct answer plaease try again ");
}
} while (correctInput);
}
}
//student class the public student is where he wants the data.
//what I can't figure out is where once the user enter 2 at the menu for student the program dies
//i need to know how to get it to jump into the constructor
//class Student follows
package unit05lab;
import javax.swing.*;
/**
*
* @author impaler
*/
public class Student extends Person {
private int iYearsInSchool;
private int iSchool;
public Student()
{
Student Name = new Student();
JOptionPane.showMessageDialog(null, " Please enter the Students name ");
String getStudentFirstName = JOptionPane.showInputDialog(" Please Enter the Students First Name: ");
String getStudentLastName = JOptionPane.showInputDialog(" Pleae Enter the Students last Name: ");
Name.setName(getStudentFirstName, getStudentLastName);
JOptionPane.showMessageDialog(null, " " + Name.getFirstName() + " " + Name.getLastName() + " is a Student! ");
String getYearsInSchool = JOptionPane.showInputDialog( " Please enter the years you ahve been a student " + Name.getFirstName() +
" " + Name.getLastName() + " " ) ;
iSchool = Integer.parseInt(getYearsInSchool);
Name.setStudentYears(iSchool);
JOptionPane.showMessageDialog(null, + Name.iYearsInSchool );
}
public void setStudentYears(int iYearsInSchoolToSet)
{
iYearsInSchool = iYearsInSchoolToSet;
}
public int getYearsInSchool()
{
return iYearsInSchool;
}
}
This post has been edited by macosxnerd101: 31 July 2010 - 05:42 PM
Reason for edit:: Added code tags.

New Topic/Question
Reply
MultiQuote











|