Enter three points for p0, p1, and p2: 4.4 2 6 5 9.5 -5 4 (-5.0, 4.0) is on the
ID: 3792609 • Letter: E
Question
Enter three points for p0, p1, and p2: 4.4 2 6 5 9.5 -5 4 (-5.0, 4.0) is on the left side of the line from (4.4, 2.0) to (6.5, 9.5) Enter three points for p0, p1, and p2: 1 1 5 5 2 2 (2.0, 2.0) is on the line from (1.0, 1.0) to (5.0, 5.0) Enter three points for p0, p1, and p2: 3.4 2 6.5 9.5 5 2.5 (5.0, 2.5) is on the right side of the line from (3.4, 2.0) to (6.5, 9.5) Suppose you shop for rice in two different packages. You would like to write a program to compare the cost. The program prompts the user to enter the weight and price of the each package and displays the one with the better price. Here is a sample run: Enter weight and price for package 1: 50 24.59 Enter weight and price for package 2: 25 11.99 Package 2 has a better price. Enter weight and price for package 1: 50 25 Enter weight and price for package 2: 25 12.5 Two packages have the same price.Explanation / Answer
HI, Please find my implementation.
Please let me know in case of any issue.
import java.util.Scanner;
public class FinancialCostCmp {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter weight and price for package 1: ");
double weight1 = sc.nextDouble();
double price1 = sc.nextDouble();
double package1 = weight1*price1;
System.out.println("Enter weight and price for package 2: ");
double weight2 = sc.nextDouble();
double price2 = sc.nextDouble();
double package2 = weight2*price2;
if(package1 == package2){
System.out.println("Two package has the same price");
}else if(package1 < package1){
System.out.println("Package 2 has the better price");
}else{
System.out.println("Package 1 has the better price");
}
}
}
/*
Sample run:
Enter weight and price for package 1:
23 45.6
Enter weight and price for package 2:
20 50
Package 1 has the better price
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.