2 Replies - 648 Views - Last Post: 02 March 2013 - 09:39 AM Rate Topic: -----

#1 rashtiman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 07-November 12

abacus model testing

Posted 02 March 2013 - 06:53 AM

//I am supposed to make an abacusmodel and test it if it works or not. Now i've made this code,
//but something is not right, the test dosent say whats wrong, so that dosent help.
//Could anyone check the code and see if something obvious is missing?

//workshop 3, until task 4 is what i've done. i now this is a homework but some help would ease my mind,
//because this anoys me. thanks

class AbacusModel 
{
        int num_of_pegs;
        int max_num_counters;
        int peg_array[];

	
	public AbacusModel(int num_pegs, int num_counters)
	{
		max_num_counters = num_counters;
		num_of_pegs = num_pegs;
		peg_array = new int[num_of_pegs];
	}
	
	boolean addCounter(int thisPeg)
   {
 
        if(thisPeg < 0 || thisPeg >= num_of_pegs)
		{
			System.out.println(2);
			return false;
		}		
 
		else if(thisPeg > max_num_counters)
		{
			System.out.println(3);
            return false;
		}
 
		else
		{
			System.out.println(4);
            peg_array[thisPeg]++;
			
            return true;
        }
	}	
		
		
	boolean removeCounter (int thisPeg)
	{
		if(thisPeg < 0 || thisPeg >= num_of_pegs || num_of_pegs < 1 )
		{
			System.out.println(5);
			return false;
		}
		else
		{
			System.out.println(6);
			peg_array[thisPeg]--;
			return true;
		}
			
	}
	
	int getNumCounters(int thisPeg)
	{
		if( thisPeg < 0 || thisPeg > peg_array[thisPeg])
		{
			System.out.println(7);
			return 12;
		}
		
		else
		{
			System.out.println(8);
			return thisPeg;
		}
	}
	
	
		
	
	public static void main(String[] args)
	{
		AbacusModel myAbacus = new AbacusModel(7, 5);

	}
	
	}

This post has been edited by GregBrannon: 02 March 2013 - 06:56 AM
Reason for edit:: Added code tags.


Is This A Good Question/Topic? 0
  • +

Replies To: abacus model testing

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2205
  • View blog
  • Posts: 5,239
  • Joined: 10-September 10

Re: abacus model testing

Posted 02 March 2013 - 07:01 AM

You create an instance of the class AbacusModel, but then the program terminates normally. You could test AbacusModel methods by adding additional code to your main() method, for example:

myAbacus.addCounter( 3 );

This post has been edited by GregBrannon: 02 March 2013 - 07:02 AM

Was This Post Helpful? 0
  • +
  • -

#3 rashtiman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 07-November 12

Re: abacus model testing

Posted 02 March 2013 - 09:39 AM

I have a program that tests my code. What my question intended to mean was what in my code is wrong, basicly. My tester dosent say, it just says my problem is incorrect
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1