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

Semester Programming Project This program should illustrate and simulate the eth

ID: 3859517 • Letter: S

Question

Semester Programming Project

This program should illustrate and simulate the ethical issue of the tragedy of the commons. In essence, it is a software toy that permits users to examine the balance between choices that benefit the individual but cost society versus those that benefit society at a cost to the individual.

The program can be written in either Java or C. Students have broad discretion with regards to implementation.

Quick overview.

Please consider creating an array (or linked list) of objects. Each object might have an integer ID, a Boolean switch (selfish or not-selfish), and a happiness score (integer). Then use the object in part A. Finally, implement part B representing the society.

Part A.

The first part of the program will create a series of individuals (objects) who make decision that are either selfish or altruistic. Each object will make its decisions independently. Some objects may choose to always be selfish. Others will always be altruistic. And some might be random. Each object will have an identity (an integer is sufficient), and can generate its choice. Each object will also have a score for happiness, which can change.

The program should be able to create from 1 to 20 (or more, if you prefer) individuals according to the user’s preference.

The program should be able to run multiple iterations (each with the same individuals), and be capable of up to 20 (or more, if you prefer) iterations, with output for each iteration.

When an individual is selfish, they gain 5 happiness points. When they are altruistic, they lose 2 happiness points.

When Part B is done, the government score will be added to the functionality of Part A.

Part B.

The second part will incorporate an entity called “government”, which will represent the aggregate effects of individual decisions by the individual objects.

If all individuals choose to be altruistic, society will benefit, but all of the individuals will be poor. If all individuals choose to be selfish, the individuals may do well, but society will be miserable. And if some number of individuals are altruistic and others are selfish, a balance might be achieved. The balance could be optimized, providing results for the number of objects with various characteristics.

If there are more selfish individuals than altruistic individuals, the government score is a negative number equal to the net number of selfish individuals (selfish – altruistic).

If there are an equal number of selfish and altruistic individuals, the government score is a zero.

If there are more altruistic individuals than selfish individuals, the government score is a positive number equal to the net number of altruistic individuals. (Altruistic – selfish).

These results are added to the individual happiness scores specified in Part A.

So if an individual is selfish, they would add 5 happiness points. If there are then 15 selfish people and 5 altruistic people, the government would subtract 10 points from each individual. Thus the selfish person would end up with -5 points. The altruistic person would end up with a -12 points for that round!

In contrast, suppose all 20 are altruistic. The government would add 20 points, the individuals would have negative scores as individuals, but the aggregate result is that each would add 18 points to their happiness score.

Punishment

The government can punish excessive selfishness. If an individual is selfish AND the government score is positive (more altruists than selfish), there is a 10% chance that a selfish individual will receive a punishment – in this case, a penalty of 50 points. Think of it as time in jail.

If an individual is selfish and the government score is negative (more selfish than altruists), there is a 50% chance that a selfish individual will receive a punishment – in this case, a penalty of 75 points. In other words, a long time in jail.

Note: These numbers are purely arbitrary. Feel free to experiment with other numbers!

Hello This is what I have I only need a main class to tie everything together.

package sample;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;
import java.util.Scanner;

class individuals
{
   private int ID;
   private boolean switchValue; // false then altruists else it will selfish
   private int happiness_Score;
   public individuals(int iD, boolean switchValue, int happiness_Score) {
       super();
       ID = iD;
       this.switchValue = switchValue;
       this.happiness_Score = happiness_Score;
   }
   public int getID() {
       return ID;
   }
   public void setID(int iD) {
       ID = iD;
   }
   public boolean isSwitchValue() {
       return switchValue;
   }
   public void setSwitchValue(boolean switchValue) {
       this.switchValue = switchValue;
   }
   public int getHappiness_Score() {
       return happiness_Score;
   }
   public void setHappiness_Score(int happiness_Score) {
       this.happiness_Score = happiness_Score;
   }
  
  
}

public class Programming {
   private ArrayList<individuals> li = new ArrayList<individuals>();
   private static int idValue=1;
   Scanner sc = new Scanner(System.in);
   private void createObjects()
   {
       int iteration = sc.nextInt();
      
       for(int i=0;i<iteration;i++)
       {
           Random rand = new Random();

           int n = rand.nextInt(1);
           if(n==0)
           {
               individuals e = new individuals(idValue,false,0);
               li.add(e);
           }
           else
           {
               individuals e = new individuals(idValue, true, 0);
               li.add(e);
           }
           idValue++;
       }
      
   }
  
