Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help editing my computer program. In this game, the monkey with the most

ID: 3541282 • Letter: I

Question

I need help editing my computer program. In this game, the monkey with the most bananas at the end the of 10 rounds gets to keep all the bananas. So at the end of the program, I need to print out the age, size, wheather or not the monkey loves bananas, how many they won themselves and the total overall that they won. The following are my Monkey class and the MonkeysAndBananas Game class (that is what my professor wants our game to be called) that someone else helped me fixed too, but my professor added new things he wants.  Thank you to whoever helps me out.


public class Monkey
{
private String name;
private int age;
private float size;
private boolean loveBananas;


public Monkey()
{
name = "";

}

public void setname(String name)
{this.name = name;}

public String toString()
{
return name;
}

public void setAge( int newAge){
      age = newAge;
   }

public int getAge(){
      return age;
   }


public void setSize(float newSize)
{size = newSize;}

public float getSize()
{return size; }

public boolean  loveBananas()
{
  if (loveBananas) {
    return true ;
  }else{
      loveBananas = false;
      return false;
    }
}}


  

import java.util.Scanner;
import java.io.*;
import java.lang.String;


public class MonkeysAndBananas
{
private Monkey greedyKong, dozyKong, sleepyKong;
private int lastRoll;
private int totalBananas1,totalBananas2,totalBananas3;
private Die die;
public MonkeysAndBananas()
{
die = new Die();
this.lastRoll = 0;
this.totalBananas1 = 0;
this.totalBananas2 = 0;
this.totalBananas3 = 0;
greedyKong = new Monkey();
dozyKong = new Monkey();
sleepyKong = new Monkey();
sleepyKong.setAge (1);
greedyKong.setAge(2);
dozyKong.setAge(3);
sleepyKong.setSize(2.5f);
greedyKong.setSize(3.5f);
dozyKong.setSize(4.5f);

greedyKong.setname("GreedyKong");
dozyKong.setname("DozyKong");
sleepyKong.setname("SleepyKong");
}
public int countBananas(int k)
{
if(k==1) return totalBananas1;
if(k==2) return totalBananas2;
return totalBananas3;
}
public Monkey get_player(int k)
{
if(k==1) return greedyKong;
if(k==2) return dozyKong;
return sleepyKong;
}
public void play()
{
takeTurn(greedyKong,1);
takeTurn(dozyKong,2);
takeTurn(sleepyKong,3);
}



public boolean takeTurn(Monkey monkey,int k)
{
System.out.println("It's your turn:" + monkey);
System.out.print ("Hit return to roll.");
die.roll();
System.out.print ("You rolled a " + die.getTopFace());
System.out.println();
switch (die.getTopFace())
{
case 1:
{
System.out.println("1");
lastRoll = die.getTopFace();
}
break;
case 2:
{
System.out.println("2");
lastRoll = die.getTopFace();
}
break;
case 3:
{
System.out.println("3");
lastRoll = die.getTopFace();
}
break;
case 4:
{
System.out.println("4");
lastRoll = die.getTopFace();
}
break;
case 5:
{
System.out.println("5");
lastRoll = die.getTopFace();
}
break;
default:
{
System.out.println ("6");
lastRoll = die.getTopFace();
}
}
switch(k)
{
case 1:totalBananas1+=lastRoll;break;
case 2:totalBananas2+=lastRoll;break;
case 3:totalBananas3+=lastRoll;break;
}
return true;
}


public static void main(String[] args)
{
System.out.println ("Welcome to Monkeys and Bananas!");
MonkeysAndBananas game = new MonkeysAndBananas();
for(int i=0; i<10; i++)
game.play();
int max = game.countBananas(1);
int index = 1;
for(int i=2; i<4; i++)
{
if (game.countBananas(i)>max)
{
max = game.countBananas(i);
index = i;
}
}
System.out.println("Total bananas collected is:  " + game.countBananas(index) + " winner is " + game.get_player(index));
}
}

Explanation / Answer

/* SAMPLE OUTPUT
Welcome to Monkeys and Bananas!
It's your turn:GreedyKong
Hit return to roll.You rolled a 3
3
It's your turn:DozyKong
Hit return to roll.You rolled a 3
3
It's your turn:SleepyKong
Hit return to roll.You rolled a 1
1
It's your turn:GreedyKong
Hit return to roll.You rolled a 1
1
It's your turn:DozyKong
Hit return to roll.You rolled a 3
3
It's your turn:SleepyKong
Hit return to roll.You rolled a 6
6
It's your turn:GreedyKong
Hit return to roll.You rolled a 4
4
It's your turn:DozyKong
Hit return to roll.You rolled a 3
3
It's your turn:SleepyKong
Hit return to roll.You rolled a 5
5
It's your turn:GreedyKong
Hit return to roll.You rolled a 6
6
It's your turn:DozyKong
Hit return to roll.You rolled a 6
6
It's your turn:SleepyKong
Hit return to roll.You rolled a 3
3
It's your turn:GreedyKong
Hit return to roll.You rolled a 6
6
It's your turn:DozyKong
Hit return to roll.You rolled a 3
3
It's your turn:SleepyKong
Hit return to roll.You rolled a 6
6
It's your turn:GreedyKong
Hit return to roll.You rolled a 2
2
It's your turn:DozyKong
Hit return to roll.You rolled a 6
6
It's your turn:SleepyKong
Hit return to roll.You rolled a 4
4
It's your turn:GreedyKong
Hit return to roll.You rolled a 1
1
It's your turn:DozyKong
Hit return to roll.You rolled a 3
3
It's your turn:SleepyKong
Hit return to roll.You rolled a 2
2
It's your turn:GreedyKong
Hit return to roll.You rolled a 1
1
It's your turn:DozyKong
Hit return to roll.You rolled a 5
5
It's your turn:SleepyKong
Hit return to roll.You rolled a 3
3
It's your turn:GreedyKong
Hit return to roll.You rolled a 2
2
It's your turn:DozyKong
Hit return to roll.You rolled a 6
6
It's your turn:SleepyKong
Hit return to roll.You rolled a 3
3
It's your turn:GreedyKong
Hit return to roll.You rolled a 4
4
It's your turn:DozyKong
Hit return to roll.You rolled a 5
5
It's your turn:SleepyKong
Hit return to roll.You rolled a 6
6
winner is DozyKong
DozyKong age is 3
DozyKong size is 4.5
DozyKong Loves bananas or not ? No
Total bananas owned by DozyKong is: 43
Overall bananas owned by DozyKong is: 112
won bananas from other monkeys is 69
*/

