Hey guys. I have two questions about my code(which has no errors but isnt giving the output i want)...Is it possible to have an if statement in my 3rd constructor? Also why is my output giving the filepath instead of outputting calcutations? Thanks for having a look
public class order {
public static int OrderNum=0;
public double Price = 0.0;
public double Discount = 0.0;
public int Quantity = 0;
public double Total = 0.0;
public String ProductName="";
public String Message = "ERROR, you havent supplied any information";
boolean isDisCounted= false;
boolean isValidOrder = true;
public order()
{
isValidOrder = false;
Message= "ERROR: you havent supplied any information";
OrderNum++;
}
public order(String s, double d, int i)
{
ProductName=s;
Price = d;
Quantity = i;
OrderNum++;
}
public order(String s, double d, int i, double d2)
{
ProductName=s;
Price = d;
Quantity = i;
Discount = d2;
if(Discount >=1 && Discount <=100)///////////////// Is this an issue here? /////////
{
isDisCounted = true;
Discount = d2;
OrderNum++;
}
else
{
isValidOrder=false;
Message = "Error: discount-" +Discount+"isnt valid";
OrderNum++;
}
}
public void calculate()
{
if (isValidOrder = false)
{
Message="ERROR:Order number"+OrderNum+"cannot be totalled as its invalid";
}
else if(isDisCounted)
{
Total = Quantity*Price;
}
else
{
Total =Quantity *Price - Quantity* Price *(Discount/100);
}
}
public String ToString()
{
if(isValidOrder && isDisCounted)
{
return(Message= OrderNum+ProductName+Price+Quantity+Total);
}
else if(isValidOrder && isDisCounted != isDisCounted)
{
return(Message = OrderNum+ProductName+Price+Quantity+Total+Discount );
}
return(Message);
}
}
public class ordercreator {
public static void main(String[] args) {
tescase0();
}
public static void testcase0()///// this is the template to use, Is it possible to do this? ////////
{
order o1 = new order("stapler",12.7, 6);
System.out.println("testcase 0:"+"\n"+ o1);
}
testcase 0: ////////////////this is the output i get///////////////////////
stellarstationary.order@8dc8569