Welcome to Dream.In.Code
Become a Java Expert!

Join 149,973 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,401 people online right now. Registration is fast and FREE... Join Now!




program to add instructor/student

 
Reply to this topicStart new topic

program to add instructor/student, struggling...

circuspeanuts
18 Oct, 2008 - 07:47 AM
Post #1

D.I.C Head
**

Joined: 11 Apr, 2008
Posts: 68

Here are the parameters:

1. Have a console menu system to:
Add an instructor
Add a student
Exit the program
2. capture all user information using the scanner class
3. Ask the user type of "person" they want to add (Instructor/Student)
4. Ask last name of instructor/student
5. Ask first name of instructor/student
6. If they are an instructor, ask them how many years they've been teaching; if they are a student, ask them how many years they've been attending school. Verify that what they input is a number using exception handling
7. Store all this information in the object/class
8. Create a person class with appropriate data members and member methods. Extend the person class into Instructor and Student, again with appropriate data members and member methods
9. Use these instructor and student classes to store the input data
10. For the instructor class gather the data in the main method and load the data using set/get methods
11. For the student class gather the data in the students constructor
12. For now echo the data back to the user using the console, but do not print any of the capture data from the class, use set/get methods to get the data from the class and print from the main method.



^ Those are the parameters for this project. I missed class last week and thus I'm a little confused. This is what I have for code so far.

Person Class
CODE

import javax.swing.*;
import java.util.*;

public static Person {

private

Scanner scanner = new Scanner(System.in);
String FirstName;
String LastName;
String Age;
int iAge;

void SetName() {

System.out.print("Please tell me your last name:");
String LastName = scanner.next();
System.out.print("Please tell me your first name:");
String Firstname = scanner.next();

System.out.print("Hello, " + FirstName + LastName);
}

}


Main
CODE

System.out.print("Please select from one of the following: \n\n");
System.out.print("\t 1. Add an Instructor \n\n \t 2. Add a Student \n\n \t 3. Exit");


then in my instructor class and student class all I have is
CODE

Public Instructor extends Person


and the same for student.

My question is, where do I go from here? In my main method, it doesn't allow me to create an integer to recognize user input for their selection ( it doesn't like scanner.nextInt(); ) and it doesn't like the import.java.util.*; either...

This post has been edited by circuspeanuts: 18 Oct, 2008 - 07:47 AM
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Program To Add Instructor/student
18 Oct, 2008 - 05:19 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,655



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Well, lets start from the most basic, your Person class has a few issues. I have corrected them and show you using in-code comments below...

java

import javax.swing.*;
import java.util.*;

// Classes use the "class" keyword here, not static
public class Person {
//Not sure why private is here, it is not like C++ where all member variables to follow are private.
// You must specify private on each variable or name you want private.
//private

private Scanner scanner = new Scanner(System.in);
private String FirstName;
private String LastName;
private String Age;
private int iAge;

public void SetName() {

System.out.print("Please tell me your last name:");
String LastName = scanner.next();
System.out.print("Please tell me your first name:");

// Capital "N" for name, not lowercase.
String FirstName = scanner.next();

// Might want to add a space between the first and last names just to make it easier to read.
System.out.print("Hello, " + FirstName + " " + LastName);
}

}


Make these changes to Person to correct these errors and then recompile. Then show us the main class (test program) you have going and we can take a look. It should not have an issue with your java.util.*; declaration or the nextInt().

smile.gif

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 06:44PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month