1 Replies - 18089 Views - Last Post: 18 November 2009 - 09:19 PM Rate Topic: -----

#1 VB6cobolGuy  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 11-November 09

JAVA Unimplemented Method Exception

Posted 18 November 2009 - 09:03 PM

Hey guys having a little trouble doing an assignment of mine that's dealing with Unimplemented methods. I am suppose to "Create a class UnimplementedMethodException as a subclass of Runtime exception. Have the constructor take two arguments a Class class and a String methodName. Create a message "Method " + methodName + "not implemented for class" + cls.getName() pass it to the super class constructor." Here is what I got so far


FULL Assignment
1) Create a class UnimplementedMethodException as a subclass of Runtime exception. Have the constructor take two arguments a Class class and a String methodName. Create a message

“Method “ + methodName +
“ not implemented for class “ +class.getName()

Pass it to the super class constructor.

Define UnimplementedMethodException in package edu.iup.cosc210.util.

2) Create a class GrowableList that implements java.util.List. Use an array of objects for the internal data implementation. Provide a complete implementation for the add(), get(), and size() methods. The add method should reallocate the internal array whenever there is no more space available in the array. Initially create the array with a size of five and double it each time it runs out of space. For all other methods throw a new UnimplementedMethodException passing this.getClass() and the method name as a String.

Define GrowableList in package edu.iup.cosc210.util.

3) Write a program to test your GrowableList class. Make sure the add, get, and size methods are working correctly. For add, test the array is doubles in size in the event of insufficient space. In addition, test UnimplementedMethodException are thrown when calling the other methods.

4) Change the Company class to use GrowableList for your list of departments (instead of using an array). Define the type of the departments variable to be a List. You will need to modify the for loop accordingly.

5) Change Department to use ArrayList for the list of employees (instead of an array). Define the employees variable as a List of Employees.

COMPANY CLASS
package edu.iup.cosc210.company;

import java.util.List;

import edu.iup.cosc210.util.GrowableList;


/**
 * A Company.  Maintains a list of departments and methods access
 * the company's departments.
 * 
 * @
 */
public class Company {
	private List departments = new GrowableList();

	/**
	 * Add a Department to the list of departments for this company.
	 * 
	 * @param department - the company to be added
	 */
	public void addDepartment(Department department) {
		departments.add[department];
	}

	/**
	 * Find a department with a given department code
	 * 
	 * @param deptCode - the department code used to find a department
	 * @return the department with the given code.  Returns null if 
	 * a department by the given department code is not found.
	 */
	public Department findDepartment(String deptCode) {
		for (int i = 0; i < noDepts; i++) {
			Department department = departments[i];
			if (deptCode.equals(department.getDeptCode())) {
				return department;
			}
		}
		
		return null;
	}

	/**
	 * Get the number of departments in this company.
	 * @return the number of departments in this company.
	 */
	public int getNoDepts() {
		return departments.size();
	}

	/**
	 * Get the ith department in this company
	 * @param i - index identifying the department to be returned
	 * @return the ith department in this company
	 */
	public Department getDeparment(int i) {
		return (Department) departments.get(i);
	}
}




public class UnimplementedMethodException{
	
	public UnimplementedMethodException(Class class, String methodName){
		super("Method " + methodName + " of class " + cls.getName + " not implemented");
		
	}
}



I am getting errors with that?


package edu.iup.cosc210.util;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class GrowableList implements List {
	private Object[] items = new Object[5];
	private int noItems;
	
	
	public boolean add(Object item) {
		if (noItems == items.length){
			Object[] temp = new Object[items.length * 2];

			for (int i = 0; i < items.length; i++){
				temp[i] = items[i];
			}
			items = temp;
		}
		items[noItems++] = items;
		return true;
	}
	
	public Object get(int index) {
		return items[index];
	}


	public int size() {
		return noItems;
	}
	
}




if anyone can help me I'd appreciate it! JAVA is not my programming language yet haha

This post has been edited by VB6cobolGuy: 18 November 2009 - 09:05 PM


Is This A Good Question/Topic? 0
  • +

Replies To: JAVA Unimplemented Method Exception

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,858
  • Joined: 06-March 08

Re: JAVA Unimplemented Method Exception

Posted 18 November 2009 - 09:19 PM

If you write a class that extends Exception... would be a good idea to extend Exception :)

public class UnimplementedMethodException extends Exception {
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1