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); } }
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 now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images