• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

totally screwed newbie, need assignment help

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may want to know that the cowboys and cowgirls at JavaRanch are very conservative when it comes to doing someone's homework. If you have a specific question or problem, we are willing to help. But no one will feed your cattle if you just leave it in the middle of the field.
 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Uhhhhh.... Where is the question? Are you asking if your approach is right? Are you wondering if you should make lots and lots of helper classes? Maybe you are looking to create an innerclass or two?
I'd have to agree with the previous post.
Regards - Dr. A>
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's something to play with - about 50% done, I'll leave you to complete it.
 
Nick Allen
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow, Mike. Thanks alot. I wasn't even hoping for that much help. I got most of those methods sort of working, but your code is a lot cleaner and I didn't think of using that same BufferedReader variable, br, over and over like that, I'm not quite sure why though. That should get me a lot closer to this thing actually getting done though. Thanks man.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic