this is my skeleton for my assignment:
import java.io.*;
import java.util.*;
public class Assignment7
{
// declare instance variables
// this method displays the menu options to the user
// the choice should be read in as a
String and then converted to an int
// the int should then be returned by this method
public int menu() throws Exception
{
}
// this method should
//1) call the readInUsers() method
//2) provide the menu loop
//3) call the needed methods depending on user choice
public void start() throws Exception
{
readInUsers();
// add in your code here
System.out.println("Thanks for using the system, goodbye");
}
// the constructor of this class, should initialize the instance variables
public Assignment7()
{
}
// this method will ask the user for a filename, and will create a PhoneUser for all users in the file
// and will add this PhoneUser array
public void readInUsers() throws Exception
{
System.out.print("Enter the filename in which the users are stored: ");
// read the filename from the keyboard
String filename=kb.readLine().trim();
// initialize a BufferedReader to read from the file
BufferedReader file=new BufferedReader(new FileReader(filename));
String lineRead=new String();
//read a line from the file
lineRead=file.readLine();
//while text can be read from the file, keep reading
while (lineRead!=null)
{
//the first line is the name of the user
String name=lineRead;
// read another line from the file (department)
String department=file.readLine();
//read another line from the file (phone number)
String phoneString=file.readLine();
// convert the phone number String to an int
int phoneNum=Integer.parseInt(phoneString);
// create a temporary PhoneUser object
// with the values read from the file as
// parameters to the constructor
PhoneUser tempUser=new PhoneUser(name,department,phoneNum);
// add the reference to this user to the array of users
users[numberOfUsers]=tempUser;
// increment the counter that keeps track of how many
// users there currently are in the array
numberOfUsers++;
//read the next line from the file
lineRead=file.readLine();
}
file.close();
}
//below are some suggestions for methods you might want to use
// method receives a String, traverses the array and
// looks for an entry that contains the String in the name field (case insensitve)
// it prints out a message if no user was found
public void findUserByName(String name)
{
}
// method receives an index as a parameter, this index should be a
// valid index in the users array.
// the user is then asked which value should be changed.
// depending on which option is selected, the user will be
// prompted to enter a new name or department
public void changeUserInfo(int index) throws Exception
{
}
// method receives a String, traverses the array and
// looks for an entry that matches the dept String (case insensitve)
// it prints out a message if no user was found
public void findUserByDept(String dept)
{
}
// this method receives a phone number as parameter
// it should return the index in the array of the user that has this
// phone number, or -1 if the user could not be found
public int findUserIndex(int number)
{
}
// this method will print all the users to the screen with the index
// they have in the array
public void listAllUsers()
{
}
public static void main(String[] args) throws Exception
{
Assignment7 a=new Assignment7();
a.start();
}
}
and my user skeleton:
public class PhoneUser
{
// instance variables
//constructor
public PhoneUser(//add parameters here)
{
//use the values sent in as parameters
//to initialize the instance variables
}
//
you should add methods that allow external classes to
// - retrieve the class variables
// - assign a new value to the name and department instance variables
// - retrieve all instance variables in tab delimited format (toString() )
}
i realise this is pretty general, i'm gonna keep hacking away at it, but any help will be greatly appreciated with any part of the program.