Want to make an applet

How can I turn my program into an applet

Page 1 of 1

1 Replies - 743 Views - Last Post: 15 November 2009 - 02:22 PM Rate Topic: -----

#1 lorigami  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-October 09

Want to make an applet

Posted 15 November 2009 - 02:11 PM

Hi I wanted to turn this program into an applet, but I've never made one before so I was wondering if anyone could help me. Thanks.
public final class MakeChange
{
	// Dynamic programming algorithm to solve change making problem.
	// As a result, the coinsUsed array is filled with the
	// minimum number of coins needed for change from 0 -> maxChange
	// and lastCoin contains one of the coins needed to make the change.
	public static void makeChange( int [ ] coins, int differentCoins,
				int maxChange, int [ ] coinsUsed, int [ ] lastCoin )
	{
		coinsUsed[ 0 ] = 0; lastCoin[ 0 ] = 1;

		for( int cents = 1; cents <= maxChange; cents++ )
		{
			int minCoins = cents;
			int newCoin  = 1;

			for( int j = 0; j < differentCoins; j++ )
			{
				if( coins[ j ] > cents )   // Cannot use coin j
					continue;
				if( coinsUsed[ cents - coins[ j ] ] + 1 < minCoins )
				{
					minCoins = coinsUsed[ cents - coins[ j ] ] + 1;
					newCoin  = coins[ j ];
				}
			}

			coinsUsed[ cents ] = minCoins;
			lastCoin[ cents ]  = newCoin;
		}
	}

	// Simple test program
	public static void main( String [ ] args )
	{
		// The coins and the total amount of change
		int numCoins = 5;
		int [ ] coins = { 1, 5, 10, 21, 25 };
		int change = 0;

		if( args.length == 0 )
		{
			System.out.println( "Supply a monetary amount on the command line" );
			System.exit( 0 );
		}

		try
		  { change = Integer.parseInt( args[ 0 ] ); }
		catch( NumberFormatException e )
		{
			System.out.println( e );
			System.exit( 0 ); 
		}

		int [ ] used = new int[ change + 1 ];
		int [ ] last = new int[ change + 1 ];

		makeChange( coins, numCoins, change, used, last );

		System.out.println( "Best is " + used[ change ] + " coins" );

		for( int i = change; i > 0; )
		{
			System.out.print( last[ i ] + " " );
			i -= last[ i ];
		}
		System.out.println( );
	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Want to make an applet

#2 jimdandy75  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 311
  • Joined: 30-June 08

Re: Want to make an applet

Posted 15 November 2009 - 02:22 PM

try these:
Tutorial 1
Tutorial 2
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1