Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Im asking for assistance Thank you in advance Figure 1 depicts the classes to which you will interface while completing the exercise. 1. In class

Im asking for assistance Thank you in advance
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
image text in transcribed
image text in transcribed
image text in transcribed
Figure 1 depicts the classes to which you will interface while completing the exercise. 1. In class singer,: a. Complete the first constructor that accepts name, genre, budget, as well as a reference to the Ministry(incoming arguments include n for the name, for gence, and b for budget). b. Implement the second constructor so that all instance variables are initialized. 2. In class Song, write the caiculation in method getEstEarnings of class Song 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 getSonePartEst/hint. the singer kecps a reference to the ministry. You con observe how the reference is used in method getClaimobleEarnings). 3. In class Singer, correct the method sum EstEarnings to evaluate the sum of estimates eamings for the singer. 4. Record a song in a studio and try to register the song a. In class Song write a mutator named setstudio(5tudio studio) - method for the song that accepts a Studio, and sets the associated studio on the on the song to the referenced Studio. b. In class singer, method tryTokegistersang, if the singer has a preferred studio, set studio to the preferred studio (use method setstudio0), then add the song to the list of registered songs. 5. In class singer, method tryToRegisterSone, update logic to check if artist can afford studio before setting the studio on the song. 6. In class Singer, method tryToRegisterSone update logic to allow ministry to suggest a studio by calling the method getBestAvailableStudiolint budget, Studio preferred) from Ministry, which retums a suggested studio. If the method returns a studtio (returned value is not null) then set the studio for the song to the returned studio if the singer is able to afford it. You can then check if the song has been connected with a studio, and if it is, add the song to the list of registered songs. 7. In class Singer, method tryToRegisterSong, ensure singer's budget is reduced by the cost of the studio. 8. In class singer, method tryToRegistersong, call the studio's resenve method when adding a song to the list of registered songs. Also, check to see if a studio is available (using the isAvallablef method in the studio class) before assigning the song to the studio. mport java.util. Arraylist; mport java. io.t; Tass song \{ private string title, genre; Singer singer; private Studio studio; pubtic Song(String title, String genre, singer singer) (.) this.studio=nutl;this.genre=genre;this.singer=singer;this.title=title; 3 public int getestEarnings () ( return (int) (title. Length() Esinger.getkinistry() getsongpartest()) i//Q2. Perform this \} public int getclaimabletarnings O i int est = getestEarnings () ; if cest > singer-getMinistry() - getMinclaisable()) return est; else. return : public String gettitle() t return title; (. Q4. you wil inplement setstudio sopewhere around here of public void setstudio (studio studio) S this.studio = studioi y public studjo getstudjo() return studio; private bootean isbestsoller() \& return getestearnings())singer- getkinistry(), getbestselteimit(); return getestEarnings () ssinger.getkinistry (),getBestSelttinit(); public boolean hasstudio() ( return ( ( (studio==null )); public string tostring( ) ( String outval ="Released "; if (isbestseller()) outval+="kk"; int cost =0; if (i(studio=nult)) cost= studio.getcost ( ) ; outvalt=title" as a "+genre + " single to earn s"+string. fornat ("\%, d", getEstEarnings())+"."; return outval; i) F3 folais singer 1 private string name="', , genre; private int budget; private Studio favstudio; private Arraylistn, String g, int b, Mintstry min, booleen waot papply R o 1/ question 20 songs: new Arraytiste Songl () ; registeredsongs new Arrayliste Song? 17Q13. Add code to coaplete this constructori / name =n: zenres gi budget: b: ministry mine granthessage ="n; this favstudio nutl: witlappty = want oonpply; pubtic Singer(string name, String benre, sht budget, int fav, Winistry ointatry, boolean witapply, ( (this. fisstudto- ministry. sotstudrofav): raib. Add code to conplete this constructor-/ Horis. name nanef thit gonre gonre; thys. budsat budgot: thisimistry ministry; Brantressoge = iliti thisifarstudionuli: public Ministry getMinistry() ( ) return ministry; public boolean applying () f ) return willapply; public boolean studioExists(Studio favstudio) f. return (fovstudiol=nut1); 3 public boolean canAfford(Studio studio) f return studio.getcost () = oi for (Song regsongtregisteredsongs) sum+=regsong - getclaimabletarnings ( ) : return sum; public int suntstvatue() f int sus = o; F Code to iniplement Q3 here of for (Song rsong i songs) sumft rsong-getEstEarnings (0; return sum; public scring getNone() ( return name; () public void tryToRegister5ong(Song song) f if (favstudio:nuti) str = str. " No preferced studio."; else (s. str = str + "Prefers -vavstudio.getwano(): if (I favstudio. isavartable()) strt=" (Not available)." ; else. str += "(Available:cost [($+ String. format ("x1,dn, favstudio. getcost ())+" " ])."; 3 System. out.print ln(str); // /I/I/I/IN THIS METHOO, DO NOT MODIFY ABOVE THIS LINE ////////////////// I Aode for logic that can pass test cases 5,6 and 7 can go heref/ 3 public void addsong(String title) f songs. add (new Song(title, genre, this )); 3 public ArraylisteSong? getSongs() return song5; 3 public void applyforGrant() i for (Song songisongs) tryToRegistersong(song); String response = ministry.processGrant (this); String[] responseparts = response. sptit((;); grantvatue = Integer.parsoInt (responseparts [e]); grantkessage = responseParts [1]; 3 pubtic strting tostring( ) ( string strn" str = nane, touppercase () : if (studioExists (favstudio)) strt= ["+favstudio-getiane ()-"]?s If (grantvatuesi) f. etse return str: Lass Studio \& private String name; private int freetime; private int cost, recordTime; public Studio(String nate, int freetime, int cost, int recordTime) \{. this.name=nane;this.freetime=freetime;this,cost=cost;this.recordTime=recordTine; 3 public string getNane() return name; S) pubtic int getfreetine() t return freotiae; f public 8oolean is ivailable() f 3 return freetime s: recordtime; publc void resorve() C. freetime - =recordTine; 3 3 public sne getcost 0 ) return cost: 3 //packoge kab2; irclass Ministry 1 private studto[] studios; private int grantpool; private int mingrantval; private final int MINCLATMABE =0,//50009; private int songPartEst, bestsellilinit: private bookean suggeststudios: private Arraylistesingers singers; public Mimatry (Tint grantpool, the mingrantval, int songPartest, init bestsellitiait, boolean suggeststudios) if istudios oek studiols]: studiostele now studioc "Rutf Gong", 12,10000,3 ): return cost; ackage lab2 ss Rinistry il private Studio[] studios: private int grantpool; priyate int mingrantval; private final int MINCLAIMABLE =0;//50000; private int songpartest, bestselluimit; private boolean suggeststudios: private Arraylistesinger? singers; public Ministry (int grantpool, int mingrantVal, int songPartEst, int bestselulinit, boolean suggeststudios) ( studios new studio[5]; studios [0]= new Studio("Ruff Gong", 12,10000,3 ) ; studt os [1]= new Studto ("Studio one", 12,20000,3 ); studios [2]= new Studio ("gich Entertalnment", 12,60000,3)i studios [3]= new Studio ("E{ght76 Music", 12,80000,3); studtos [4]= new 5 tudto("Juss Buss", 12, 160000,3) ) this.mingeantval = mingrantval; this.grantPool=grantpooli this, bestsellitimit = bestsellimit; this. songPartest sopgartest ; this. suegeststudios a suggeststudios: singers = new Arraylistestager (); public studto getstudio (4nt id) I return studtos [id]) public int getsongpartest() i return honigpartist; public int getbestselltinit() t return bestselfitinit. public int getkinclainable () \& return MINCLAIMABLE; y. public String process6rant(singer singer) i int grantval=0; Stings grantMs = " "; int singuat = singer .suaregisteredsongs (); System,out pointin(" sprocessing request from " +singer. getName()+" for \$"+ +string. format ("\$, d", singval)); if (singyal? MINCLAIMABLE) Singers.add (singer); fif (singyal 3 mingrantval). grantMsg = "Request for $ +String. format(" grants/is s" +strang. format (ir, d", mingrantVal); else 1). if (oingval > grantpool) grantMsg ="Request for \( \$ "+5 t c i n g \)quot;+5tcing. forsat("s,d", singval)+" dectined:Insuffictent funds in grant pootlis else \{ grantval = singval; grantMsg = "sststring, foreot (",d", grantval) + granted to "+singer. get Name () ; grantpool - grantval; 7. ) returh grantval+"i" grantMsg; public void sbowAwarded(boolean awarded) f Singers. fortach ( (stager ) 1 if (( singer,getGrantvalue ()>0)= inarded ) system.out.print ta(singer) i)); //AROTHER WAY TO DO THIS IS .... 111. If ( (singers. get (4) , getGrantvalue ()>0)= awarded) (I) systea.out.println(singors.get (i)); publie int countsingers() i return singersisize( ), ] public studio getllestavaitstudio(tht budget, studio favstudio) ( I I studto atready stored ti sorted order of cost... no. need to sort booteon found ifatse: studio rotstudio:favstudio; Int found x o-1: if (cuggeststudios) 1 if (studios [dx], istavailable ()) f System,out, print ln(">>"+studios [dx] - getNase() +" is available for \( \$ "+5 t r i n g \)quot;+5tring, form studios [dx]getcost()+(N,"); found =( budget >= studios [dx]gctcost()); if (found) (i) foundbx=dx;retstudio=studios[dx]; f etse System. out.println(">>", studios [dx],getwane() " is not avallable,"); 1f (retstudio-nult) System.00t.println("s>No studio available for 5"+ String. format ("5,d, budget )+"."); etse System, out, println ("P>Assigned studio "+retstudio.gethane()*"."); return retstudio; Apublic class onver. public static vold main(5tring[] args) throws loException ( hint nugrants= ; BufferedReader bufferedResder = new BufferedReader(nem Inputstreangesder (5ystem, in)); int t = integer.porseint (prenultipleinput [] ); hint grantpool Integer.parseint (prenultipleinput [1]); int mingrantval= Integer. parseInt (prekultipleInput {2]); int songpartest- Integer. parseint (premultipleinput [3]): int bestselllinit= Integer.porseint (preMultipleinput [4]); String suggeststudios = pre4ultipleInput [5]; string showsusinary = prekultipleinput [6]; bootean nillsuggest = false; bootean summary = false; if (suggest studios.equals ("res")) whitsuggest= true; (showsumeary.equals ("-es")) sumarys truef Ministry min =new Ministry (grantpool, aingrantval, songpartist, Destselthieit, witlsoggest): blic static void main(String[] args) throws IOException f. int numbrants=0; BufferedReader bufferedReader = new BufferedReader (new Inputstreankeader (System, in)); int t= Integer, parselnt (preMultipleInput [] ); int grantPool = Integer.parseInt (prekultipleInput(1]); int ainGrantval= Integer.parseint (prekultipleInpot [2]); int songPartEst = Integer. parseint (preMultipleinput [3]); int bestselllimit = Integer. parseInt (preMultipleInput [4]); string suggeststudios: = preMultipleInput[s]i String showsunnary f prekult pleinput [6]; boolean wiltsuggest = false; boolean summary = false; if (suggeftstudios.equals ("res")) willsuggest = true; if (showsunmary. equals ("Vos")) Fumbar y= true; Ministry min = new Ministry (grantpool, mingrantval, songPartest, bestsellLimit, willsuggest); for (int test =0; test tt;test+t) (i) if if (sg-applying ()) ( 5g.applyforGrant() ; (1). nuagrants: =(5g+80tGrantvalue()>0:1:); I catch (Ioexception ex) ( throw new RuntimeException(ex); (3. bufferedieader.close(); if (numGrants>i) () min. Showawarded(true) i: if if (nuegrantscmin. countsingers () ) fi. inin. showawarded (fatse)

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

Recommended Textbook for

Database Processing Fundamentals Design

Authors: Marion Donnie Dutton Don F. Seaman

14th Edition Globel Edition

1292107634, 978-1292107639

More Books

Students also viewed these Databases questions

Question

Define in words the complement of an event?

Answered: 1 week ago

Question

5. Identify three characteristics of the dialectical approach.

Answered: 1 week ago

Question

6. Explain the strengths of a dialectical approach.

Answered: 1 week ago

Question

4. Explain the strengths and weaknesses of each approach.

Answered: 1 week ago