Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

can you guys help me with this problem ?? 1. change the parametized constructor

ID: 3926352 • Letter: C

Question

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;
}
  

}

Explanation / Answer

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());
                       }
               }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote