Results 1 to 14 of 14
  1. #1
    Unknown1369 is offline Member
    Join Date
    Jul 2008
    Posts
    10
    Rep Power
    0

    Default having some trouble

    here are the instructions...

    1. Add 2 CPS courses
    a. Add 1 entry to the “cps_courses” array in constructor;
    b. Add 1 entry to the “cps_courses” array by calling (from “main”)the “add_cps_course” method.
    c. You will need to instantiate a courses object in order to call the “add_cps_course” method.

    2. Write an “add_cis_course” method similar to the “add_cps_course” method.

    3. Add 1 CIS courses
    a. Add 1 entry to the “cis_courses” array by calling (from “main”) the “add_cis_course” method.
    b. You will do not need to instantiate a courses object in order to call the “add_cis_course” method, if you already did so in step 1.c

    4. Printout the entire contents of one of the course arrays
    a. Print all the elements of either the “cis_courses” array or the “cps_courses” array.
    b. Add the print method to the “courses” class
    c. Print to the console using “System.out.print” and “System.out.println”
    d. Make sure print out is neatly formatted and appropriately spaced.

    5. Modify the “print_student” method to print the 4 courses
    a. Print the course ID
    b. Print the course Description

    6. Add yourself as a student to the by calling (from “main”) the “add_student” method
    a. Use your own name
    b. Use 99999 as your student ID
    c. Use fictitious information for the address
    d. Add four classes
    i. 2 of the 4 classes must be the ones added in steps 1 and steps 3 above.

    7. Call the “print_student” method to print out your student information.



    now, i have done numbers 1, 2, 3, and 6. hopefully i done them right. i just can't figure out how to do the rest of the instructions. another problem, when i tried to run the app., i get 3 errors but i don't understand because i don't see any red. i have attached the source files. could somebody help me. thanks.
    Attached Files Attached Files

  2. #2
    m_kaleia is offline Member
    Join Date
    Jul 2008
    Posts
    7
    Rep Power
    0

    Default

    Hello unkown , the source file isn't open with winrar can send it again .

  3. #3
    Unknown1369 is offline Member
    Join Date
    Jul 2008
    Posts
    10
    Rep Power
    0

    Default

    ok, try this

    i used winrar to compress.
    Attached Files Attached Files

  4. #4
    Niveditha's Avatar
    Niveditha is offline Senior Member
    Join Date
    May 2008
    Posts
    307
    Rep Power
    7

    Default

    Can you paste those errors here?
    To finish sooner, take your own time....
    Nivedithaaaa

  5. #5
    m_kaleia is offline Member
    Join Date
    Jul 2008
    Posts
    7
    Rep Power
    0

    Default

    sorry,but the win rar send this message when i extract the file
    "No archives found"

  6. #6
    m_kaleia is offline Member
    Join Date
    Jul 2008
    Posts
    7
    Rep Power
    0

    Default

    sorry but the thers is an error when i recieve the file find the error and try to send the file again .

  7. #7
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    9

    Default

    How big are these source files? I think it would be better for everyone to include them inside code tags.
    Did this post help you? Please me! :cool:

  8. #8
    Unknown1369 is offline Member
    Join Date
    Jul 2008
    Posts
    10
    Rep Power
    0

    Default

    hmmm...

    don't know why it won't work, it works on my side.

    trying agian, using winzip... there's 4 sources files.

    if not working agian, can someone tell me how i should upload it.
    Attached Files Attached Files

  9. #9
    Unknown1369 is offline Member
    Join Date
    Jul 2008
    Posts
    10
    Rep Power
    0

    Default

    letme try it inside code tags


    contactInfo.java
    Java Code:
    public class contactInfo {
    
    	public static final int MAX_ENTRIES = 100;
    	public static int curr_entries = 6;
    	private static String[] first_names  = new String[MAX_ENTRIES];
    	private static String[] last_names = new String[MAX_ENTRIES];
    	private static String[] street_address = new String[MAX_ENTRIES];	
    	private static String[] city = new String[MAX_ENTRIES];
    	private static String[] state = new String[MAX_ENTRIES];
    	
    	// This is the constructor for "contactInfo"
    	contactInfo()
    	{
    	  // Initialize first_names array
    	  first_names[0] = "Stan";
    	  first_names[1] = "Fredia";
    	  first_names[2] = "James";
    	  first_names[3] = "Sandra";
    	  first_names[4] = "Jerry";
    	  first_names[5] = "Robin";
    	  // Initialize last_names array
    	  last_names[0] = "Marko";
    	  last_names[1] = "Zells";
    	  last_names[2] = "Johnson";
    	  last_names[3] = "Christmas";
    	  last_names[4] = "Kelly";
    	  last_names[5] = "Byrde";
    	  // Initialize street_address array
    	  street_address[0] = "2 Easy Street";
    	  street_address[1] = "23 King Junction";
    	  street_address[2] = "10207 W. OuttaMy Way";
    	  street_address[3] = "18 Walker Blvd";
    	  street_address[4] = "00 Memory Lane";
    	  street_address[5] = "16 Lovers Lane";	  
    	  // Initialize city array
    	  city[0] = "Ann Arbor";
    	  city[1] = "Ypsilanti";
    	  city[2] = "Belleville";
    	  city[3] = "Dexter";
    	  city[4] = "Maumee";
    	  city[5] = "Toledo";	  
    	  // Initialize street_address array
    	  state[0] = "Michigan";
    	  state[1] = "Michigan";
    	  state[2] = "Michigan";
    	  state[3] = "Michigan";
    	  state[4] = "Ohio";
    	  state[5] = "Ohio";	  
    	}
    	
    	public void set_first_name(int index,String fname)
    	{
    		first_names[index] = fname;
    	}
    	
    	public void set_last_name(int index,String lname)
    	{
    		last_names[index] = lname;
    	}
    	
    	public void set_street_address(int index, String addr)
    	{
    		street_address[index] = addr;
    	}
    	
    	public void set_city(int index,String cty)
    	{
    		city[index] =cty;
    	}
    	
    	public void set_state(int index, String stt)
    	{
    		state[index] = stt;
    	}
    	public String get_first_name(int index)
    	{
    		return first_names[index];
    	}
    	
    	public String get_last_name(int index)
    	{
    		return last_names[index];
    	}
    	
    	public String get_street_address(int index)
    	{
    		return street_address[index];
    	}
    	
    	public String get_city(int index)
    	{
    		return city[index];
    	}
    	
    	public String get_state(int index)
    	{
    		return state[index];
    	}
    	
    	public int add_entry (String fname,String lname,String addr,String cty,String stt)
    	{
    		int ret_code;
    		
    		if (curr_entries<MAX_ENTRIES)
    		{
    			set_first_name(curr_entries, fname);
    			set_last_name(curr_entries, lname);
    			set_street_address(curr_entries,addr);
    			set_city(curr_entries,cty);
    			set_state(curr_entries,stt);
    			curr_entries++;
    			ret_code = 0;
    		}
    		else
    		{
    			ret_code = 1;
    		}
    	    return ret_code;
    	}
    }

    courses.java
    Java Code:
    public class courses 
    {
    	public static final int ARRAY_FULL = 1;
    	public static final int ENTRY_ADDED = 0;
    
    	public static final int MAX_COURSES = 25;
    	public static final int MAX_FEATURES = 2;
    
    	public static final int COURSE_ID = 1;
    	public static final int COURSE_DESC = 2;
    	public int curr_cps_entries = 5;
    	
    	public String [][] cps_courses= new String[MAX_COURSES][MAX_FEATURES];
    	
    	public int curr_cis_entries = 3;
    	public String [][] cis_courses= new String[MAX_COURSES][MAX_FEATURES];
    	
    	// Constructor for "courses" class 
    	courses()
    	{
    		cps_courses[0][1] = "CPS120";
    		cps_courses[0][2] = "Introduction to Computer Science";
    	    cps_courses[1][1] = "CPS161";
    	    cps_courses[1][2] = "Introduction to Programming Java";
    	    cps_courses[2][1] = "CPS171";
    	    cps_courses[2][2] = "Introduction to Programming C++";
    	    cps_courses[3][1] = "CPS185";
    	    cps_courses[3][2] = "Introduction to Visual Basic";
    	    cps_courses[4][1] = "CPS261";
    	    cps_courses[4][2] = "Programming Data Structures in Java";
    	    
    		cis_courses[0][1] = "CIS100";
    		cis_courses[0][2] = "Introduction to Computer Applications";
    	    cis_courses[1][1] = "CIS110";
    	    cis_courses[1][2] = "Introduction to Computer Information Systems";
    	    cis_courses[2][1] = "CIS117";
    	    cis_courses[2][2] = "Windows Operating System";
    	}
    
        public int add_cps_course (String crsid,String crsdesc)
        {
        	int retcode;
        	
        	if (curr_cps_entries < MAX_COURSES)
        	{
        		cps_courses[curr_cps_entries][COURSE_ID] = crsid;
        		cps_courses[curr_cps_entries][COURSE_DESC] = crsdesc;
        		curr_cps_entries++;
        		retcode = ENTRY_ADDED;
        	}
        	else
        	{
        		retcode = ARRAY_FULL;
        	}
        	return retcode;
        }
    
    public int add_cis_course (String crsid,String crsdesc)
    {
    	int retcode;
    	
    	if (curr_cis_entries < MAX_COURSES)
    	{
    		cis_courses[curr_cis_entries][COURSE_ID] = crsid;
    		cis_courses[curr_cis_entries][COURSE_DESC] = crsdesc;
    		curr_cis_entries++;
    		retcode = ENTRY_ADDED;
    	}
    	else
    	{
    		retcode = ARRAY_FULL;
    	}
    	return retcode;
    }
    
        }

    studentInfo.java
    Java Code:
    public class studentInfo extends contactInfo {
    
    		public static final int MAX_STUDENT_COURSES = 5;
    		private int[] student_number = new int[MAX_ENTRIES];
    		
    		private String[] course_one = new String[MAX_ENTRIES];
    		private String[] course_two = new String[MAX_ENTRIES];
    		private String[] course_three = new String[MAX_ENTRIES];
    		private String[] course_four = new String[MAX_ENTRIES];
    
    		studentInfo()
    		{
    			student_number[0] = 10010;
    			student_number[1] = 10022;
    			student_number[2] = 10032;
    			student_number[3] = 10156;
    			student_number[4] = 10271;
    			student_number[5] = 10072;
    			
    			for (int x=1;x<curr_entries;x++)
    			{
    				course_one[x] = "BOS207";
    				course_two[x] = "BOS183";
    				course_three[x] = "BOS206";
    				course_four[x] = "BOS157";
    			}
    		}
    		
    		public void set_student_number(int index, int stu_num)
    		{
    			student_number[index] = stu_num; 
    		}
    		
    		public int get_student_number(int index)
    		{
    			return student_number[index]; 
    		}
    
    		public void set_student_first_name(int index, String fname)
    		{
    			super.set_first_name(index, fname);
    		}
    
    		public void set_student_last_name(int index, String lname)
    		{
    			super.set_last_name(index, lname);
    		}
    		
    		public void set_student_city(int index, String cty)
    		{
    			super.set_city(index, cty);
    		}
    
    		public void set_student_state(int index, String stt)
    		{
    			super.set_state(index, stt);
    		}
    
    		public void set_student_address(int index, String addr)
    		{
    			super.set_street_address(index, addr);
    		}
    		
    		public int add_student (String fname, String lname, String addr, String cty, String stt,
    				               String crs1, String crs2, String crs3, String crs4)
    		{
    			int ret_code;
    			
    			if (curr_entries<MAX_ENTRIES)
    			{
    				set_first_name(curr_entries, fname);
    				set_last_name(curr_entries, lname);
    				set_street_address(curr_entries,addr);
    				set_city(curr_entries,cty);
    				set_state(curr_entries,stt);
    				course_one[curr_entries] = crs1;
    				course_two[curr_entries] = crs1;
    				course_three[curr_entries] = crs1;
    				course_four[curr_entries] = crs1;
    				curr_entries++;
    				ret_code = 0;
    			}
    			else
    			{
    				ret_code = 1;
    			}
    		    return ret_code;
    		}
    		
    		public int print_student(int stid)
    		{
    			int retcode = 1;
    			int index = -1 ;
    			
    			for (int count=0;count<curr_entries;count++)
    			{
    				if (student_number[count] == stid)
    				{
    					index = count;
    				}
    			}
    			
    			if (index != -1)
    			{
    			  System.out.print("RECORD FOR STUDENT #");
    			  System.out.println(student_number[index]);
    			  System.out.println("-------------------------");
    			  System.out.print(get_first_name(index)+" ");
    			  System.out.println(get_last_name(index));
    			  System.out.println(get_street_address(index)+" ");
    			  System.out.print(get_city(index)+", ");
    			  System.out.println(get_state(index)+" ");
    			  System.out.println();
    			  retcode = 0;
    			}
    			
    			return retcode;
    		}
    }

    finalProject.java
    Java Code:
    public class finalProject {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		
    		studentInfo Course = new studentInfo();
    		Course.add_student("John", "Doe","1 Washington Street", "Detroit", "Michigan", "CPS120", "CPS287", "CIS212", "CIS100");
    		Course.print_student(99999);
    		
    		courses Course1 = new courses();
    		Course1.add_cps_course("CPS287", "Advanced Visual Basic");
    		Course1.add_cis_course("CIS121", "Linux/UNIX I: Fundamentals");
    	
    	
    	}}
    Last edited by Unknown1369; 07-21-2008 at 07:37 PM.

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    i get 3 errors but i don't understand
    Can you post the errors also?

  11. #11
    Unknown1369 is offline Member
    Join Date
    Jul 2008
    Posts
    10
    Rep Power
    0

    Default

    here are the 3 errors:

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
    at courses.<init>(courses.java:23)
    at finalProject.main(finalProject.java:14)

  12. #12
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    Ok, look at your code in courses at line 23 and see if there is some indexing code there. If so, can the index be OufOfBounds? The value 2 seems to be out of bounds.
    Remember the index of the last element in an array is the size of the array minus 1.
    A two dim array has elements 0 and 1.

  13. #13
    Unknown1369 is offline Member
    Join Date
    Jul 2008
    Posts
    10
    Rep Power
    0

    Default

    ok, i changed the numbering so it states: [0][0],[0][1], and so forth...
    i also changed:

    public static final int COURSE_ID = 1;
    public static final int COURSE_DESC = 2

    to read: course_id = 0
    course_desc = 1

    when i ran it, nothing showed up on the console

    no errors tho.

    it's probably because i still need to do numbers 4, 5, and 7 in the instructions... but i don't know how to
    Last edited by Unknown1369; 07-21-2008 at 11:18 PM.

  14. #14
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    Add some System.out.println() statements to your code to see where it is going and what the value of variables are.

Similar Threads

  1. compiling trouble
    By capacitator in forum CLDC and MIDP
    Replies: 4
    Last Post: 06-10-2008, 10:12 PM
  2. Trouble in Runing
    By kavithaprabhaker in forum New To Java
    Replies: 5
    Last Post: 05-13-2008, 05:59 AM
  3. trouble with program
    By jimJohnson in forum New To Java
    Replies: 1
    Last Post: 04-03-2008, 09:29 AM
  4. Having trouble with array
    By ice22 in forum New To Java
    Replies: 3
    Last Post: 11-13-2007, 03:06 AM
  5. JTree trouble
    By Alantie Vala in forum AWT / Swing
    Replies: 3
    Last Post: 07-31-2007, 11:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •