Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hi, I would like to ask for help on This HW. I have posted the GUI and template code provided with the HW files online
Hi,
I would like to ask for help on This HW. I have posted the GUI and template code provided with the HW files online for your ease. Please follow the restrictions.
I appreciate your kind and well informed help and for your time !
message on throaway369@G mail for more any questions
PetShop.java: https://pastebin.com/jJ3y1nrp
StoreOrganizer.java: https://pastebin.com/mZuH2ySc
PetValidator.java: https://pastebin.com/EtuQpMdT
HW7 Polly's Pet Shop Problem Description Polly owns her own pet shop and wants a digital application of her store. She has called you, a software developer, to help her do this. She has already created the frontend of the application, the user interface, and wants you to finish the backend, logical side, which will power the frontend. Grabbing a cup of coffee from the coffee machine with Polly, you learn that she wants the digital application to give her customers a way to search and sort through her pets. Solution Description You will nced to crcate an animal hicrarchy to organize the pcts and will ncod to determinc a way to scarch and sort the pets. (HINT: what allows you to compare two objects?) We will provide you with some guidance on how to design the backend of the program, but there will be a bit of creative freedom with the implementation. Working as a software developer it will be important for you to think of possible edge cases that could break your code. When providing a program like this to a user you must consider that you cannot always predict what the user will do. Reminders: Use the naming conventions we have taught in class. For example a getter method for a variable called count should be named getCount0 . Be sure to use appropriate visibility modifiers for variables and mnethods. 1. Animal Class: You know that each animal in the pet store has a storeld (whole numbers), name, and a price. Don't allow there to be an instance of the Animal class as cach pet will be directly instantiated as its specific specics. Bc sure any constructors for this class have parameters in the same order as the variables listed above, because the PetShop class will not compile otherwise. You will need to write two constructors for this class. One where the user can decide the store id, name, and price and a constructor only accepting the store id. In the latter constructor, the default valucs are name: Buzz" and price: 222.00 Write sctters and getters for all of the instance variables. Thcse mcthods should be named get VariableName and setVariableName, but replacing VariableName with the actual name of the instance variable. Animals have a NATURAL ORDERING following the ordering of the store id. If two animals have the same store id they should then be compared alphabetically using the animal's name. Implement an interface that cxpresses this natural ordcring. Write a toString method that contains the instance variables for the Animal. Look at the examples section and follow the same formatting of "Store ID: , Name: , Price: ". Be sure to print exactly 2 decimal places for the price. 2. Dog Class: The Dog class should inherit the methods and instance variables defined in the Animal class, but do not duplicate code. The Dog class has a natural ordering but it CAN delegate to Animal's natural ordering (Consider how that changes your implementation). All dogs also have a variable specifying whether or not they have a curlyTail (true or false) and a whole number representing the droolRate. The dog class should have two constructors. One constructor should allow the client to set the name, price, curly tail, and drool rate. The second constructor should allow the client to set only the curly tail and drool rate. For the second constructor, set the default values for price The sort ) method should sort the animals in the pets variable by using the bubble sort method. Click this link for a good visual representation as to what bubble sort does: here This class should have a method binarySearch (Animal a) To search for an animal, a client should be able to pass in an instance of an animal and the method will return the index if the animal is found or -1 if it cannot be found. Use the binary search method to search through the pets. Click this link for a good visual representation of the binary search method: here There will also be a method called linearSearch (Animal a) which similarly to binarySearch(Animal a), will take in an animal and return either the index that the pet is found or -1 if it cannot be found. This method however should use lincar scarching instcad of binary scarching. Click this link for a visual representation of linear searching: here You should understand the efficiency of the scarch and sort methods that you have implemented. In tho javadocs of the search and sort methods write the Big(O) efficiency and give a brief explanation as to why this is the efliciency. 5. StoreOrganizer Interface: This is the interface that the Store class should implement. Do not change this interface and be sure your Store class implements this correctly or your code will not properly compile. 6. PetShop Class: Do not change this class at all! This is the class creating the GUI. You do not need to u code is working yet. If you are having trouble running this class then go to the Background section. If your code is not working or not compiling with this class then you should be changing your classes, not this one. 7. Pet Validator Class: Do not change this class at all! This is a utility class which ensures validity of user input and that the GUI will not crash. You will not be turning this class in and as such if you change this class to make your code run better then you wi lose points. Read the javadocs to learn more about the methods in this class if you are interested, but that is not requircod Examples Remember that you have written the backend for Polly's Pet Shop application. The frontend, or GUI, displays the results of the backend. This is helpful when testing your code. You can use the GUI to add, scarch, and sort pets and be sure that your code is working properly. We have included some pictures below of what the GUI may look like if working properly After using the add button, this is an example of what the GUI should look like. Note that this is before sorting. 3 Polly's Pet Shop! .,Polly's Pet Shop! D X -n Polly's Pet Shop! Polly's Pet Shop! Polly's Pet Shop! Polly's Pet Shop! Store ID 100, Name: Shishir, Price: 2.00, Curly Tail: true, Drool Rate 2 Store ID 200, Name: Maddy, Price: 100000.00, Mice Caught: 2, Likes Lasagnk true Store ID: 100, Name: Emily, Price: 8.00, Curly Tail: true, Drool Rate: 800 Stora I 200, Name: Davon, Price: 00, Mice Caught: 6b, likes lasagna: falsa Store ID: 100, Name: Emily, Price: 8.00, Curly Tail true, Drool Rate: 800 Store ID: 100, Name: Shishir, Price: 200, Curly Tail: true, Drool Rate:-i Store ID: 100, Name: Emily, Price: 8.00, Curly Tail: true, Drool Rate: 800 Store ID: 100, Name: Shishir, Price: 2.00, Curly Tail:true, Droal Rate:2 Store ID: 20, Namw: Da on, Prew. 7a00, Mi Caught 66, Likes Lasagna: sa Storn ID 200, Name: Davon, Prien: ratio, Mien Caught le, 1 kas lasagna: fake Store ID: 200, Name: Maddy, Price: 100000.00, Mice Caught: 2, Likes Lasagna: tr Store ID: 200, Name: Maddy Price: 100000.00, Mice Caught: 2, Likes Lasagna: true Add Pet Sort Pets Search Pet Add Pet Sort Pets Search Pet Add Pet Sort Pets Search Pet The image on the left shows what the GUI should look like after using the add button. The image in the center is an example of sorting the same pets from the first image. The image on the right is an example of searching for the pet named Emily. Note that the found pet is highlighted. Background You will need to use JavaFX in order to compile and run the application. Javall does not come build with JavaFX, so you will have to download this. Below are instructions to download JavaFX and how to compile and run JavaFX files for Windows and Mac. If you have troubles with this please come to office hours as it is difficult to resolve computer download problems remotely through Piazza. NOTE: If you are having trouble with the GUI not reflecting changes you are making in your code, then you may have to manually delete the .class files in the directory and recompile. Windows and Mac: 1. Use this link to download the Java SDK. Be sure it is the SDK and not jmod: here 2. After doing this you will have a new zipped folder on your computer called javafx-sdk-11.0.2. Extract the contents of this zipped folder to the directory holding your hw7 code. Be sure it is in the same folder as your code. There is a way to run JavaFX with the SDK in a different folder but it involves setting environment variables and is much more complex. 3. Compile the file with the JavaFX code (in this case it will be the provided file) by typing into the command prompt (being sure to change fileName.java to the file holding the JvaFX code) javacmodule-path javafx-sdk-11.0.2/1ib --add-modules-javafx.controls fileName.java 4. To run the code type in the command prompt(being sure to change fileName to the file holding the java module-path javafx-sdk-11.0.2/1ib --add-modules-javafx.controls fileName Tips and Considerations JavaFX code): The difficulty of this assignment stems from you having more freedom in how you code this. Start early on this and think about good programming techniques taught in lecture. Allowed Imports To prevent trivialization of the assignment, you are not allowed to import anything on the classes you write The imports written in the PetShop class are okay because we are providing this class to you and you should not be modifving this class. 4 If you would like to import anything else, ask on Piazza. Featuire Restrictions There are a few features and methods in Java that overly simplify the concepts we are trying to teach. For that reason, do not use any of the following in your final submission: var (the reserved keyword) System.arraycopy Rubric 15] Animal Class 2 Class is abstract -2 Class implements Comparable 3] Two correctly written constructors 3 toString properly 5 compareTo proper implementation [17] Dog Class 2 Class implements Comparable 2 Class extends Animal 2 Setters and getters work properly 3 Two correctly written constructors 3 toString properly formatted 5 compareTo proper implementation [17] Cat Class 2 Class implements Comparable 2 Class extends Animal 2 Setters and getters work properly 3] Two correctly written constructors 3] toString properly formatted 5 compareTo proper implementation .51] Store Class -[2] Class implements StoreOrganizer 2 Properly implements the StoreOrganizer interface 2 Big O is correct for the sort and search methods 3 Explanation for Big O is given and correct 4] Sorting method properly sorts the pets Scarch method returns correct index 4 Add method properly adds a pet 10 Sort properly uses bubble sort 101 linearSearch properly uses lincar 10 binarySearch properly uses binary search HW7 Polly's Pet Shop Problem Description Polly owns her own pet shop and wants a digital application of her store. She has called you, a software developer, to help her do this. She has already created the frontend of the application, the user interface, and wants you to finish the backend, logical side, which will power the frontend. Grabbing a cup of coffee from the coffee machine with Polly, you learn that she wants the digital application to give her customers a way to search and sort through her pets. Solution Description You will nced to crcate an animal hicrarchy to organize the pcts and will ncod to determinc a way to scarch and sort the pets. (HINT: what allows you to compare two objects?) We will provide you with some guidance on how to design the backend of the program, but there will be a bit of creative freedom with the implementation. Working as a software developer it will be important for you to think of possible edge cases that could break your code. When providing a program like this to a user you must consider that you cannot always predict what the user will do. Reminders: Use the naming conventions we have taught in class. For example a getter method for a variable called count should be named getCount0 . Be sure to use appropriate visibility modifiers for variables and mnethods. 1. Animal Class: You know that each animal in the pet store has a storeld (whole numbers), name, and a price. Don't allow there to be an instance of the Animal class as cach pet will be directly instantiated as its specific specics. Bc sure any constructors for this class have parameters in the same order as the variables listed above, because the PetShop class will not compile otherwise. You will need to write two constructors for this class. One where the user can decide the store id, name, and price and a constructor only accepting the store id. In the latter constructor, the default valucs are name: Buzz" and price: 222.00 Write sctters and getters for all of the instance variables. Thcse mcthods should be named get VariableName and setVariableName, but replacing VariableName with the actual name of the instance variable. Animals have a NATURAL ORDERING following the ordering of the store id. If two animals have the same store id they should then be compared alphabetically using the animal's name. Implement an interface that cxpresses this natural ordcring. Write a toString method that contains the instance variables for the Animal. Look at the examples section and follow the same formatting of "Store ID: , Name: , Price: ". Be sure to print exactly 2 decimal places for the price. 2. Dog Class: The Dog class should inherit the methods and instance variables defined in the Animal class, but do not duplicate code. The Dog class has a natural ordering but it CAN delegate to Animal's natural ordering (Consider how that changes your implementation). All dogs also have a variable specifying whether or not they have a curlyTail (true or false) and a whole number representing the droolRate. The dog class should have two constructors. One constructor should allow the client to set the name, price, curly tail, and drool rate. The second constructor should allow the client to set only the curly tail and drool rate. For the second constructor, set the default values for price The sort ) method should sort the animals in the pets variable by using the bubble sort method. Click this link for a good visual representation as to what bubble sort does: here This class should have a method binarySearch (Animal a) To search for an animal, a client should be able to pass in an instance of an animal and the method will return the index if the animal is found or -1 if it cannot be found. Use the binary search method to search through the pets. Click this link for a good visual representation of the binary search method: here There will also be a method called linearSearch (Animal a) which similarly to binarySearch(Animal a), will take in an animal and return either the index that the pet is found or -1 if it cannot be found. This method however should use lincar scarching instcad of binary scarching. Click this link for a visual representation of linear searching: here You should understand the efficiency of the scarch and sort methods that you have implemented. In tho javadocs of the search and sort methods write the Big(O) efficiency and give a brief explanation as to why this is the efliciency. 5. StoreOrganizer Interface: This is the interface that the Store class should implement. Do not change this interface and be sure your Store class implements this correctly or your code will not properly compile. 6. PetShop Class: Do not change this class at all! This is the class creating the GUI. You do not need to u code is working yet. If you are having trouble running this class then go to the Background section. If your code is not working or not compiling with this class then you should be changing your classes, not this one. 7. Pet Validator Class: Do not change this class at all! This is a utility class which ensures validity of user input and that the GUI will not crash. You will not be turning this class in and as such if you change this class to make your code run better then you wi lose points. Read the javadocs to learn more about the methods in this class if you are interested, but that is not requircod Examples Remember that you have written the backend for Polly's Pet Shop application. The frontend, or GUI, displays the results of the backend. This is helpful when testing your code. You can use the GUI to add, scarch, and sort pets and be sure that your code is working properly. We have included some pictures below of what the GUI may look like if working properly After using the add button, this is an example of what the GUI should look like. Note that this is before sorting. 3 Polly's Pet Shop! .,Polly's Pet Shop! D X -n Polly's Pet Shop! Polly's Pet Shop! Polly's Pet Shop! Polly's Pet Shop! Store ID 100, Name: Shishir, Price: 2.00, Curly Tail: true, Drool Rate 2 Store ID 200, Name: Maddy, Price: 100000.00, Mice Caught: 2, Likes Lasagnk true Store ID: 100, Name: Emily, Price: 8.00, Curly Tail: true, Drool Rate: 800 Stora I 200, Name: Davon, Price: 00, Mice Caught: 6b, likes lasagna: falsa Store ID: 100, Name: Emily, Price: 8.00, Curly Tail true, Drool Rate: 800 Store ID: 100, Name: Shishir, Price: 200, Curly Tail: true, Drool Rate:-i Store ID: 100, Name: Emily, Price: 8.00, Curly Tail: true, Drool Rate: 800 Store ID: 100, Name: Shishir, Price: 2.00, Curly Tail:true, Droal Rate:2 Store ID: 20, Namw: Da on, Prew. 7a00, Mi Caught 66, Likes Lasagna: sa Storn ID 200, Name: Davon, Prien: ratio, Mien Caught le, 1 kas lasagna: fake Store ID: 200, Name: Maddy, Price: 100000.00, Mice Caught: 2, Likes Lasagna: tr Store ID: 200, Name: Maddy Price: 100000.00, Mice Caught: 2, Likes Lasagna: true Add Pet Sort Pets Search Pet Add Pet Sort Pets Search Pet Add Pet Sort Pets Search Pet The image on the left shows what the GUI should look like after using the add button. The image in the center is an example of sorting the same pets from the first image. The image on the right is an example of searching for the pet named Emily. Note that the found pet is highlighted. Background You will need to use JavaFX in order to compile and run the application. Javall does not come build with JavaFX, so you will have to download this. Below are instructions to download JavaFX and how to compile and run JavaFX files for Windows and Mac. If you have troubles with this please come to office hours as it is difficult to resolve computer download problems remotely through Piazza. NOTE: If you are having trouble with the GUI not reflecting changes you are making in your code, then you may have to manually delete the .class files in the directory and recompile. Windows and Mac: 1. Use this link to download the Java SDK. Be sure it is the SDK and not jmod: here 2. After doing this you will have a new zipped folder on your computer called javafx-sdk-11.0.2. Extract the contents of this zipped folder to the directory holding your hw7 code. Be sure it is in the same folder as your code. There is a way to run JavaFX with the SDK in a different folder but it involves setting environment variables and is much more complex. 3. Compile the file with the JavaFX code (in this case it will be the provided file) by typing into the command prompt (being sure to change fileName.java to the file holding the JvaFX code) javacmodule-path javafx-sdk-11.0.2/1ib --add-modules-javafx.controls fileName.java 4. To run the code type in the command prompt(being sure to change fileName to the file holding the java module-path javafx-sdk-11.0.2/1ib --add-modules-javafx.controls fileName Tips and Considerations JavaFX code): The difficulty of this assignment stems from you having more freedom in how you code this. Start early on this and think about good programming techniques taught in lecture. Allowed Imports To prevent trivialization of the assignment, you are not allowed to import anything on the classes you write The imports written in the PetShop class are okay because we are providing this class to you and you should not be modifving this class. 4 If you would like to import anything else, ask on Piazza. Featuire Restrictions There are a few features and methods in Java that overly simplify the concepts we are trying to teach. For that reason, do not use any of the following in your final submission: var (the reserved keyword) System.arraycopy Rubric 15] Animal Class 2 Class is abstract -2 Class implements Comparable 3] Two correctly written constructors 3 toString properly 5 compareTo proper implementation [17] Dog Class 2 Class implements Comparable 2 Class extends Animal 2 Setters and getters work properly 3 Two correctly written constructors 3 toString properly formatted 5 compareTo proper implementation [17] Cat Class 2 Class implements Comparable 2 Class extends Animal 2 Setters and getters work properly 3] Two correctly written constructors 3] toString properly formatted 5 compareTo proper implementation .51] Store Class -[2] Class implements StoreOrganizer 2 Properly implements the StoreOrganizer interface 2 Big O is correct for the sort and search methods 3 Explanation for Big O is given and correct 4] Sorting method properly sorts the pets Scarch method returns correct index 4 Add method properly adds a pet 10 Sort properly uses bubble sort 101 linearSearch properly uses lincar 10 binarySearch properly uses binary searchStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started