My task is to create 3 CellPhone objects, and to take in user input. The user enters the manufacturer, the model, and the price. Im supposed to then find the lowest price of the 3 phones. This is my code
public class CellPhone {
Scanner scan = new Scanner(System.in);
private static String manufact;
private static String model;
private static double price;
public CellPhone(String manufact, String model, double price) {
manufact = CellPhone.manufact;
model = CellPhone.model;
price = CellPhone.price;
}
public String getManufact() {
return manufact;
}
public void setManufact(String manufact) {
CellPhone.manufact = manufact;
}
public String getModel() {
return model;
}
public void setModel(String model) {
CellPhone.model = model;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
CellPhone.price = price;
}
And then my main method is
public static void main(String[] args) throws IOException {
//I created 9 different scanners, to use 3 as arguments for each of the 3 objects
Scanner scan = new Scanner(System.in);
String manufact = scan.next();
String model = scan.next();
double price = scan.nextDouble();
String manufact1 = scan.next();
String model1 = scan.next();
double price1 = scan.nextDouble();
String manufact2 = scan.next();
String model2 = scan.next();
double price2 = scan.nextDouble();
//objects
CellPhone cell1 = new CellPhone(manufact, model, price);
CellPhone cell2 = new CellPhone(manufact1, model1, price1);
CellPhone cell3 = new CellPhone(manufact2, model2, price2);
PrintWriter outputFile = new PrintWriter("bestprice.txt");
// finds lowest retail price for each object
if (cell1.getPrice() < cell2.getPrice()) {
if (cell1.getPrice() < cell3.getPrice()) {
outputFile.println(
"The lowest price is:\n" + cell1.getManufact() + cell1.getModel() + "for $" + cell1.getPrice());
System.out.println(
"The lowest price is:\n" + cell1.getManufact() + cell1.getModel() + "for $" + cell1.getPrice());
}
}
if (cell2.getPrice() < cell1.getPrice()) {
if (cell2.getPrice() < cell3.getPrice()) {
outputFile.println(
"The lowest price is:\n" + cell2.getManufact() + cell2.getModel() + "for $" + cell2.getPrice());
System.out.println(
"The lowest price is:\n" + cell2.getManufact() + cell2.getModel() + "for $" + cell2.getPrice());
}
}
if (cell3.getPrice() < cell1.getPrice()) {
if (cell3.getPrice() < cell2.getPrice()) {
outputFile.println(
"The lowest price is:\n" + cell3.getManufact() + cell3.getModel() + "for $" + cell3.getPrice());
System.out.println(
"The lowest price is:\n" + cell3.getManufact() + cell3.getModel() + "for $" + cell3.getPrice());
}
}
outputFile.close();
}
my program has no output whatsoever. What have I done wrong?