Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Ministry of Vybsie_Culcha intends to implement a grant for singers in order to offset difficulties experienced from the pandemic. The grant is to be

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

The Ministry of Vybsie_Culcha intends to implement a grant for singers in order to offset difficulties experienced from the pandemic. The grant is to be funded from a fixed pool of funds (so the first set of singers that exhaust the funds are the only ones that are able to receive the grant). You are contracted to write a program that models the expected payouts. In order to reduce the possibility of fraud however, the ministry has decided to implement a controversial) strategy that requires entertainers to prove they are the song owners by recording it at a Studio, even if already released. The Ministry maintains a list of Studios, and code for the Ministry and Studio classes have already been fully implemented. The starting code also includes calls to a template of a Singer class that interacts with a Song class. Your task is to execute six(6) tasks that complete the Singer and Song classes. MARKING CRITERIA (PLEASE REVIEW BEFORE STARTING) Code passes all test cases, good programming style (5 marks) Accessors and mutators for Singer and Song (1 mark) Explanation of the importance of the toString method (1 mark) Correct implementation of logic to sum song values (1 mark) Explanation of your logic for tryToRegisterSong() (2 marks) Note that where convenient, you may declare private (support) methods. LAB EXERCISES 1. Complete constructors for the Singer class: a. Complete the first constructor that accepts name, genre, budget, as well as a reference to the Ministry. b. Complete the second constructor so that all instance variables are initialized. 2. Write code for the class Song to include: a. A constructor that accepts the song title, genre, singer and studio that relate to the song then sets instance variables b. A method to evaluate estimated earnings. Note that while in the real world, other methods would be used to estimate earnings, in this simplified model, the estimated earnings will be the length of the title, multiplied by the a value extracted by the ministry using the method getSongPartEst(hint.. the singer keeps a reference to the ministry). C. A toString() method that returns a string with data formatted as illustrated below if the song is a best seller: **Title, Genre, but the format : Title, Genre if the song is not a best seller. Note that a song is a best seller if the expected earnings exceed a value that is extracted from the ministry using the method getBestseller Limit 3. Complete the method in Singer named tryToRegisterSong: so that it executes the following logic... If the singer has a favourite studio that is available and within budget, use the favourite studio to record the song. Otherwise get the best available studio from the ministry within the singer's budget (simply call ministry.getBestAvailStudio(budget) for that). If the singer is successful in selecting a studio, proceed with registering the song by reserving the studio and reducing budget by the cost of the studio. The singer should also add the song to a list of songs. To keep information on a song, remember that the singer needs to note the title, the genre, as well as the studio. Of course, it is also important for each singer to note him/herself as the singer on the song. Input Format The first line contains integers t, f, m, v and b, where t is the number of test cases, f is the value of available funds, m is the minimum grant request to be entertained, v is the value of each character in calculating song value, and b is the lower limit(-1) for a song to be regarded a best seller. t test cases follow. Each test case begins with the name of a singer, a genre, a budget, and, optionally a favourite studio. The next line contains an integer s that indicates the number of songs the singer will attempt. s lines follow. Each of the s lines contain a string that represents the name of a song. Output Format as defined Sample Input o 1 10000000 100000 20000 500000 Iron_Balloon Waan_Buss 50000 Sample Output o ===APPLICATIONS NOT GRANTED==================== IRON_BALLOON: : Request for $0 declined: minimum intellectual property for grants is $100,000 Sample Input 1 1 1 10000000 100000 20000 500000 Iron_Balloon Waan_Buss 50000 1 0 Sample Output 1 ===APPLICATIONS NOT GRANTED=== IRON_BALLOON[Studio One] :: Request for $0 declined: minimum intellectual property for grants is $10,000,000 Sample Input 2 1 10000000 100000 10000 500000 One_hit_wonder Waan_Buss 50000 1 Mary_had_a_little_lamb Sample Output 2 =======GRANTS AWARDED=== ONE_HIT_WONDER::GRANTED $220,000 SONGS SUPPORTED Mary_had_a_little_lamb, Waan_Buss, [$10,000] Sample Input 3 1 10000000 100000 20000 500000 Shen_Yengz Dancehall 100000 2 1 Youre_the_one_I_love_so_I_will_run_run_run Sample Output 3 ====GRANTS AWARDED== SHEN_YENGZ[Rich Entertainment] :: GRANTED $840,000 SONGS SUPPORTED **Youre_the_one_I_love_so_I_will_run_run_run, Dancehall, [$40,000] Sample Input 4 2 10000000 100000 20000 500000 Iron_Balloon Waan_Buss 50000 1 1 Wha? Shen_Yengz Dancehall 100000 2 2 Youre_the_one_I_love_so_I_will_run_run_run Lighter Sample Output 4 ====GRANTS AWARDED========= SHEN_YENGZ[Rich Entertainment] :: GRANTED $980,000 SONGS SUPPORTED Sample Output 4 =====GRANTS AWARDED== SHEN_YENGZ[Rich Entertainment]::GRANTED $980,000 SONGS SUPPORTED **Youre_the_one_I_love_so_I_will_run_run_run, Dancehall, [$40,000] Lighter, Dancehall, [$40,000] ======APPLICATIONS NOT GRANTED==== IRON_BALLOON [Studio One] : : Request for $80,000 declined:minimum intellectual property for grants is $100,000 Sample Input 5 1 50000000 100000 20000 500000 Agent_Sasco Dancehall 140000 3 5 Banks_of_the_Hope Winning_right_now Mama_Prayed Sasco_vs_Assassin Loco Sample Output 5 ==========GRANTS AWARDED======================== AGENT_SASCO[Eight76 Music]:: GRANTED $1,320,000 SONGS SUPPORTED Banks_of_the_Hope, Dancehall,[$80,000] Winning_right_now, Dancehall, [$10,000] Mama_Prayed, Dancehall,[$10,000] Sasco_vs_Assassin, Dancehall,[$10,000] Loco, Dancehall, [$10,000] Sample Input 6 7 5000000 200000 20000 500000 Iron_Balloon Waan_Buss 25000 O 3 Wha? Yow! Far_In_Wi_Seh! Shen_Yengz Dancehall 100000 2 2 Youre_the_one_I_love_so_I_will_run_run_run Lighter Agent Sasco Dancehall 140000 3 5 Banks_of_the_Hope Winning_right_now Mama_Prayed Sasco_vs_Assassin Loco Adele Soul 400000 2 Go_easy_on_me Water_under_the_bridge_when_we_were_young Tessanne_Chin Rock 400000 2 Messenger One_Step_closer Tracy_Chapman Blues 400000 3 All_that_you_have Fast_Car Subcity Poppy Dancehall 500000 3 1 Unrulyrulyrulyrulyrulyrulyrulyrulyrulyrulyrulyrulyruly!!!! Sample Output 6 =====GRANTS AWARDED=: SHEN_YENGZ[Rich Entertainment] :: GRANTED $980,000 SONGS SUPPORTED **Youre_the_one_I_love_so_I_will_run_run_run, Dancehall, [$40,000] Lighter, Dancehall, [$40,000] AGENT_SASCO[Eight76 Music]::GRANTED $1,320,000 SONGS SUPPORTED Banks of the Hone. Dancehall 1680.0001 Sample Output 6 ========GRANTS AWARDED====== EEEEEEEEEE SHEN_YENGZ[Rich Entertainment] :: GRANTED $980,000 SONGS SUPPORTED **Youre_the_one_I_love_so_I_will_run_run_run, Dancehall, [$40,000] Lighter, Dancehall, [$40,000] AGENT_SASCO[Eight76 Music]:: GRANTED $1,320,000 SONGS SUPPORTED Banks_of_the_Hope, Dancehall, [$80,000] Winning_right_now, Dancehall, ($10,000] Mama_Prayed, Dancehall, ($10,000] Sasco_vs_Assassin, Dancehall, ($20,000] Loco, Dancehall, [$20,000] ADELE::GRANTED $1,080,000 SONGS SUPPORTED Go_easy_on_me, Soul, [$20,000] **Water_under_the_bridge_when_we_were_young, Soul, [$20,000] TESSANNE_CHIN::GRANTED $480,000 SONGS SUPPORTED Messenger, Rock, [$40,000] One_Step_Closer, Rock, [$40,000] TRACY_CHAPMAN::GRANTED $640,000 SONGS SUPPORTED All_that_you_have, Blues, [$80,000] Fast_Car, Blues, [$80,000] Subcity, Blues, [$80,000] ====APPLICATIONS NOT GRANTED==================== IRON_BALLOON[Ruff Gong] :: Request for $160,000 declined: minimum intellectual property for grants is $200,000 POPPY[Eight76 Music]:: Request for $1,160,000 declined: Insufficient funds in grant pool Java 8 8 1, import java.util.ArrayList; 2 import java.io.*; 3 4 5, class Song { 6 7 private String title, genre; Singer singer; 9 Studio studio; 10 11 public Song (String title, String genre, Singer singer, Studio studio) 12 { 13 this.studio = studio; 14 } 15 16 public int getEstEarnings () { 17 18 return 0; 19 } 20 21 22 private boolean is Bestseller() { 23 //Can use this to help complete toString 24 return getEstEarnings () >singer.getMinistry().getBestselllimit(); 25 } 26 27 28 } 29 30 31 class Singer { 32 33 private String name="", , genre; 34 private int budget; 35 private Studio favStudio; 36 private ArrayList songs = new ArrayList(); 37 private Ministry ministry; 38 private int grantValue; 64 30 31. class Singer { 32 33 private String name="", genre; 34 private int budget; 35 private Studio favStudio; 36 private ArrayList songs = new ArrayList(); 37 private Ministry ministry; 38 private int grantValue; 39 private String grantMessage; 40 41 public Singer(String n, String g, int b, Ministry min ) { 42 ministry= min; 43 } 44 45 public Singer (String name, String genre, int budget, int fav, Ministry ministry ) { 46 // Complete this constructor case 2 47 this.ministry= ministry; 48 this.favStudio= ministry.getStudio(fav); 49 } 50 51 public Ministry getMinistry() { 52 return ministry; 53 } 54 55 boolean studioExists(Studio favStudio) 56 { 57 return (favStudio!=null); 58 } 59 60 boolean canAfford (Studio studio) 61 { 62 return studio.getCost() 0) 98 { 99 str+="::GRANTED $"+String.format("%d", grantValue)+" "; 00 str+="SONGS SUPPORTED "; 01 for(int i=0; i= recordTime; 142 } 143 144 public void reserve() 145 { 146 freetime -=recordTime; 147 } 148 149 public int getCost() { 150 151 return cost; 152 } 153 } 154 155 //package lab2; 156 157 class Ministry { 158 private Studio[] studios; 159 private int grantPool; 160 private int minGrantval; 161 private int songPartEst, bestsellLimit; 162 private ArrayList singers = new ArrayList(); 163 164 165 public Ministry(int grantPool, int minGrant Val, int songPartEst, int bestselllim { 166 studios = new Studio[5]; 167 studios[0]= new Studio ("Ruff Gong", 12, 10000, 3); 168 studios[1]= new Studio ("Studio One", 12, 20000, 3); 169 studios [2] = new Studio ("Rich Entertainment", 12, 40000, 3); 170 studios[3] = new Studio ("Eight76 Music", 12, 80000,3); 171 studios[4]= new Studio ("Juss Buss", 12, 160000, 3); 172 173 this.minGrantVal = minGrantval; 174 this.grantPool=grant Pool; 175 this.bestsellLimit = bestsellLimit; 176 this.songPartEst=songPartEst; 177 } 178 179 public Studio getStudio(int id) { 180 return studios[id]; 181 } 182 183 public int getSongPartEst() { 184 return songPartEst; 185 } 186 public int getBestsellLimit() { 187 return bestsellLimit; 188 } 189 190 191 public String processGrant (Singer singer) { 192 int grantval=0; 193 String grantMsg; 194 int singval = singer.getTotalEarnings(); 195 singers.add(singer); 196 if (singval grant Pool) 201 grantMsg ="Request for $"+String.format("%d", singval)+" declined: Insufficient funds in grant pool"; else { 203 grantVal = singval; 204 grantMsg = "$"+String.format("%d", grantVal) +" granted to 202 ZUZ else 1 203 grantVal = singval; 204 grantMsg = "$"+String.format("%d", grantVal) +" granted to "+singer.getName(); 205 grantPool -=grantval; 206 } 207 } 208 return grantVal+";"+grantMsg; 209 } 210 211 public void showAwarded (boolean awarded) { 212 singers.forEach((singer)->{ 213 if((singer.getGrantValue() >0) ==awarded) 214 System.out.println(singer);}); 215 1//for(int i=0; i0) == awarded) 217 // System.out.println(singers.get(i)); 218 219 } 220 221 public int count Singers() { 222 return singers.size(); 223 } 224 public Studio getBestAvailStudio(int budget) 225 { 226 //studio already stored in sorted order of cost... no need to sort 227 boolean found = false; 228 Studio retStudio=null; 229 int foundDx =-1; 230 231 for (int dx=0; ((dx=studios[dx].getCost()); 240 if (found) 241 { 242 foundDx=dx; 243 retStudio = studios [dx]; 244 245 } 246 247 248 } 249 250 } 251 252 return retStudio; 253 254 } 255 256 257 } 258 259, public class Driver{ 260 261 public static void main(String[] args) throws IOException { 262 int numGrants=0; 263 BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); 264 String[] preMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" "); 265 int t = Integer.parseInt(preMultipleInput[0]); 266 267 int grantPool = Integer.parseInt(preMultipleInput[1]); 268 int minGrantVal= Integer.parseInt(preMultipleInput[2]); 269 int songPartEst= Integer.parseInt(preMultipleInput[3]); 270 int bestselllimit= Integer.parseInt(preMultipleInput[4]); 271 Ministry min = new Ministry(grant Pool,minGrantVal, songPartEst, bestsellLimit); 272 for (int test =0; test0?1:0); 294 } catch (IOException ex) { 295 throw new RuntimeException(ex); 296 } 297 298 299 bufferedReader.close(); 300 if (numGrants>0) 301 { 302 System.out.println("= ==GRANTS AWARDED== ======"); 303 min.showAwarded(true); 304 } 305 if (numGrants

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

How can you influence the powers that be to make changes?

Answered: 1 week ago