jeudi 9 avril 2015

Issue with if statment

Im trying to make an if statement so when r1 and num are equal it prints r1 but it just wont print. it asks for the product number and when I enter it nothing prints. Main all the way at the end. please show me what im doing wrong?



import java.io.*;
import java.util.*;
import java.lang.*;
import java.text.*;

public class ProductType implements Comparable<ProductType>
{



private String partnum;
private double price;
private int stock;

public ProductType (String partnum, double price , int stock ){

this.partnum = partnum;
this.price = price ;
this.stock = stock ;

}

public ProductType(){
partnum = "" ;
price = 0;
stock = 0;

}
public void setNum(String partnum)
{this.partnum = partnum;}

public void setPrice(double price)
{this.price = price ;}

public void setStock(int stock)
{this.stock = stock ;}

public String getNum()
{return partnum;}

public double getPrice()
{return price;}

public int getStock()
{return stock;}

public int compareTo(ProductType otherType)
{
int temp = (this.getNum().compareTo(otherType.getNum()));
return temp;
}

//object1.compareTo(object2);
//(function).compareTo.function2;
public String toString()
{
String result = "" + partnum + " Price" + price + "Stock" + stock;
return result;
}

public static void main(String[] args)
{

ProductType r1 = new ProductType("1422", 1.00, 2);
ProductType r2 = new ProductType("8535", 2.00, 3);

Scanner in = new Scanner(System.in);
System.out.print("enter a Product number: ");
String num = in.nextLine();

if ( r1.equals(num))
System.out.print(r1);


}

}

Aucun commentaire:

Enregistrer un commentaire