import java.util.Scanner;
import java.io.*;
import java.lang.String;

class Die
{
private int roll_no;
public Die()
{
roll_no = 0;
}
public void roll()
{
roll_no = (int)(Math.random() * 6) + 1;
}
public int getTopFace()
{
return roll_no;
}
}

class Monkey
{
private String name;
private int age;
private float size;
private boolean loveBananas;
public Monkey()
{
name = "";
}
public void setname(String name)
{
this.name = name;
}
public String toString()
{
return name;
}
public void setAge( int newAge)
{
age = newAge;
}
public int getAge()
{
return age;
}
public void setSize(float newSize)
{
size = newSize;
}
public float getSize()
{
return size;
}
public boolean loveBananas()
{
if (loveBananas)
{
return true ;
}
else
{
loveBananas = false;
return false;
}
}
}

public class MonkeysAndBananas
{
private Monkey greedyKong, dozyKong, sleepyKong;
private int lastRoll;
private int totalBananas1,totalBananas2,totalBananas3;
private Die die;
public MonkeysAndBananas()
{
die = new Die();
this.lastRoll = 0;
this.totalBananas1 = 0;
this.totalBananas2 = 0;
this.totalBananas3 = 0;
greedyKong = new Monkey();
dozyKong = new Monkey();
sleepyKong = new Monkey();
sleepyKong.setAge (1);
greedyKong.setAge(2);
dozyKong.setAge(3);
sleepyKong.setSize(2.5f);
greedyKong.setSize(3.5f);
dozyKong.setSize(4.5f);
greedyKong.setname("GreedyKong");
dozyKong.setname("DozyKong");
sleepyKong.setname("SleepyKong");
}
public int countBananas(int k)
{
if(k==1) return totalBananas1;
if(k==2) return totalBananas2;
return totalBananas3;
}
public Monkey get_player(int k)
{
if(k==1) return greedyKong;
if(k==2) return dozyKong;
return sleepyKong;
}
public void play()
{
takeTurn(greedyKong,1);
takeTurn(dozyKong,2);
takeTurn(sleepyKong,3);
}
public boolean takeTurn(Monkey monkey,int k)
{
System.out.println("It's your turn:" + monkey);
System.out.print ("Hit return to roll.");
die.roll();
System.out.print ("You rolled a " + die.getTopFace());
System.out.println();
switch (die.getTopFace())
{
case 1:
{
System.out.println("1");
lastRoll = die.getTopFace();
}
break;
case 2:
{
System.out.println("2");
lastRoll = die.getTopFace();
}
break;
case 3:
{
System.out.println("3");
lastRoll = die.getTopFace();
}
break;
case 4:
{
System.out.println("4");
lastRoll = die.getTopFace();
}
break;
case 5:
{
System.out.println("5");
lastRoll = die.getTopFace();
}
break;
default:
{
System.out.println ("6");
lastRoll = die.getTopFace();
}
}
switch(k)
{
case 1:totalBananas1+=lastRoll;break;
case 2:totalBananas2+=lastRoll;break;
case 3:totalBananas3+=lastRoll;break;
}
return true;
}


public static void main(String[] args)
{
System.out.println ("Welcome to Monkeys and Bananas!");
MonkeysAndBananas game = new MonkeysAndBananas();
for(int i=0; i<10; i++)
game.play();
int max = game.countBananas(1);
int sum = game.countBananas(1);
int index = 1;
for(int i=2; i<4; i++)
{
    sum = sum + game.countBananas(i);
if (game.countBananas(i)>max)
{
max = game.countBananas(i);
index = i;
}
}
System.out.println("winner is " + game.get_player(index));
System.out.println(game.get_player(index) + " age is " + game.get_player(index).getAge());
System.out.println(game.get_player(index) + " size is " + game.get_player(index).getSize());
System.out.println(game.get_player(index) + " Loves bananas or not ? " + (game.get_player(index).loveBananas()?"Yes":"No"));
System.out.println("Total bananas owned by "+ game.get_player(index) + " is: " + game.countBananas(index));
System.out.println("Overall bananas owned by "+ game.get_player(index) + " is: " + sum + " won bananas from other monkeys is " + (sum-game.countBananas(index)));


}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote