Question

Code in Java using ( NetBeans )

Chapter 7 Assignment (Popular Candy) - 15 points Your goal is to record the sales for 4 different types of candy and determin

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Java Program:

package candybox;

import javax.swing.*;

public class CandyBox {
  
//Main method
public static void main(String[] args) {
JFrame f=new JFrame();
   String[] candies = {"Sour Apple", "Fizzy Chip", "Marshmallows", "Jelly Snake"};
   int[] sales = new int[4];
  
//Reading sales of each candy box
for(int i=0; i<4; i++) {
//Reading sales
sales[i] = Integer.parseInt(JOptionPane.showInputDialog(f,"Enter the number of boxes of " + candies[i]));
}
  
//Calculating total sales and highest and lowest selling candies
int total=0, high=0, low=0;
  
//Iterating over candies
for(int i=0; i<4; i++) {
  
//Accumulating total sales
total += sales[i];
  
//Comparing for highest number of sales
if(sales[i] > sales[high]) {
//Updating values
high = i;
}
//Comparing for lowest number of sales
if(sales[i] < sales[low]) {
//Updating values
low = i;
}
}
  
//Printing results
   JOptionPane.showMessageDialog(f,"Total boxes of candy sold: " + total + "\nHighest Selling Candy: " + candies[high] + "\nLowest Selling Candy: " + candies[low]);
}
}

__________________________________________________________________________________________

Sample Run:

X Input ? Enter the number of boxes of Sour Apple 15 OK Cancel

х Message 0 Total boxes of candy sold: 59 Highest Selling Candy: Fizzy Chip Lowest Selling Candy: Marshmallows OK

Add a comment
Know the answer?
Add Answer to:
Code in Java using ( NetBeans ) Chapter 7 Assignment (Popular Candy) - 15 points Your...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Program 2 <100 points>: Chips and Salsa (chipsSalsa.cpp) Write a program that lets a maker of...

    Program 2 <100 points>: Chips and Salsa (chipsSalsa.cpp) Write a program that lets a maker of chips and salsa keep track of sales for five different types of salsa: mild, medium, sweet, hot, and zesty. The program should use two parallel 5-element arrays: an array of strings that holds the five salsa names and an array of integers that holds the number of jars sold during the past month for each salsa type. The salsa names should be stored using...

  • Write a C++ program that lets a maker of chips and salsa keep track of their...

    Write a C++ program that lets a maker of chips and salsa keep track of their sales for five different types of salsa they produce: mild, medium, sweet, hot, and zesty. It should use two parallel five-element arrays: an array of strings that holds the five salsa names and an array of integers that holds the number of jars sold during the past month for each salsa type. The salsa names should be stored using an initialization list at the...

  • In this module, you learned about Arrays in C++ and how to implement arrays within your...

    In this module, you learned about Arrays in C++ and how to implement arrays within your C++ programs. For this assignment, you will implement your knowledge of arrays for Michigan Popcorn Company’s sales management system. Write a program that lets the Michigan Popcorn Company keep track of their sales for seven different types of popcorn they produce: plain, butter, caramel, cheese, chocolate, turtle and zebra. It should use two parallel seven-element arrays: an array of strings that holds the seven...

  • Need to revise the following code to use an array of product objects instead of two...

    Need to revise the following code to use an array of product objects instead of two parallel arrays. The product class will need member variables to hold a product name and a quantity. #include<iostream> #include<string> using namespace std; int main() { //Declare variables const int salsaTypes = 5; const int jarsSold = 5; string salsa[salsaTypes] = { "Mild", "Medium", "Sweet", "Hot", "Zesty" }; int jars[jarsSold]; int totalSales, highestSales, lowestSales; string highestSoldProduct; string lowesetSoldProduct; //Repeat loop for all salsas for (int...

  • Please Write in Java 15 salesmen have performed sales in 10 different cities and the information...

    Please Write in Java 15 salesmen have performed sales in 10 different cities and the information is stored in a two-dimensional array. For example: City 0 City 1 City 2 City … City 9 salesman 0 3.4 4.0 2.6 …… 3.5 salesman 1 3.7 4.44 1.90 …… 5.9 salesman … 1.5 5.9 7.4 …… 0.0 salesman 14 44.4 5.6 7.8 ….. 0.9 Write a class called Employee that contains the following methods A static method called totalSales() (String name, double...

  • Assignment 1. You are to write a simple program using Netbeans Java IDE  that consists of two...

    Assignment 1. You are to write a simple program using Netbeans Java IDE  that consists of two classes. The program will allow the user to place an order for a Tesla Model X car. 2. Present the user with a menu selection for each option on the site. We will use JOptionPane to generate different options for the user. See the examples posted for how to use JOPtionPane. 3. Each menu will have multiple items each item will be in the...

  • Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that...

    Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that will process monthly sales data for a small company. The data will be used to calculate total sales for each month in a year. The monthly sales totals will be needed for later processing, so it will be stored in an array. Basic Logic for main() Note: all of the functions mentioned in this logic are described below. Declare an array of 12 float/doubles...

  • Project 4: Month-end Sales Report with array and validation Input dialog box for initial user prompt...

    Project 4: Month-end Sales Report with array and validation Input dialog box for initial user prompt with good data and after invalid data Input OK Cancel Input dialog boxes with sample input for Property 1 Ingut X Input Enter the address for Property 1 Enter the value of Property 1: OK Cancel Input dialog boxes after invalid data entered for Property 1 Error Please enter anmumber greater than D Ester the walue of Peoperty t Console output END SALES REPORT...

  • If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but...

    If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but minor discrepancies may require you to adjust. If you are attempting this assignment using another version of Visual Studio, you can expect differences in the look, feel, and/or step-by-step instructions below and you’ll have to determine the equivalent actions or operations for your version on your own. INTRODUCTION: In this assignment, you will develop some of the logic for, and then work with, the...

  • Objectives – to practice these new concepts: decision-making with if, if-else, if-else-if-… switch data validation for...

    Objectives – to practice these new concepts: decision-making with if, if-else, if-else-if-… switch data validation for user input using a while (or while/do) loop nicely formatted output report with printf and format strings multiple input data sets using a while (or while/do) loop named constants PROJECT OVERVIEW This project provides a detailed payroll report for the sales staff at TheLaptopShop. The company has 3 tiers of salespeople: low, middle, high (designated by L, M, H) – based on their past...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT