can you guys help me with this problem 1 change the paramet

can you guys help me with this problem ??
1. change the parametized constructor so that it first checks to see if theValue is possitive. If its not, the parameterized constructor should throw a new instance of IllegalArgumentException(\"your own description\");


public class Coin {
  
//data
protected Country country;
protected String coinName;
protected int value;
  
  
// constructor
// default constructor
  
public Coin()
{
this.country=new Country(\"US\");
this.coinName=\"Quater\";
this.value=25;

}
  
//parametirezed constructor
public Coin(Country where,String theName,int theValue)
{
  
  
  
  
  
  
  
  
  
this.country=where;
this.coinName=theName;
this.value=theValue;
  
  
}
  
//copy constructor
public Coin(Coin another)
{
  
  
  
  
  
}
  
  
//methods
//getValue()-returns its value
public int getValue()
{
return value;
  
}
  

//toString-returns its String representation
public String tostring()
  
{
return coinName+\"with value\"+value;
}
  

}

Solution

The modified parameterised constructor is defined below

//parametirezed constructor
public Coin(Country where,String theName,int theValue)
       {
       try{
           if(theValue>=0)
               {
               this.country=where;
               this.coinName=theName;
               this.value=theValue;
               }
               else // if negative throw new IllegalArgumentException
                   {
                   throw new IllegalArgumentException(\"Number should be positive\");
                   }
                   }
       // catch block to catch IllegalArgumentException
               catch(IllegalArgumentException e)
                   {
                   System.out.println(e.toString());
                       }
               }


Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site