Scanner user input doesn't work with ACM Library

I am having a hard time reading user input. My program is supposed to use user input (in the form of an int) to perform a certain function on a source audio file. In the program, the source audio file is “voice.wav”. When the user presses 1, there should be a new audio file created called “output.wav”, which contains the contents of voice.wav at a lower volume. I believe the issue is in the user input not being read correctly. I am working with the ACM Library (Overview). Any ideas are appreciated!

Repl link: https://replit.com/@AmyWang51/Audio-Algorithms-Project-Starter-Code#MyProgram.java

public class MyProgram extends ConsoleProgram {

    public void run(){
      //Create a buffer array here for each audio file 
      int[] buffer = getBufferFromFile("organ.wav");
      
        printMessage();
        Scanner s = new Scanner(System.in);
        int choice = s.nextInt();

      //Program what happens for each option below
        if(choice == 1){

        int[] newBuffer = lowerVolume(buffer);
        writeBufferToFile("output.wav", newBuffer);
          
        } else if(choice == 2){
          
        } else if(choice == 3){
          
        } else if(choice == 4){
          
        } else if(choice == 5){
         
        } else if(choice == 6){
          
        } else if(choice == 7){
          
        }
        System.out.println("Done!");
    }

    
  

    public int[] lowerVolume(int[] buffer) {
      int[] newBuffer = new int[buffer.length];
      for(int i=0; i<buffer.length; i++) {
        newBuffer[i] = buffer[i]/4;
      }
      return newBuffer; 
      
    }

IIRC the ACM ConsoleProgram class usually has its own methods to handle user input, so instead of using Scanner , try using the input methods provided by the ConsoleProgram class like readInt().

For example, change this:

Scanner s = new Scanner(System.in);
int choice = s.nextInt();

To this:

int choice = readInt();

Did some research about the ACM and found it

1 Like