Question

In: Computer Science

Use the code supplied to display the Customers, Products, and Prices . Also show the total...

Use the code supplied to display the Customers, Products, and Prices . Also show the total and average prices package

arraylist3;

import java.util.ArrayList;

import javax.swing.JOptionPane;

public class Arraylist3 {

public static void main(String[] args) {

private static ArrayList customers = new ArrayList<>()

; private static ArrayList products = new ArrayList<>();

private static ArrayList price = new ArrayList<>();

private static int x = 0;

public static void main(String[] args) {

x = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the number of customer")); input_customers(); display_sales_report(); } private static void input_customers(){ for(int y = 0;y < x; y++){ customers.add(JOptionPane.showInputDialog(null,"Please enter the customer :"+(y+1))); products.add(JOptionPane.showInputDialog(null,"Please enter the product :" + customers.get(y))); price.add(Double.parseDouble(JOptionPane.showInputDialog(null,"Please enter the price :R" + products.get(y)))); } } private static void display_sales_report(){ } } } }

Solutions

Expert Solution

The java code after modifying the given code is as follows:

//importing the necessary components
import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Arraylist3 
{
public static void main(String[] args) 
{
//declaring the variable arraylists    
private static ArrayList customers = new ArrayList<>();
private static ArrayList products = new ArrayList<>();
private static ArrayList price = new ArrayList<>();
private static int x = 0;
//main method
public static void main(String[] args) 
{
x = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the number of customers"));
input_customers();
display_sales_report();
}
// method to take inputs
private static void input_customers() 
{
    for(int y = 0;y < x; y++)
    { 
        customers.add(JOptionPane.showInputDialog(null,"Please enter the customer :"+(y+1)));
        products.add(JOptionPane.showInputDialog(null,"Please enter the product :" + customers.get(y)));
        price.add(Double.parseDouble(JOptionPane.showInputDialog(null,"Please enter the price :R" + products.get(y))));
    }
} 
//method to display the output
private static void display_sales_report() 
{
    float sum=0;
    for(int i=0;i<price.size();i++)
    {
        sum=sum+price.get(i);    
    }
    JOptionPane.showMessageDialog(null,"Total prices:"+ sum);
    float average=0;
    average=sum/price.size();
    JOptionPane.showMessageDialog(null,"Average of prices: "+ average);
} 
    
} 


    


Related Solutions

Show the code in matlab to display an ECG graph (I do not want code that...
Show the code in matlab to display an ECG graph (I do not want code that simply calls the ecg function in matlab but how to write that kind of code)
Write VHDL code for the following: Use HEX-to-seven segment display converters to display the inputs and...
Write VHDL code for the following: Use HEX-to-seven segment display converters to display the inputs and results for a 4-bit adder. The inputs are unsigned 4-bit binary numbers. The outcome is a 4-bit binary adder with LED display. First you need to create a symbol for the HEX-to-seven segment display converter. Then implement a 4-bit adder using VHDL. Finally, connect three HEX-to-seven segment display converters to display input X, input Y, and sum S.
If an internal selling division can also sell products to outside companies at a prices that...
If an internal selling division can also sell products to outside companies at a prices that are greater than the selling division's marginal costs for these products how should the selling division set its transfer prices for these same products when it sells them to the internal buying division?
Write a passage and use Mathlab to display a matrix showing the code word and probability...
Write a passage and use Mathlab to display a matrix showing the code word and probability of occurrence of each character. thanks
Also please add comments on the code and complete in C and also please use your...
Also please add comments on the code and complete in C and also please use your last name as key. The primary objective of this project is to increase your understanding of the fundamental implementation of Vigenere Cipher based program to encrypt any given message based on the Vignere algorithm. Your last name must be used as the cipher key. You also have to skip the space between the words, while replicating the key to cover the entire message. Test...
You will need your ticker code for stock prices for this question. Use your ticker code...
You will need your ticker code for stock prices for this question. Use your ticker code to obtain the closing prices for the following time period: March 2, 2019 to March 16, 2019 Use the last two digits (the decimals) of the closing price and use them to replace the X.Xs in the following table. Notice that in the dataset a decimal point will separate the two digits. (already been done in the table) Head Width (cm) Bitting Force (grams/centimer^2)...
How do I use ASCII code to generate and display two random letters that are one...
How do I use ASCII code to generate and display two random letters that are one lowercase and one uppercase in C++? Please give me an example.  
Please use C programming to write the code to solve the following problem. Also, please use...
Please use C programming to write the code to solve the following problem. Also, please use the instructions, functions, syntax and any other required part of the problem. Thanks in advance. Use these functions below especially: void inputStringFromUser(char *prompt, char *s, int arraySize); void songNameDuplicate(char *songName); void songNameFound(char *songName); void songNameNotFound(char *songName); void songNameDeleted(char *songName); void artistFound(char *artist); void artistNotFound(char *artist); void printMusicLibraryEmpty(void); void printMusicLibraryTitle(void); const int MAX_LENGTH = 1024; You will write a program that maintains information about your...
APPLIED STATISTICS 2 USE R CODE! SHOW R CODE Use data file RecordMath2526.txt, to produce a...
APPLIED STATISTICS 2 USE R CODE! SHOW R CODE Use data file RecordMath2526.txt, to produce a plot graph with Exam1 as x, Exam2 as y, use Gender as color, and Hw1 as pch. RecordMath2526 information Index Gender Hw1 Hw2 Hw3 Exam1 Hw4 Exam2 Hw5 Hw6 Hw7 Final 1 F 9 6 8 60 7 82 10 10 9 69 2 M 10 10 10 94 9 98 10 10 8 91 3 M 9 10 8 79 9 55 10...
pl use R code to do that and show me the program Use a linear regression...
pl use R code to do that and show me the program Use a linear regression of Y~log(X) using the labtestdata.csv data to predict Y (2dp) when x = 250 on the unlogged scale? Calculate the F-value (1 dp) from an ANOVA on the regression of Y~log(X) using the data contained in labtestdata.csv abtestdata.csv y x 1.018746 1 1.508895 2 0.727282 3 1.787127 4 2.903983 5 3.181554 6 1.737834 7 2.715766 8 1.570552 9 3.046107 10 4.499675 11 4.240688 12...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT