Hello ive been working on this assignment for a collage project, the program is suppossed to function like a calculator, add, subtract, multiply, divide, and do a random number generator as well. Im trying to have the program run with arrays and the main problem im having is trying to write for loops to add user inputs for example have the variables in the for loops act as the numbers that are added or subtracted.
package array_calculator; import java.util.Scanner; import java.util.Arrays; //Setting up constant variables for use in calc_menu. public class ArrayCalculator { public static final String String = null; public static final double[] operand1 = new double[3]; public static final double[] operand2 = new double[3]; public static final double lowerLimit = 0; public static final double upperLimit = 0; public static final int size = 0; public static void main(String[] args) { /*Calls up get operand and get menu option methods, and to let user * choose from several options within the menu in * getOperand method.*/ System.out.println("Hello welcome to the array calculator! Enter a number to choose option "); String prompt = null; getOperand(prompt); getMenuOption(); } public static int getMenuOption() { //This method lets user choose the options in the getOperad method or calculator menu. //This method runs through several if, else if, and else statements. //The if, else if statement loops inside a do while loop. // The do while loop determines what method to call based on users choice, or if user chooses 6 or any key it exits the menu. Scanner input = new Scanner(System.in); int calc_menu = input.nextInt(); do { if(calc_menu == 1) { add(operand1, operand2); break; } else if(calc_menu == 2) { subtract(operand1, operand2); break; } else if(calc_menu == 3) { multiply(operand1, operand2); break; } else if(calc_menu == 4) { divide(operand1, operand2); break; } else if(calc_menu == 5) { random(lowerLimit, upperLimit, size); break; }else { break; } }while(calc_menu >= 1 && calc_menu <= 5); return calc_menu; } public static double[] getOperand(String prompt, int size) { } public static String getOperand(String prompt) { // This method when called in main method simply displays the calculator menu for the user. System.out.println("Array Calculator Menu "); System.out.println("<----------------------->"); System.out.println("1: Add "); System.out.println("2: Subtract "); System.out.println("3: Multiply "); System.out.println("4: Divide "); System.out.println("5: Random "); System.out.println("6: Or Any Key To Exit "); System.out.println("<----------------------->"); return String; } public static double add(double[] operand1, double[] operand2) { // This method is called from the getMenuOption method, and adds values from two arrays. Scanner input = new Scanner(System.in); System.out.println("You have chosen to add, enter a number total of three numbers per array "); for(int m = 0; m < operand1.length; m++) { operand1[m] = input.nextDouble(); } for(int n = 0; n < operand2.length; n++) { operand2[n] = input.nextDouble(); } double aDD = operand1[m] + operand2[n]; System.out.println("Your totals are " + aDD); return aDD; }
Here's what i have so far the part of the code im struggling with is in lines 86 - 102, any help would me much appriciated!