I'm trying to create a program that includes a menu and will execute whatever choice the user chooses. I completed the methods and got them to compile, but am lost on how to call the classes. Here is the code in screenshots so they're easier to read:
Geek Class: (Contains all the methods)
public class Geek{ private String name; private int numberofQuestions=0; public Geek (String name){ this.name = name; numberofQuestions = 0; } public String getName(){ return name; } public int getnumberofQuestions(){ return numberofQuestions; } public boolean allTheSame(int num1, int num2, int num3){ numberofQuestions++; if(num1 == num2 && num2 == num3 && num1 == num3){ return true;} else return false; } public int sum (int num1, int num2){ numberofQuestions++; int largest = Math.max(num1, num2); int smallest = Math.min(num1, num2); int result =0; for (int i=smallest; i <= largest;i++){ result = result + i;} return result; } public String repeat(String str, int n){ numberofQuestions++; String repetition = ""; for (int j=0; j < n; j++){ repetition = repetition + str;} return repetition; } public boolean isPalindrome(String str){ numberofQuestions++; int n = str.length(); for( int i = 0; i < n/2; i++ ) if (str.charAt(i) != str.charAt(n-i-1)) return false; return true; } } Main:
https://i.sstatic.net/E2z3a.png
EDIT: Im getting a cannot find symbol error in this section of code:
case "d": myGeek.sum(num1, num2, num3); System.out.println("Enter the first number"); int num1 = scan.nextInt(); System.out.println("Enter the second number"); int num2 = scan.nextInt(); System.out.println("Enter the third number"); int num3 = scan.nextInt(); break;