These are the problems:
Ground Beef Value Calculator
Different packages of ground beef have different percentages of fat and different costs per pound. Write a program that asks the user for:
1. The price per pound of package "A"
2. The percent lean in package "A"
3. The price per pound of package "B"
4. The percent lean in package "B"
The program then calculates the cost per pound of lean (non-fat) beef for each package and writes out which is the best value.
Price per pound package A:
2.89
Percent lean package A:
85
Price per pound package B:
3.49
Percent lean package B:
93
Package A cost per pound of lean:3.4
Package B cost per pound of lean:3.752688
Package A is the best value
Assume that the two packages will not come out equal in value.
This is my unfinished code because I don't know how would I compute the formula to derived with these answers:
import java.util.Scanner;
public class DMExer5 {
public static void main (String [] args){
Scanner scan = new Scanner(System.in);
System.out.println("Price per pound package A: ");
double priceA = scan.nextDouble();
System.out.println("Percent lean package A: ");
double leanA = scan.nextDouble();
System.out.println("Price per pound package B: ");
double priceB = scan.nextDouble();
System.out.println("Percent lean package B: ");
double leanB = scan.nextDouble();
double percentA = 100-leanA; // not sure with my formulas
double percentB = 100-leanB;
double A = priceA + (percentA*0.01);
double B = priceB + (percentB*0.01);
System.out.println("");
System.out.printf("Package A cost per pound of lean: %.2f " , A);
System.out.println("");
System.out.printf("Package B cost per pound of lean:%.4f " , B);
System.out.println("");
if(A<B){
System.out.println("package A is the best value");}
else {
System.out.println("package B is the best value");
}
}
}
Second, Write a program that asks a user for their birth year encoded as two digits (like "62") and for the current year, also encoded as two digits (like "99").
The program is to correctly write out the users age in years.
Sample Output:
Year of Birth: 62
Current year: 99
Your age: 37
The program will have to determine when a two digit value such as "62" corresponds to a year in the 20th century ("1962") or the 21st century.
Here another run of the program, where "00" is taken to mean the year 2000:
Year of Birth: 62
Current year: 00
Your age: 38
Assume that ages are not negative. Another run of the program:
Year of Birth: 27
Current year: 07
Your age: 80
In the following run, the age of the person could be 6 or 106 depending on the assumptions. Assume that the age will always be less than or equal to
100.
Year of Birth: 01
Current year: 07
Your age: 6
codes:
import java.util.Scanner;
public class DMExer5b {
public static void main(String args []){
Scanner scan = new Scanner(System.in);
System.out.print("Year of Birth: ");
int birth = scan.nextInt();
System.out.print("Current Year: ");
int current = scan.nextInt();
int age = current-birth;
if(current<20){
int lower = current + 2000;
int age2 = lower - (birth+1900);
System.out.println("Your age:"+age2);}
else if (birth<20){
int age3 = current - birth;
System.out.println("Your age:" + age3); }
else {
System.out.println("Your age:" + age);}
}
}
Thanks for the help!