A soft drink company recently surveyed 12,467 of its customers and found that ap
ID: 3553007 • Letter: A
Question
A soft drink company recently surveyed 12,467 of its customers and found that approximately 14 percent of those surveyed purchase one or more energy drinks per week. Of those customers who purchase energy drinks, approximately 64 percent of them prefer citrus-flavored energy drinks. Write a Java program that displays the following:
*The approximate number of customers in the survey who purchase one or more energy drinks per week.
*The approximate number of customers in the survey who prefer citrus-flavored energy drinks.
___________________________________________
This is what I have so far and it runs with no errors but my numbers being displayed at the end are not mathematically correct or look like they're in the right decimal format...Can't figure out what exactly needs to be changed.. Also what would be another datatype I could use for customers, as I realize they're not going to be a half.
_______________________________________________________
public class Ex2_15 {
private double customers;
private double thoseThatPurch;
private double preferCitrus;
private double nopeople1;
private double nopeople2;
public Ex2_15()
{
customers = 12467;
thoseThatPurch = 14;
preferCitrus = 64;
}
public Ex2_15(double customers, double thoseThatPurch, double preferCitrus) {
this.customers = customers;
this.thoseThatPurch = thoseThatPurch;
this.preferCitrus = preferCitrus;
}
public void printOutput()
{
nopeople1 = customers * thoseThatPurch;
nopeople2 = nopeople1 * preferCitrus;
System.out.println("********************************************");
System.out.println("ENERGY DRINK CONSUMPTION");
System.out.println("********************************************");
System.out.println("Number of people surveyed: " + customers);
System.out.println("Number who purchase one or more energy drinks: " + nopeople1);
System.out.println("Number who prefer citrus flavored energy drinks: " + nopeople2);
System.out.println();
}
public static void main(String args[]) {
Ex2_15 edc1 = new Ex2_15();
Ex2_15 edc2 = new Ex2_15(12467.0,14.0,64.0);
edc1.printOutput();
edc2.printOutput();
}
}
_________________________________
END RESULT :
********************************************
ENERGY DRINK CONSUMPTION
********************************************
Number of people surveyed: 12467.0
Number who purchase one or more energy drinks: 174538.0
Number who prefer citrus flavored energy drinks: 1.1170432E7
********************************************
ENERGY DRINK CONSUMPTION
********************************************
Number of people surveyed: 12467.0
Number who purchase one or more energy drinks: 174538.0
Number who prefer citrus flavored energy drinks: 1.1170432E7
Explanation / Answer
public class Ex2_15 {
private long customers;
private long thoseThatPurch;
private long preferCitrus;
private long nopeople1;
private long nopeople2;
public Ex2_15()
{
customers = 12467;
thoseThatPurch = 14;
preferCitrus = 64;
}
public Ex2_15(long customers, long thoseThatPurch, long preferCitrus) {
this.customers = customers;
this.thoseThatPurch = thoseThatPurch;
this.preferCitrus = preferCitrus;
}
public void printOutput()
{
nopeople1 = customers * thoseThatPurch/100;
nopeople2 = nopeople1 * preferCitrus/100;
System.out.println("********************************************");
System.out.println("ENERGY DRINK CONSUMPTION");
System.out.println("********************************************");
System.out.println("Number of people surveyed: " + customers);
System.out.println("Number who purchase one or more energy drinks: " + nopeople1);
System.out.println("Number who prefer citrus flavored energy drinks: " + nopeople2);
System.out.println();
}
public static void main(String args[]) {
Ex2_15 edc1 = new Ex2_15();
Ex2_15 edc2 = new Ex2_15(12467,14,64);
edc1.printOutput();
edc2.printOutput();
}
}
OUTPUT:
********************************************
ENERGY DRINK CONSUMPTION
********************************************
Number of people surveyed: 12467
Number who purchase one or more energy drinks: 1745
Number who prefer citrus flavored energy drinks: 1116
********************************************
ENERGY DRINK CONSUMPTION
********************************************
Number of people surveyed: 12467
Number who purchase one or more energy drinks: 1745
Number who prefer citrus flavored energy drinks: 1116
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.