public class Main { //global variables static int yoVol,heyVol; static final int targetVolume = 15; public static void main(String[] args) { // TODO Auto-generated method stub yoVol = 0; heyVol = 0; welcome(); game(); } public static void welcome() { System.out.println("Welcome to Dr Hey and Dr Yo!"); for(int i = 0; i<5; i++) System.out.print("Hey Yo!!\t"); } public static void game() { while(heyVol < targetVolume && yoVol < targetVolume) { scream(); } //end of screaming, determine the winner determineWinner(); } public static void scream() { String word; //Dr Hey screams a word word = getScreamWord(); updateVolume("Dr Hey", word); //Dr Yo screams a word word = getScreamWord(); updateVolume("Dr Yo", word); } //it figures out whose volume to update public static void updateVolume(String player, String screamWord) { System.out.println("\n"+player+" screamed "+screamWord+"!"); if(player.equals("Dr Yo") && screamWord.equals("Yo!")) { yoVol = yoVol+1; //update Dr Yo's volume } if(player.equals("Dr Hey") && screamWord.equals("Hey!")) { heyVol = heyVol+1; //update Dr Hey's volume } } //this function returns either "Hey!" or "Yo!" public static String getScreamWord() { int rand = (int)(Math.random()*2); if(rand%2==0) { return "Hey!"; }else{ return "Yo!"; } } public static void determineWinner() { if(heyVol>yoVol){ System.out.println("Dr Hey is the winner. Volume: "+heyVol); }else if(yoVol>heyVol) { System.out.println("Dr Yo is the winner. Volume: "+yoVol); }else{ System.out.println("It's a tie! Dr Hey Volume: "+heyVol+"; Dr Yo Volume: "+yoVol); } } }