Question

please only use java import j option pane. use modular programing please write a program with...

please only use java import j option pane. use modular programing please write a program with a two dimensional array use int for array whole numbers are going to be use. the purpose is to fill the array with the item number and price of up to 100 products (up to 100 item numbers and up to 100 prices). then print out the array. Also verify that the user is entering a number greater then 0 for each input (item number) (price)

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

import javax.swing.JOptionPane;

public class ProductsPrices {
   public static void main(String[] args) {
       int arr[][] = new int[100][2];
       int size = getProductsAndPrices(arr);
       displayProducts(arr, size);

   }

   private static void displayProducts(int[][] aArr, int aSize) {
       for (int i = 0; i < aSize; i++)
           System.out.println(aArr[i][0] + " : " + aArr[i][1]);
   }

   private static int getProductsAndPrices(int[][] arr) {
       int size = 0;
       for (int i = 0; i < 100;) {
           int id = Integer.parseInt(JOptionPane.showInputDialog("Enter Product ID (-1 to exit)"));
           if (id == -1)
               break;
           int price = Integer.parseInt(JOptionPane.showInputDialog("Enter Product price"));
           while (id <= 0 || price <= 0) {
               JOptionPane.showMessageDialog(null, "Values must be greater than 0");
               id = Integer.parseInt(JOptionPane.showInputDialog("Enter Product ID (-1 to exit)"));
               if (id == -1)
                   break;
               price = Integer.parseInt(JOptionPane.showInputDialog("Enter Product price"));
           }
           arr[i][0] = id;
           arr[i][1] = price;
           size++;
           i++;
       }
       return size;
   }
}

<terminated> ProductsPrices Java A : 100 2: 200

Add a comment
Know the answer?
Add Answer to:
please only use java import j option pane. use modular programing please write a program with...
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
  • In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are...

    In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are in the range 0 to 100 inclusive. The program will ask a user to re-enter an integer if the user inputs a number outside of that range. The inputted integers must then be stored in a single dimensional array of size 20. Please create 3 methods: 1. Write a method public static int countEven(int[] inputArray) The method counts how many even numbers are in...

  • java; programing language Write a program to calculate the price of a purchase. It should ask...

    java; programing language Write a program to calculate the price of a purchase. It should ask the user to enter the name of the item bought (like sweater, apple, …), number of items bought (4, 5 lbs,…), price per item ($40.50, $1.99 per pound,…), and the sales tax rate (8.35% for example). It should calculate the subtotal (price*number of items), sales tax (subtotal*sales tax), and total price (subtotal+ sales tax). It should print all the information in a receipt form

  • Please help, Array does not print properly. I need to print out the 8 class numbers...

    Please help, Array does not print properly. I need to print out the 8 class numbers entered by the user ! Java only using J option pane, you cannot use ulti or anything else only J option pane Program compiles but does not print the array correctly! import javax.swing.JOptionPane; public class programtrial {    public static void main(String[] args) {    int newclass = 0;    int countclass = 0;    final int class_Max = 8;    int[] classarray =...

  • Please complete this code for java Lab Write a program as follows: Create an array with...

    Please complete this code for java Lab Write a program as follows: Create an array with 10 elements. The array should contain numbers generated randomly between 1 and 100 Ask the user to enter any number - Search the array to see if the user entered number is in the array If the user-entered number is in the array, print a 'match found' message. Also print at which index the match was found, else print a 'match not found' message...

  • use java thanks 1.Given the following arrays, write a Java program to generate the output below....

    use java thanks 1.Given the following arrays, write a Java program to generate the output below.    String [] item = {"milo", "water", "coke", "tea", "coffee"};    double [] price = {3.00, 1.00, 5.00, 2.00, 3.50};    int [] quantity = {200, 500, 350, 100, 700}; Re-write Question 1 using array list and display the sale of the day report. Re-write Question 1 using 2-dimensional array and display the sale of the day report. Write a segment program to replace...

  • Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a...

    Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a one-dimensional array with the first 30 Fibonacci numbers using a calculation to generate the numbers. Note: The first two Fibonacci numbers 0 and 1 should be generated explicitly as in -long[] series = new long[limit]; //create first 2 series elements series[0] = 0; series[1] = 1; -But, it is not permissible to fill the array explicitly with the Fibonacci series’ after the first two...

  • Please write a Java program that does the following: Create an array of 100 integers. Store...

    Please write a Java program that does the following: Create an array of 100 integers. Store 100 random integers (between 1 and 100) in the array. Print out the elements of the array. Sort the array in ascending order. Print out the sorted array. Prompt the user to enter a number between 1 and 100. Search the array for that number and then display "Found" or "Not Found" message. Display each number from 1 to 100 and the number of...

  • In Java Write a program that reads an arbitrary number of 25 integers that are positive...

    In Java Write a program that reads an arbitrary number of 25 integers that are positive and even. The program will ask the user to re-enter an integer if the user inputs a number that is odd or negative or zero. The inputted integers must then be stored in a two dimensional array of size 5 x 5. Please create 3 methods: 1. Write a method public static int sum2DArray( int [1] inputArray ) The method sums up all elements...

  • (JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students...

    (JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students identified by rows and test scores identified by columns. Ask the user for the number of students and for the number of tests (which will be the size of the two-dimensional array). Populate the array with user input (with numbers in {0, 100} for test scores). Assume that a score >= 60 is a pass for the below. Then, write methods for: Computing the...

  • Java. Please write the output import java.util.Scanner; import java.text.Decimalformat: * This program demonstrates two-dimensional array. public...

    Java. Please write the output import java.util.Scanner; import java.text.Decimalformat: * This program demonstrates two-dimensional array. public class CorpSales public static void main(String[] args) Final int DIVS - 3; // Three divisions in the company final int QTRS = 4; // Four quarters double totalSales - e.e; / Accumulator // Create an array to hold the sales for each // division, for each quarter. double[][] sales - new double[DIVS][QTRS] // Create a Scanner object for keyboard input. Scanner keyboard = new...

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