ProblemDescriptionPlease make sure to read all parts of this document carefully.AsHalloween approaches, you decide togo trick or treating with friends, and want to document your memories using your...

1 answer below »
ProblemDescriptionPlease make sure to read all parts of this document carefully.AsHalloween approaches, you decide togo trick or treating with friends, and want to document your memories using your knowledge ofobject-orientedprogramming. Some of your friends decide to be witches, and some decide to be ghosts. All of you are trick or treaters, andall ofyou want to keep track of the total amount of candy you get.Use the following instructions to write your classes.SolutionDescriptionYou’ll be creating the 5 classes in this assignment:TrickOrTreater, Ghost, Witch,BlackCat, andHappyHalloween.Each of these has constructors, methods, and variables that are described below.A lot of the code will be reused through inheritance, so make sure you pay attention to the hints given below!TrickOrTreater.javaThis file defines aTrickOrTreaterobject.Variables:TheTrickOrTreaterclass must have these variables:•name–the name of the trick or treater. This should be aString.It should be visible to subclasses ofTrickOrTreater.•neighborhood–the neighborhood the trick or treater lives in. This should be aString.It should be visible to subclasses ofTrickOrTreater.•numCandy–the integer amount of candy thisTrickOrTreaterhas.It should be visible to subclasses ofTrickOrTreater.•totalCandy–The totalintegeramount of candy acquired by all trick or treaters.Think about what reserved word you need to use for this variable. It should be visible to subclasses ofTrickOrTreater.Constructor(s):•A constructor that takes in thename,neighborhood, andnumCandy.•A constructor that takes in no parameters. nameshould be set to “Agnes”. neighborhoodshould be set to “Halloweentown.”numCandyshould be set to 0.•Assume that inputs to the constructor are valid inputs.•Youmustminimize the amount of codewrittenand maximize code reuse when writing these constructors.Hint: what keyword have we learned that does this?Methods:The following methods should be public.•seekCandyotakes in anint luckandcalculates the number ofcandygained to be 3*luck.Thisamount of candy should be added tonumCandyandtotalCandy.The method should not return anything.•Getters and settersfor each of the instance variables.oRemember, ifnumCandyis updated,totalCandyshould also be updated.onumCandyandtotalCandyshould only be able to increase.Ghost.javaThis file defines aGhostobject, and should be a subclass ofTrickOrTreaterVariables:In addition to thevariablesit inherits from its superclass,Ghostshould also have the following variables:•transparency–this should be an int that represents how transparent the Ghost is.This should not be visible outside the Ghost class.Constructor(s):•A constructor that takes in thename,neighborhood,numCandy.andtransparency.•A constructor that takes intransparency.(name,neighborhood, andnumCandyshould follow the same default values as inTrickOrTreater.How can you implement this using constructor chaining?)•A constructor that takes in anotherGhostotherand creates a copy based on thatGhost.•Assume that inputs to the constructor are valid inputs.Methods:The following methods should be public.•spookoThis shouldprintout:o“Very spooky” if the transparency level isat10 or highero“Boo!” if the transparency level is between 3 and 9, inclusiveo“Not very spooky” if the transparency level isat 2 or lower.•Getters and setters for each of the instance variablesWitch.javaThis file defines aWitchobject andshould be a subclass ofTrickOrTreater.Variables:In addition to thevariablesit inherits from its superclass,Witchshould also have the following variables:•signatureSpell–this should be aStringthat representstheWitch’sfavorite spell.This should not be visible outside theWitchclass.•companion–this should be an object of typeBlackCatthataccompanies this witch. (More on that class below).This should not be visible outside theWitchclass.Constructor(s):•A constructor that takes in thename,neighborhood,numCandy,signatureSpell,andcompanion.•A constructor that takes inname,signatureSpell,andcompanion.neighborhoodshould be set to “Godric’s Hollow” andnumCandyshould be set to 13;This constructor should chain to Witch’s other constructorto maximize code reuse.•Aconstructor that takes in another Witchotherand creates adeepcopy based on that Witch.(Hint: should changes made to the other witch’s companion affect this witch’s companion?)•Assume that inputs to the constructor are valid inputs.Methods:The following methods should be public.•castSpelloThis method should printout, “> casts signatureSpell>!”.It should also double the witch’s candy. (This should also updatetotalCandy. Hint: How can you use methods you already wrote to do this?)This method should take in no parameters and does not return anything.•Getters and setters for each of the instance variablesBlackCat.javaThis file defines aBlackCatobject. This is an object that atrick-or-treatersdressed as witches should be accompanied by.Variables:TheBlackCatclass must have the following variables:•name–A String that represents the name of the cat.This should not be visible outside theBlackCatclass.•familiar–Abooleanrepresenting if the cat is a familiar (a supernatural creature that may accompany a witch) or not (just a regular cat).This should not be visible outside theBlackCatclass.Constructor(s):•A constructor that takes in name and familiar.Methods:The following methods should be public.•meowoThisshouldprint out “name> is a familiar” or “name> is not a familiar” based on the value offamiliar.•Getters and setters for nameand familiar.TestingHappyHalloween.javaThis Java file is a driver, meaning it will contain and runTrickOrTreater, Witch, Ghost, andBlackCat. Use this to test your code. Here are some tips to help you get started:•Create at least 2 Witches, Ghosts, andBlackcoats.•Use the copy constructors at least once. Try modifying the objects to see if you have deep copied properly.•CallseekCandy()using each of yourTrickOrTreaters.•Print out the amount oftotalCandythey all get.•Reuse your code when possible. These tests and the ones onGradescopeare by no means comprehensive,so be sure to create your own!CheckstyleYoumustruncheckstyleonyoursubmission(To learn more about Checkstyle, check out cs1331-style-guide.pdf under CheckStyle Resources in the Modules section of Canvas.) The Checkstyle cap for this assignment is 15points.This means there is a maximum point deduction of 15. If you don't have Checkstyle yet, download it from Canvas -> Modules -> CheckStyle Resources -> checkstyle-8.28.jar. Place it in the same folder as the files you want to run Checkstyle on. Run checkstyle on your code like so:$java-jarcheckstyle-8.28.jaryourFileName.javaStartingaudit...Auditdone.ThemessageabovemeanstherewerenoCheckstyleerrors.Ifyouhadanyerrors,theywouldshowupabovethismessage,andthenumberattheendwouldbethepointswewouldtakeoff(limitedbythecheckstylecapmentionedintheRubricsection).Infuturehomeworkswewillbeincreasingthiscap,sogetintothehabitoffixingthesestyleerrorsearly!Additionally, you must Javadoc your code.Run the following to only check your Javadocs:$ java -jar checkstyle-8.28.jar -j yourFileName.java Run the following to check both Javadocs and Checkstyle:$ java -jar checkstyle-8.28.jar -a yourFileName.java For additional help with Checkstyle see the CS 1331 Style Guide.Turn-In ProcedureSubmissionTo submit, upload the files listed below to the corresponding assignment on Gradescope:•TrickOrTreater.java•Ghost.java•Witch.java•BlackCat.java•HappyHalloween.javaMake sure you see the message stating the assignment was submitted successfully. From this point, Gradescope will run a basic autograder on your submission as discussed in the next section. Any autograder test are provided as a courtesy to help “sanity check” your work and you may not see all the test cases used to grade your work.You are responsible for thoroughly testing your submission on your own to ensure you have fulfilled the requirements of this assignment. If you have questions about the requirements given, reach out to a TA or Professor via Piazza for clarification.You can submit as many times as you want before the deadline, so feel free to resubmit as you make substantial progress on the homework. We will only grade your latest submission. Be sure tosubmit every file each time you resubmit.Gradescope AutograderIf an autograder is enabled for this assignment, you may be able to see the results of a few basic test cases on your code. Typically, tests will correspond to a rubric item, and the score returned represents the performance of your code on those rubric items only. If you fail a test, you can look at the output to determine what went wrong and resubmit once you have fixed the issue.The Gradescope tests serve two main purposes:•Prevent upload mistakes (e.g. non-compiling code)•Provide basic formatting and usage validationIn other words, the test cases on Gradescope are by no means comprehensive. Be sure to thoroughly test your code by considering edge cases and writing your own test files. You also should avoid using Gradescope to compile, run, or Checkstyle your code; you can do that locally on your machine.Other portions of your assignment can also be graded by a TA once the submission deadline has passed, so the output on Gradescope may not necessarily reflect your grade for the assignment.AllowedImportsTopreventtrivializationoftheassignment,you are not allowed to import any classes or packages.FeatureRestrictionsThereareafewfeaturesandmethodsinJavathatoverlysimplifytheconceptswearetryingtoteachorbreakourautograder.Forthatreason,donotuseanyofthefollowinginyourfinalsubmission:•var(thereservedkeyword)•System.exit•System.arraycopyCollaborationOnly discussion of theHomework(HW)at a conceptual high level is allowed. You can discuss course concepts and HW assignments broadly, that is, at a conceptual level to increase your understanding. If you find yourself dropping to a level where specific Java code is being discussed, that is going too far. Those discussions should be reserved for the instructor andTAs.To be clear, you should never exchange code related to an assignment with anyone other than theinstructor andTAs.ImportantNotes(Don'tSkip)•Non-compilingfiles will receive a 0 for all associated rubric items•Do not submit .classfiles•Test your code in addition to the basic checks on Gradescope•Submit every file each time you resubmit•Read the "Allowed Imports" and "Restricted Features" to avoid losing points•Check on Ed Discussion for a note containing all official clarifications and sample outputsIt is expected that everyone will follow the Student-Faculty Expectations document, and the Student Code of Conduct. The professor expects a positive,respectful, and engaged academic environmentinside the classroom, outside the classroom, in all electronic communications, on all file submissions, and on any document submitted throughout the duration of the course. No inappropriate language is to be used, and any assignment, deemed by the professor, to contain inappropriate, offensive language or threats will get a zero. You are to use professionalism in your work. Violations of this conduct policy will be turned over to the Office of Student Integrity for misconduct
Answered 1 days AfterOct 06, 2021

Answer To: ProblemDescriptionPlease make sure to read all parts of this document carefully.AsHalloween...

Kshitij answered on Oct 07 2021
121 Votes
BlackCat.java
BlackCat.java
/*   Created by IntelliJ IDEA.
 *   Author: Kshitij Varshney (kshitijvarshne1)
 *   Date: 07-Oct-21
 *   Time: 1:03 AM
 *   File: BlackCat.java
 */
package Octob
er.oct07_21;
public class BlackCat {
    //instance variable
    private String name;
    private boolean familiar;
    // constructor
    public BlackCat(String name, boolean familiar) {
        this.name = name;
        this.familiar = familiar;
    }
    // getter and setter
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public boolean isFamiliar() {
        return familiar;
    }
    public void setFamiliar(boolean familiar) {
        this.familiar = familiar;
    }
    // method to show familiar or not
    public void meow() {
        if (this.familiar == true) {
            System.out.println(this.name + " is a familiar");
        } else {
            System.out.println(this.name + " is not a familiar");
        }
    }
}
Ghost.java
Ghost.java
/*   Created by IntelliJ IDEA.
 *   Author: Kshitij Varshney (kshitijvarshne1)
 *   Date: 07-Oct-21
 *   Time: 12:56 AM
 *   File: Ghost.java
 */
package October.oct07_21;
public class Ghost extends TrickOrTreater {
    // instance variable
    private int transparency;
    // constructor
    public Ghost(int transparency) {
        this.transparency = transparency;
    }
    // copy constructor
    public Ghost(Ghost g) {
        this.transparency = g.transparency;
    }
    public Ghost(String name, String neighborhood, int numCandy, int transparency) {
        super(name, neighborhood, numCandy);
        this.transparency = transparency;
    }
    // gette and setter
    public int getTransparency() {
        return transparency;
    }
    public void setTransparency(int transparency) {
        this.transparency = transparency;
    }
    public void s...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here