   private void iteration()
   {
       for(int i=0;i<20;i++)
       {
           Random rand = new Random();

           int sValue = rand.nextInt(1);
           int person = rand.nextInt(20) + 1;
           if(sValue==0)
           {
               for(individuals d : li)
               {
           if(d.getID() == person )
           {
               d.setHappiness_Score(d.getHappiness_Score() - 2);
               break;
           }
           }

           }
           else
           {
               for(individuals d : li)
               {
           if(d.getID() == person )
           {
               d.setHappiness_Score(d.getHappiness_Score() + 5);
               break;
           }
           }
           }
       }
   }
   private int incorporate()
   {
       int selfish = 0;
       int altruistic = 0;
       for(individuals d : li)
       {
   if(d.isSwitchValue() == true )
   {
       selfish++;
   }
   else
       altruistic++;
   }
       int govtScore = altruistic - selfish;
      
       return govtScore;
   }
  
   public static void main(String []args)
   {
       Programming pObj = new Programming();
       int governmentScore = pObj.incorporate();
      
       pObj.createObjects();
       pObj.iteration();
      
       for(int i=0;i<pObj.li.size();i++)
       {
           if(governmentScore > 0 && pObj.li.get(i).isSwitchValue() == true) // If an individual is selfish AND the government score is positive (more altruists than selfish)
           {
               System.out.println("10% chance of receiving punishment and penalty is 50 points.");
              
           }
           else if(pObj.li.get(i).isSwitchValue() == true && governmentScore < 0)
           {
               System.out.println("50% chance of receiving punishment and penalty is 75 points.");
           }
           else
           {
               System.out.println("Long term jail for you.");
           }
       }
      
   }

}

//output:

Outline Ta Programming.java 38 39 o setlD (int isSwitch o setSwit o getHapp o setHapp Programmin a i:Array a dValue SC : Scar create iteration E incorpo main(St 41 public class Programming i 42 43 private ArrayList

Explanation / Answer

package sample;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;
import java.util.Scanner;

class individuals
{
   private int ID;
   private boolean switchValue; // false then altruists else it will selfish
   private int happiness_Score;
   public individuals(int iD, boolean switchValue, int happiness_Score) {
       super();
       ID = iD;
       this.switchValue = switchValue;
       this.happiness_Score = happiness_Score;
   }
   public int getID() {
       return ID;
   }
   public void setID(int iD) {
       ID = iD;
   }
   public boolean isSwitchValue() {
       return switchValue;
   }
   public void setSwitchValue(boolean switchValue) {
       this.switchValue = switchValue;
   }
   public int getHappiness_Score() {
       return happiness_Score;
   }
   public void setHappiness_Score(int happiness_Score) {
       this.happiness_Score = happiness_Score;
   }
  
  
}

public class Programming {
   private ArrayList<individuals> li = new ArrayList<individuals>();
   private static int idValue=1;
   Scanner sc = new Scanner(System.in);
   private void createObjects()
   {
       int iteration = sc.nextInt();
      
       for(int i=0;i<iteration;i++)
       {
           Random rand = new Random();

           int n = rand.nextInt(1);
           if(n==0)
           {
               individuals e = new individuals(idValue,false,0);
               li.add(e);
           }
           else
           {
               individuals e = new individuals(idValue, true, 0);
               li.add(e);
           }
           idValue++;
       }
      
   }
  
   private void iteration()
   {
       for(int i=0;i<20;i++)
       {
           Random rand = new Random();

           int sValue = rand.nextInt(1);
           int person = rand.nextInt(20) + 1;
           if(sValue==0)
           {
               for(individuals d : li)
               {
           if(d.getID() == person )
           {
               d.setHappiness_Score(d.getHappiness_Score() - 2);
               break;
           }
           }

           }
           else
           {
               for(individuals d : li)
               {
           if(d.getID() == person )
           {
               d.setHappiness_Score(d.getHappiness_Score() + 5);
               break;
           }
           }
           }
       }
   }
   private int incorporate()
   {
       int selfish = 0;
       int altruistic = 0;
       for(individuals d : li)
       {
   if(d.isSwitchValue() == true )
   {
       selfish++;
   }
   else
       altruistic++;
   }
       int govtScore = altruistic - selfish;
      
       return govtScore;
   }
  
   public static void main(String []args)
   {
       Programming pObj = new Programming();
       int governmentScore = pObj.incorporate();
      
       pObj.createObjects();
       pObj.iteration();
      
       for(int i=0;i<pObj.li.size();i++)
       {
           if(governmentScore > 0 && pObj.li.get(i).isSwitchValue() == true) // If an individual is selfish AND the government score is positive (more altruists than selfish)
           {
               System.out.println("10% chance of receiving punishment and penalty is 50 points.");
              
           }
           else if(pObj.li.get(i).isSwitchValue() == true && governmentScore < 0)
           {
               System.out.println("50% chance of receiving punishment and penalty is 75 points.");
           }
           else
           {
               System.out.println("Long term jail for you.");
           }
       }
      
   }

}

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