-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompareCosts.java
More file actions
22 lines (19 loc) · 1.01 KB
/
Copy pathCompareCosts.java
File metadata and controls
22 lines (19 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.util.Scanner;
public class CompareCosts {
public static void main(String[] args) {
Scanner input = new Scanner(System.in); // Create Scanner object
// Prompt the user to enter the weight and price of each package
System.out.print("Enter weight and price for package 1: ");
double weight1 = input.nextDouble();
double price1 = input.nextDouble();
System.out.print("Enter weight and price for package 2: ");
double weight2 = input.nextDouble();
double price2 = input.nextDouble();
if (price1 / weight1 < price2 / weight2)
System.out.println("Package 1 has a better price.");
else if (price1 / weight1 > price2 / weight2)
System.out.println("Package 2 has a better price.");
else
System.out.println("Two packages have the same price.");
}
}