Hello together
I am learning Java and want to solve a task with certain specifications.
There are 4 inputs which the user has to enter actively and these are then written into the respective variable.
There are two prices and a delivery time.
import java.util.Scanner;
public class Customer {
public static void main(String[] args) {
Scanner keyScan = new Scanner(System.in);
int deliveryTime1, deliveryTime2;
double price1, price2;
System.out.print("Price from the first company A: ");
price1= keyScan.nextDouble();
System.out.print("Delivery time company A: ");
deliveryTime1= keyScan.nextInt();
System.out.print("Price from the first company B: ");
price2= keyScan.nextDouble();
System.out.print("Delivery time company B: ");
deliveryTime2= keyScan.nextInt();
keyScan.close();
if (price1< price2 && deliveryTime1< deliveryTime2)
System.out.println("Order from company a");
else if (price1< price2 && deliveryTime1> deliveryTime2)
System.out.println("Order from company b");
else if (price1> price2 && deliveryTime1< deliveryTime2)
System.out.println("Order from company a");
else if (price1> price2 && deliveryTime1> deliveryTime2)
System.out.println("Order from company b");
else if (price1< price2 && deliveryTime1> 14)
System.out.println("Order nothing");
else if (price1 > price2 && deliveryTime1 > 14)
System.out.println("Order nothing");
else if (price1< price2 && deliveryTime2> 14)
System.out.println("Order nothing");
else if (price1> price2 && deliveryTime2> 14)
System.out.println("Order nothing");
else if (price1== price2 && deliveryTime1 < 14)
System.out.println("Free selectable");
else if (price1== price2 && deliveryTime2 < 14)
System.out.println("Free selectable");
}
}
The following points must be fulfilled
In the case of the cheaper order with a delivery time shorter than 14 days should be ordered there
In the case of the cheaper order with a delivery time longer than 14 days but not that of the more expensive one, the order should be placed there.
if both have longer than 14 days, nothing should be ordered
if both are the same price and both do not have a delivery time longer than 14 days, the customer can decide for themselves
Furthermore, I want to program this so that the output still says how much cheaper it is compared to the other company and the delivery time of a company x is too long and this in a loop where you can trigger the order again or cancel this with a defined number with the output "Thank you for your visit"
I've currently come this far, but am still beating my head against the logic. That is, I don't know how to display the result in the system.out.println (how much cheaper it is or the delivery time) and still wrap this in a loop.
Thanks for the help!