• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

purse

 
kofi ofei
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i check the programme for errors below none appear. but when i compile the programme it says i should recompile with xlint and when i run the programme nothing happens


import java.util.ArrayList;
import java.lang.String;
/** A purse holds a collection of coins.
*/
public class Purse
{
/** Constructs an empty purse.
*/
public Purse()
{
coins = new ArrayList();

}

/** Adds a coin to the purse.
@param aCoin the coin to add
*/
public void add(Coin aCoin)
{
//aCoin = new Coin(0.1);
coins.add(aCoin);
}

/**
Get the total value of the coins in the purse.
@return the sum of all coin values
*/
public double getTotal()
{
double total = 0;
for (int i = 0; i < coins.size(); i++)
{
Coin aCoin = (Coin)coins.get(i);
total = total + aCoin.getValue();
}
return total;
}
/** Counts the number of coins in the purse.
@return the number of coins
*/
public int count()
{
return coins.size();
}
/** Test whether the purse has a coin that matches a given coin.
@param aCoin the coin to match
@return true if there is a coin equal to aCoin
*/
public boolean find(Coin aCoin)
{
for(int i = 0; i < coins.size(); i++)
{
Coin c = (Coin)coins.get(i);
if (c.equals(aCoin)) return true; //found a match
}
return false; // no match in the entire array list
}
/** Counts the number of coins in the purse that match a given coin.
@param aCoin the coin to match
@return the number of coins equal to aCoin
*/
public int count(Coin aCoin)
{
int matches = 0;
for (int i = 0; i < coins.size(); i++)
{
Coin c = (Coin)coins.get(i);
if (c.equals(aCoin)) matches++; // found a match
}
return matches;
}

/** Find the coin with the largest value.
(Precondition: The purse is not empty)
@return a coin with maximum value in this purse
*/
public Coin getMaximum(/*coins aCoin*/)
{
Coin max = (Coin)coins.get(0);
for (int i= 1; i < coins.size(); i++)
{
Coin c = (Coin)coins.get(i);
if
(c.getValue()> max.getValue());
max = c;
}
return max;
}

private ArrayList coins;
}
//private Coin a;

/** public class Coin
{

public void Coin(double valuec)
{
value =valuec;
//kind = type;

}
public double getValue()
{
return value;
}
private double value;
//private String kind;
}
}*/
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ditto move to JIG (Beginner)

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic