
Concept explainers
PLEASE NEED HELP WITH THIS JAVA CODE!!!!! I need help changing this java code from scanner input to ONLY JOptionPane for input and output. So meaning no import scanner should not be in this code only import JOptionPane should be in this code for input and output import java.util.Scanner; // class to perform all processing class Process { // method to get best bid from the 2D array public int getBestBid(int [][]bidsAndRatings) { int bestIndex=0; // Loop to check each element and determine which is the best bid of all for(int i=1;i<5;i++) { if(bidsAndRatings[i][0] < bidsAndRatings[bestIndex][0] && bidsAndRatings[i][1] > bidsAndRatings[bestIndex][1]) { bestIndex=i; } } // return the index of best bid from the array return bestIndex; } // method to print report of the bid public void printBids(int [][]bidsAndRatings,String []namesOfContacter) { // varaible to calculate total bids int totalBids = 0; // printing the report in well formatted format System.out.println("\nAll Bids placed are: "); System.out.printf("\n%10s %10s %10s\n","Name","Bid","Rating"); // Loop to print the report for(int i=0;i<5;i++) { System.out.printf("\n%10s %10d %10d",namesOfContacter[i],bidsAndRatings[i][0],bidsAndRatings[i][1]); totalBids+=bidsAndRatings[i][1]; } // printing average of bids System.out.println("\nAvergae Bid Amount is "+(totalBids/5)); } public void takeAndProcessInputs(int maxBudget) { // 2d array for bids and ratings and 1D array for names // 2D array has column 1 for bids and column 2 for ratings int [][] bidsAndRatings = new int[5][2]; String []namesOfContacter = new String[5]; Scanner cin = new Scanner(System.in); int inputsTaken = 0; // Loop to accept inputs until 5 inputs are recived while(inputsTaken!=5) { // take inputs from the user one by one System.out.println("\nEnter the details bid number "+(inputsTaken+1)); System.out.print("Enter the bid amount: "); int bid = cin.nextInt(); System.out.print("Enter the rating: "); int rating = cin.nextInt(); System.out.print("Enter the name of contractor: "); namesOfContacter[inputsTaken] = cin.next(); // If ratings and bid is valid then add it to array and increment inputtaken variable if(rating <= 5 && bid <= maxBudget) { bidsAndRatings[inputsTaken][0] = bid; bidsAndRatings[inputsTaken][1] = rating; inputsTaken++; } // if rating is invalid accept inputs again else if (rating > 5) { System.out.println("\nRating input is invalid!"); } // if bid is invalid accept inputs again else if(bid > maxBudget) { System.out.println("\nBid amount is more than max budget"); } } // get index of best bid int indexOfBestBid = getBestBid(bidsAndRatings); // print report of all bids printBids(bidsAndRatings,namesOfContacter); // print winning bid System.out.println("\n\nWinning bid : "); System.out.printf("\n%10s %10d %10d",namesOfContacter[indexOfBestBid],bidsAndRatings[indexOfBestBid][0],bidsAndRatings[indexOfBestBid][1]); } } // Main class with main function public class Main { public static void main(String[] args) { // Accept input for maximum budget Scanner cin = new Scanner(System.in); System.out.print("Enter the maximum budget: "); int maxBudget = cin.nextInt(); // create object of class and call the function Process p = new Process(); p.takeAndProcessInputs(maxBudget); } }

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 2 images

- Java. Please use the templatearrow_forward**Please help fix code, code is not running and not giving output* Question to be answered: Using the code in the image provided: Implement a method called summation which adds two integers and returns their sum. INPUT: The first line of input contains an integer a. The Second Line of input containes and integer b. OUTPUT: Print the result which is the sum of a and b. CODE: import java.util.*;import java.io.*;import java.math.*;class Outcome { /* * Implement method/function with name 'summation' below. * The function accepts following as parameters. * 1. a is of type int. * 2. b is of type int. * return int. */ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int a,b; a=sc.nextInt(); // enter 1st integer b=sc.nextInt(); // enter 2nd integer int sum=summation(a,b); // call function System.out.println(sum); // display message } public static int summation(int a,int b){ //Write your code here int s=0;…arrow_forwardI need help with this code !! import java.util.Arrays;import java.util.Scanner; public class MaxElement {public static void main(String[] args) { //create an object for Scanner class Scanner x = new Scanner (System.in);System.out.print ("Enter 10 integers: ");// create an arrayInteger[] arr = new Integer[10]; // Execute for loopfor (int i = 0; i < arr.length; i++) {//get the 10 integersarr[i] = x.nextInt(); } // Print the maximum numberSystem.out.print("The max number is = " + max(arr));System.out.print("\n"); } //max method public static <E extends Comparable<E>> E max(E[] arr) {E max = arr[0]; // Execute for loop for (int i = 1; i < arr.length; i++) { E element = arr[i];if (element.compareTo(max) > 0) {max = element;}}return max; }}arrow_forward
- Write a Java method (do not write a class, only the method) with the following signature: Return type: void Parameters: 2D integer array Name: printDiagonal Implement the method code that will print out the values of the 2D array along the Diagonal from left to right. For example, if the array had the following values: 56 78 98 21 33 55 98 44 11 The method should print to the console: 56,33,11 The above 2D array example is only given for you to understand the problem Do not hard code the values in your solution or assume the array is the same as the given data. Your method should work for all 2D integer arrays.arrow_forwardUse java.arrow_forwardDesign and implement a class called RandomArray, which has an integer array. The constructor receives the size of the array to be allocated, then populates the array with random numbers from the range 0 through the size of the array. Methods are required that return the minimum value, maximum value, average value, and a String representation of the array values. Document your design with a UML Class diagram. Create a separate driver class that prompts the user for the sample size, then instantiates a RandomArray object of that size and outputs its contents and the minimum, maximum, and average values.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





