import java.util.Scanner; public class Customer{ public int compare(Camera camOn
ID: 639922 • Letter: I
Question
import java.util.Scanner;
public class Customer{
public int compare(Camera camOne, Camera camTwo) {
// complete this method
int cam1 = camOne.computeValue();
int value1 = cam1;
int cam2 = camTwo.computeValue();
int value2 = cam2;
int rat1 = camOne.userRating;
int rat2 = camTwo.userRating;
double price1 = camOne.price;
double price2 = camTwo.price;
int result;
if (value1 == value2 && rat1 == rat2 && Math.abs(price1 - price2) < 0.01)
result = 0;
else if (value1 > value2 && rat1 == rat2 && Math.abs(price1 - price2) < 0.01)
result = 1;
else if (value1 < value2 && rat1 == rat2 && Math.abs(price1 - price2) < 0.01)
result = 2;
else if (value1 == value2 && Math.abs(price1 - price2) < 0.01 && rat1 > rat2)
result = 1;
else if (value1 == value2 && Math.abs(price1 - price2) < 0.01 && rat1 < rat2)
result = 2;
else if (value1 == value2 && rat1 == rat2 && price1 < price2)
result = 1;
else if (value1 == value2 && rat1 == rat2 && price1 > price2)
result = 2;
else if (value1 == value2 && rat1 != rat2 && Math.abs(price1 - price2) > 0.01
&& price1 / value1 > price2 / value2)
result = 1;
else if (value1 == value2 && camOne.userRating != camTwo.userRating && Math.abs(price1 - price2) > 0.01
&& price1 / value1 < price2 / value2)
result = 2;
else
result = -1;
return result;
}
public static void main(String[] args) {
// Complete this method
Scanner s = new Scanner(System.in);
System.out.println ("Enter attributes of Camera 1:");
System.out.println ("Is WiFi enabled? (true/false)");
boolean hasWiFi = s.nextBoolean();
System.out.println ("Is water resistant? (true/false)");
boolean isWaterResistant = s.nextBoolean();
System.out.println ("Is GPS enabled? (true/false)");
boolean hasGPS = s.nextBoolean();
System.out.println ("Condition? (New/Refurbished/Used)");
String Condition = s.next();
System.out.println ("Enter price in $ (0.00 to 1000.00)");
double price = s.nextDouble();
System.out.println ("Enter user rating (0 to 5)");
int userRating = s.nextInt();
Camera camOne = new Camera(hasWiFi, isWaterResistant, hasGPS,
Condition, price, userRating);
System.out.println ("Enter attributes of Camera 2:");
System.out.println ("Is WiFi enabled? (true/false)");
hasWiFi = s.nextBoolean();
System.out.println ("Is water resistant? (true/false)");
isWaterResistant = s.nextBoolean();
System.out.println ("Is GPS enabled? (true/false)");
hasGPS = s.nextBoolean();
System.out.println ("Condition? (New/Refurbished/Used)");
Condition = s.next();
System.out.println ("Enter price in $ (0.00 to 1000.00)");
price = s.nextDouble();
System.out.println ("Enter user rating (0 to 5)");
userRating = s.nextInt();
Camera camTwo = new Camera(hasWiFi, isWaterResistant, hasGPS,
Condition, price, userRating);
System.out.println ("Result of Comparison: ");
Customer c = new Customer();
int rst = c.compare(camOne, camTwo);
if (rst == 0)
System.out.println ("Camera 1 is same as Camera 2!");
else if (rst == 1)
System.out.println ("Camera 1 is better than Camera 2!");
else
System.out.println ("Camera 2 is better than Camera 1!");
}
}
when I put same price and user rating but different value it gives me the wrong answer
plz help me
thankyou~
Explanation / Answer
write the another java class with name camera such that with the concept of inheritance we can achieve that....
otherwise it will throw error at
Camera camOne = new Camera(hasWiFi, isWaterResistant, hasGPS,
Condition, price, userRating);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.