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

I would like answers to be submitted via e-mail. I am aware of the scope of thes

ID: 3555753 • Letter: I

Question

I would like answers to be submitted via e-mail.

I am aware of the scope of these coding tasks. As a result, I will attempt to reward the person that answers correctly with an additional 1,500 points. I hope that our interaction goes as follows:

1- You e-mail me at laschoolproject@gmail.com with your solution.

2- I award you 1500 points here for supplying me with a satisfactory solution.

3- I create a second question, also worth 1500 points, which you simply reply to so that I may award you those extra 1500 points.

-----First Task-----

Slot machine rules:

Explanation / Answer


public class SlotMachine {

   private int timesPlayed;
   private int timesPlayedToWin;
   private int quartersPaid;
  
   private static int totalTimesPlayed = 0;
  
   public SlotMachine (int timesPlayed, int timesPlayedToWin, int quartersPaid) {
       this.timesPlayed = timesPlayed;
       this.timesPlayedToWin = timesPlayedToWin;
       this.quartersPaid = quartersPaid;
   }
  
   // This method returns quarter amount after playing the slot
   public int playSlotYield(int quarterJar) {
      
       // When there are no quarters
       if (quarterJar == 0){
           return 0;
       }
      
       // Increment times played and take away a quarter
       this.timesPlayed++;
       totalTimesPlayed++;
       quarterJar--;
      
       // Pay out and reset times played
       if (this.timesPlayed == this.timesPlayedToWin) {
           quarterJar += this.quartersPaid;
           this.setTimesPlayed(0);
           return quarterJar;
       } else {
           // Returns a jar amount with a quarter less
           return quarterJar;
       }
      
   }
  
   public static int getTotalTimesPlayed() {
       return totalTimesPlayed;
   }

   public int getTimesPlayed() {
       return timesPlayed;
   }

   public void setTimesPlayed(int timesPlayed) {
       this.timesPlayed = timesPlayed;
   }

   public int getTimesPlayedToWin() {
       return timesPlayedToWin;
   }

   public void setTimesPlayedToWin(int timesPlayedToWin) {
       this.timesPlayedToWin = timesPlayedToWin;
   }

   public int getQuartersPaid() {
       return quartersPaid;
   }

   public void setQuartersPaid(int quartersPaid) {
       this.quartersPaid = quartersPaid;
   }
  
   public String toString() {
       String result;
       result = "Times Played: " + this.timesPlayed + " Times to Win: " + this.timesPlayedToWin + " Payout: " + this.quartersPaid;
       return result;
   }
  
}

public class margeriesQuarters {

   public static void main(String[] args) {
      
       SlotMachine[] Slots = new SlotMachine[3];
       Slots[0] = new SlotMachine(0, 35, 30);
       Slots[1] = new SlotMachine(0,100, 60);
       Slots[2] = new SlotMachine(0, 10, 11);
      
       int quarterJar = 0;
      
       //Read in input
       Scanner scanner = new Scanner(System.in);
       System.out.print("How many quarters does Marge have in the jar?");
       quarterJar = scanner.nextInt();
       System.out.print("How many times has the first machine been played since paying out?");
       Slots[0].setTimesPlayed(scanner.nextInt());
       System.out.print("How many times has the second machine been played since paying out?");
       Slots[1].setTimesPlayed(scanner.nextInt());
       System.out.print("How many times has the third machine been played since paying out?");
       Slots[2].setTimesPlayed(scanner.nextInt());
      
       //Loop through the slots
       while (quarterJar > 0) {
           quarterJar = Slots[0].playSlotYield(quarterJar);
           quarterJar = Slots[1].playSlotYield(quarterJar);
           quarterJar = Slots[2].playSlotYield(quarterJar);
       }
      
       System.out.println("Martha plays " + SlotMachine.getTotalTimesPlayed() + " times.");
      
       scanner.close();
      
  
      
   }

}