You cannot use the HTTP module, only Express. If the HTTP module is used instead of Express you will receive a 0. If you use the ES6 import statement instead of the CommonJS require for node modules taught during lecture, you will lose 10%. Specifications Rich Barton, the CEO of Zillow, needs your help developing a simple API to determine the Zestimates of houses as well as fetching housing data easily. For this assignment, you will write an API Server that listens on the port provided by the first argument to your program to provide details about a home. JSON API Server Write a server called zillow.js that serves JSON data when it receives a GET request to the path ’/v1/zillow/zestimate’. Expect the request to contain a query string with a keys ’sqft’, ’bed’, and ’bath’ all of which will be required integers. The Zestimate is calculated as follows: Zestimate == sqft * bed * bath * 10 and you should return to the use JSON in the following format: {zestimate: Number } For example: /v1/zillow/zestimate?sqft=2000&bed=3&bath=4 The JSON response should contain only the ‘zestimate’ property: For example: {“zestimate”: 240000} Add a second endpoint at the path ‘/v1/zillow/houses’ that accepts an optional parameter ‘city‘. If city is provided as a parameter, the return all houses that match the given city. If no city parameter is provided, then return an empty array []. If a city is provided and the city is not found, return an empty array [] You will not connect to a real database, but to simulate one, use this array of objects: [ { price: 240000, city: “baltimore” }, { price: 300000, city: “austin” }, { price: 400000, city: “austin” }, { price: 1000000, city: “seattle”}, { price: 1 325000, city: “baltimore” }, { price: 550000, city: “seattle” }, { price: 250000, city: “boston” } ] For example: /v1/zillow/houses?city=baltimore The JSON response should contain only the the list of houses in baltimore. For example: [{ price: 240000, city: ”baltimore” }, { price: 325000, city: ”baltimore” }] For example: /v1/zillow/houses?city=raleigh The JSON response should contain: [] For example: /v1/zillow/houses The JSON response should contain: [] Add a third endpoint at the path ‘/v1/zillow/prices’ that accepts a required parameter ‘usd‘. This will return all houses equal to or under a given price. If no houses are under the given price, return an empty array: [] For example: /v1/zillow/prices?usd=30000 The JSON response should contain: [{ price: 240000, city: ”baltimore” }, { price: 250000, city: ”boston” }] For example: /v1/zillow/prices?usd=10000 The JSON response should contain: [] Please return a 200 status code if the request is correct and a 404 if the request is not correct (invalid endpoint, arguments, etc.) Submission Please submit the following on Blackboard: • zillow.js
DoorDash, Grubhub, and UberEats have been dominating the food delivery market, so to combat this, Towson is coming up with a ghost kitchen, TUEats. You are assigned to the team that is working on the signup flow for new users. Please use a text editor of your choice to create tueats.html, tueats.css and tueats completed.html. The second phase of the TUEats project is to add some styling. This portion of the assignment must be done only in CSS. You must link your tueats.html file to tueats.css, as an external CSS. tueats.html (HTML) For tueats.html, you will need to: • Create a “Sign Up” fieldset with: – A username textfield (required) – An email address textfield (required) – A referral code (optional) – A password obscured textfield (required) – A password verify obscured textfield (required) – A checkbox with a label to the right side saying: “Sign up for our newsletter?” • A “Menu” fieldset that contains a 4×4 table (including the table headers): – Row 1: There will be four table heading fields: “” (aka blank), “Name”, “Price”, and “Calories” 1 – Row 2: “item 1”, “Burger”, “$8”, “550” – Row 3: “item 2”, “Mozzarella Sticks”, “$7”, “400” – Row 4: “item 3”, “Fries”, “$4”, “400” – You’ll notice (r3,c4), (r4,c4) both have “400”. Make is so it only says “400” once for column 4 across rows 3-4 (HINT: look at rowspan and colspan) – Caption the table saying “Menu is subject to change, please visit our main site for more information” and the words “Towson Website” is a link that takes users to towson.edu if clicked. • A single submit button that performs a GET request onsubmit to tueats completed.html. Please note if this path is hardcoded with an absolute, i.e. /Users/yourname/Desktop/assigments/tueats completed.html OR even using /tueats completed.html it will not work when used on another machine. Please ensure this is a relative path i.e. just using ”tueats completed.html” as long as it is in the same folder as tueats.html, otherwise points will be deducted. tueats.css (CSS) For tueats.css, you need to: • Add CSS to the menu table – Bold all table header elements – Make the width of the table 75% – Add a 1px solid black border – Align the text in the table to be centered – Make the background of the table to be gray (HEX: #808080) • Add a picture for TUEats (this can be any photo you choose online (Towson logo is fine), just be sure there is a comment in your CSS sourcing it). • Change the “Welcome to TUEats” header to the Towson Gold (see below for exact color). • If a user hovers over any link in the page (this should only be the “Towson Website” link in the table caption), it should turn Towson’s Gold color. tueats completed.html For this tueats completed.html, you need to: • Simply say “Welcome to TUEats” in any heading tag size of your choice. 2 Notes Towson’s color scheme: • HEX: #FFBB00 • RGB: 255, 187, 0 This link can serve as a guide for some table styling: W3 Schools Example TUEats.html Note: I am currently hovering over “main site” in the image above Submission Please submit the following on Blackboard: • tueats.html • tueats.css • tueats completed.html • any image files needed
The goal is to demonstrate you knowledge of File I/O and JSON to parse text files as well as utilize the asynchronous properties of JavaScript. Look at readFile and readdir functions for parts 3 & 4. Important: If you are on a Windows machine, do not take into account /r for anything, you will lose points if you do. Also, if you use the ES6 import statement instead of the CommonJS require for node modules taught during lecture, you will lose 10%. Specifications For this assignment, you will need to understand File I/O and how to use an asynchronous function in JavaScript. Part 1: File I/O & JSON Create a file called toJSON that reads a .txt file from the command line. This file should always contain at least three lines: • line 1: is a first name (1 word) • line 2: is a last name (1 word) • line 3: is a location (1 word) • lines 4-n: can be string(s) (n # of word(s)) Your job is to take this data and out a clean JSON object in the following format: fname: line1 fname, lname: line2 lname, location: line 3, other: lines 4-lines n The only edge cases that need to be considered are: • If there are not at least three lines in the file, print an error message and do no further processing on the file • Only one arg is read in through the command line which is the filename. If more than one arg is provided, print an error message and do no further processing on the file • If there are only three lines, other will contain “N/A” 1 Part 2: to Array Create a file called toArray.js that reads n numbers from the command line, adds only the even numbers to an array, and returns the array in the order that they were entered. You must use a forEach loop for this file. The output will contain the size of the array and the array itself. Part 3: String Count Create a file called stringCount.js that reads a textfile from the command line. You must return the total number of occurrences that the following words in the textfile (case should be ignored): • towson • cis • web • development Please note: this should only count if one of the four words is a stand-alone word, not if it is contained within another word. For example, if a textfile contained the string “Welcome to TowsonCIS”, the value returned would be 0. But if the textfile contained the string “Welcome to Towson CIS” the value returned would be 2. Part 4: File Count Write a program called asyncFileCount.js that prints the number of files with a given extension in a given directory. The first argument will be the path to the directory we want to filter on (e.g. ‘/path/to/dir/’) and a file extension to filter by as the second argument. For example, if you get ‘.txt’ as the second argument then you will need to filter the list to only files that end with .txt 2 Below are some example runs: An example run would be: node asyncFileCount.js . .js Another example run would be: node asyncFileCount.js /Users/jalirani/Desktop .docx Submission Please submit the following on Blackboard: • toJSON.js • toArray.js • stringCount.js • asyncFileCount.js
1. Consider a stable roommate problem involving four students (A, B, C, D): Each student ranks the other three in a strict order of preference. A matching involves forming two pairs of the students, and it is considered stable if no two separated (not matched) students would prefer each other over their current roommates. Prove or disprove: A stable matching always exists in this scenario. 2. Consider an instance of the Stable Matching Problem in which there exists a man m and a woman w such that m is ranked first on the preference list of w and w is ranked first on the preference list of m. Prove or disprove: In every stable matching for this instance, m is matched with w. 3. Consider the stable matching problem with n women and n men (where n ≥ 2). Prove or disprove: It is not possible for any preference lists, that the Gale-Shapley algorithm with men proposing can match every woman to her least preferred man. 4. There are six students in a class: Harry, Ron, Hermione, Luna, Neville, and Ginny. This class requires them to pair up and work on pair programming. Each has preferences over who they want to be paired with. The preferences are: Harry: Hermione > Neville > Ron > Ginny > Luna Ron: Ginny > Neville > Hermione > Harry > Luna Hermione: Ron > Neville > Ginny > Harry > Luna Luna : Harry > Ron > Ginny > Hermione > Neville Neville: Harry > Ron > Hermione > Ginny > Luna Ginny: Neville > Harry > Hermione > Ron > Luna A given matching (of students into pairs) is not stable if there are two potential partners who are not currently paired but prefer each other over their respective current partners. Prove or Disprove: No matching is stable for the preferences given above. Ungraded Problems: 1. Prove or Disprove: It is possible to have an instance of the Stable Matching problem in which two women have the same best valid partner. 2. Prove or Disprove: In every instance of the Stable Matching Problem, there is a stable matching containing a pair (m, w) such that m is ranked first on the preference list of w and w is ranked first on the preference list of m. 3. Consider the stable matching problem with n women and n men (where n ≥ 2). Suppose the preference lists are such that for any woman w, her most preferred man m, does not have w as his first preference Prove or disprove: It is possible that the Gale-Shapley algorithm with men proposing can match every woman to her most preferred man. 4. Suppose the Gale-Shapley algorithm with men proposing is run once. Then, a particular woman w falsely reports her preferences by swapping two men’s positions in her actual preference list. With this alteration, the Gale-Shapley algorithm with men proposing is run once again. Prove or disprove: It is possible for the woman w to get a more preferred partner (as per her actual preference list), by doing the swapping alteration in her preferences.
Question 1: You are given 2 implementations for a recursive algorithm that calculates the sum of all the elements in a list (of integers): def sum_lst1(lst): if (len(lst) == 1): return lst[0] else: rest = sum_lst1(lst[1:]) sum = lst[0] + rest return sum def sum_lst2(lst, low, high): if (low == high): return lst[low] else: rest = sum_lst2(lst, low + 1, high) sum = lst[low] + rest return sum Note: The implementations differ in the parameters we pass to these functions: • In the first version we pass only the list (all the elements in the list have to be taken in to account for the result). • In the second version, in addition to the list, we pass two indices: low and high (low ≤ high), which indicate the range of indices of the elements that should to be considered. The initial values (for the first call) passed to low and high would represent the range of the entire list. 1) Make sure you understand the recursive idea of each implementation. 2) Analyze the running time of the implementations above. For each version: i) Draw the recursion tree that represents the execution process of the function, and the local-cost of each call. ii) Conclude the total (asymptotic) running time of the function. 3) Which version is asymptotically faster? Question 2: Analyze the running time of each of the following functions. For each function: i. Draw the recursion tree that represents the execution process, and the cost of each call. ii. Conclude the total (asymptotic) running time. Note: For the simplicity of the analysis of sections (b) and (c), you may assume that n is a power of 2, therefore it can always be divided evenly by 2. a. def fun1(n): if (n == 0): return 1 else: part1 = fun1(n-1) part2 = fun1(n-1) res = part1 + part2 return res b. def fun2(n): if (n == 0): return 1 else: res = fun2(n//2) res += n return res c. def fun3(n): if (n == 0): return 1 else: res = fun3(n//2) for i in range(1, n+1): res += i return res Question 3: Give a recursive implement to the following functions: a. def print_triangle(n) This function is given a positive integer n, and prints a textual image of a right triangle (aligned to the left) made of n lines with asterisks. For example, print_triangle(4), should print: * ** *** **** b. def print_oposite_triangles(n) This function is given a positive integer n, and prints a textual image of a two opposite right triangles (aligned to the left) with asterisks, each containing n lines. For example, print_oposite_triangles(4), should print: **** *** ** * * ** *** **** c. def print_ruler(n) This function is given a positive integer n, and prints a vertical ruler of 2! − 1 lines. Each line contains ‘-‘ marks as follows: • The line in the middle (! ” ) of the ruler contains n ‘-‘ marks • The lines at the middle of each half (! # and $ # ) of the ruler contains (n-1) ‘-‘ marks • The lines at the ! % , $ % , & % and ‘ % of the ruler contains (n-2) ‘-‘ marks • And so on … • The lines at the ! “(, $ “(, & “(, …, “()! “( of the ruler contains 1 ‘-‘ mark For example, print_ruler(4), should print (only the blue marks): – 1/16= 1/16 – – 2/16= 1/8 – 3/16= 3/16 – – – 4/16= 1/4 – 5/16= 5/16 – – 6/16= 3/8 – 7/16= 7/16 – – – – 8/16= 1/2 – 9/16= 9/16 – – 10/16= 5/8 – 11/16= 11/16 – – – 12/16= 3/4 – 13/16= 13/16 – – 14/16= 7/8 – 15/16= 15/16 Hints: 1. Take for n=4: when finding print_ruler(4), try to think first what print_ruler(3) does, and how you can use it to print a ruler of size 4. Then, generally identify what print_ruler(n-1) is supposed to print, and use that in order to define how to print the ruler of size n. 2. You may want to have more than one recursive call 3. It looks much scarier than it actually is Question 4: Give a recursive implement to the following function: def list_min(lst, low, high) The function is given lst, a list of integers, and two indices: low and high (low ≤ high), which indicate the range of indices that need to be considered. The function should find and return the minimum value out of all the elements at the position low, low+1, …, high in lst. Question 5: Give a recursive implement to the following functions: a) def count_lowercase(s, low, high): The function is given a string s, and two indices: low and high (low ≤ high), which indicate the range of indices that need to be considered. The function should return the number of lowercase letters at the positions low, low+1, …, high in s. b) def is_number_of_lowercase_even(s, low, high): The function is given a string s, and two indices: low and high (low ≤ high), which indicate the range of indices that need to be considered. The function should return True if there are even number of lowercase letters at the positions low, low+1, …, high in s, or False otherwise. Question 6: Give a recursive implement to the following function: def appearances(s, low, high) The function is given a string s, and two indices: low and high (low ≤ high), which indicate the range of indices that need to be considered. The function should return a dictionary that stores a mapping of characters to the number of times they each appear in s. That is, the keys of the dictionary should be the different characters in s, and their associated values should be the number of times each of them appears in s. For example, the call appearances(”Hello world”, 0, 10) could return: {’e’:1, ’o’:2, ’H’:1, ’l’:3, ’r’:1, ’ ’:1, ’d’:1,’w’:1}. Note: A dictionary is a mutable object. Use that property to update the dictionary, returned from your recursive call. Question 7: Give a recursive implement to the following function: def split_by_sign(lst, low, high) The function is given a list lst of non-zero integers, and two indices: low and high (low ≤ high), which indicate the range of indices that need to be considered. The function should reorder the elements in lst, so that all the negative numbers would come before all the positive numbers. Note: The order in which the negative elements are at the end, and the order in which the positive are at the end, doesn’t matter, as long as all he negative are before all the positive. Question 8: A nested list of integers is a list that stores integers in some hierarchy. That is, its elements are integers and/or other nested lists of integers. For example nested_lst=[[1, 2], 3, [4, [5, 6, [7], 8]]] is a nested list of integers. Give a recursive implement to the following function: def flat_list(nested_lst, low, high) The function is given a nested list of integers nested_list, and two indices: low and high (low ≤ high), which indicate the range of indices that need to be considered. The function should flatten the sub-list at the positions low, low+1, …, high of nested_list, and return this flattened list. That is, the function should create a new 1-level (non hierarchical) list that contains all the integers from the low…high range in the input list. For example, when calling flat_list to flatten the list nested_lst demonstrated above (the initial call passes low=0 and high=2), it should create and return [1, 2, 3, 4, 5, 6, 7, 8]. (Extra Credit) Question 9: Given an ordered list L. A permutation of L is a rearrangement of its elements in some order. For example (1, 3, 2) and (3, 2, 1) are two different permutations of L=(1, 2, 3). Implement the following function: def permutations(lst, low, high) The function is given a list lst of integers, and two indices: low and high (low ≤ high), which indicate the range of indices that need to be considered. The function should return a list containing all the different permutations of the elements in lst. Each such permutation should be represented as a list. For example, if lst=[1, 2, 3], the call permutations(lst, 0, 2) could return [[1, 2, 3], [2, 1, 3], [1, 3, 2], [3, 2, 1], [3, 1, 2], [2, 3, 1]] Hint: Think recursion!!! Take for example lst=[1, 2, 3, 4]: to compute the permutation list of lst, try to first write down the list containing all permutations of [1, 2, 3], then, think how to modify it, so you get the permutation list of [1, 2, 3, 4].
Part 1. Reading from a file 1. Create a new Java Project for this lab assignment. Call it Lab10. 2. Download the data file, called Lab10-state-data.txt from D2L. It is located in the week14 folder. This file includes population information about the 50 USA states. Each line in the file consists of three fields where the first number is the overall state population, the second number the adult population, and the third field is the state name. For example, the following are the first few lines in the file: 4874747 3779274 Alabama 739795 554867 Alaska 7016270 5382780 Arizona 3004279 2298739 Arkansas 39536653 30476517 California 3. On your computer, find the directory where your Eclipse projects are created and find project Lab10. Put the data file in the directory Lab10. The directory will look something like this:4. Inside Lab10 project, create a file and call it ‘FileIO.java’, and this file should include only the main method. 5. Write Java code to ask the user to enter the file name and then read the user input. 6. Create a File object using the file name that is entered by the user. 7. Create a Scanner object to read from the File object that you created in the previous step. 8. Write a loop that uses hasNextLine() to read the file one line at a time and display the data on the screen. Inside the loop, read one line from the file using nextLine() and print the line on the screen. At the end of the loop, print how many lines are there in the file. 9. When you run your program, you should see all the file contents printed on the screen. Part 2. Writing to a file 13. In this part of the lab, you will read the data from the input file, process it, and save it another file. 14. In this step, you will write the output to a file instead of writing it to the screen. Create a PrintWriter object and assign it to the output file name. Then, add a statement inside your ‘while’ loop to print the output to the output file in addition to printing it to the screen. 15. Outside the loop, close the PrintWriter object so that you can open and read your output file. 16. Open the output file and make sure that the data is correctly written.Upload your work to D2L 1. Right click on the src folder and choose the Export… option.2. When asked to choose an Export Wizard, double click on General. 3. Then click Archive File and Next. Make sure the radio button next to Save in zip format is selected. 4. Use the Browse function to navigate to the H: drive, then make up a name for your file. You can name your archive file anything but it helps me find your work if you use your last name and the name of the lab so choose something like DillonLab10. Click Finish. 5. Now login to D2L. From the home page, click on the Assessments drop down menu and select Assignments. 6. From the Assignment Submission Folders page, select the Lab10 drop box. 7. Click on Add a File, browse for the archive (.zip) file you created with Eclipse and Upload it. You can add a note if you like but you don’t have to. Click Submit to finish up.NOTE: To receive credit for this lab, you are expected and MUST work with another student and to demonstrate your solution (even if it is partially completed) to the instructor before you leave class on Wednesday, April, 12th, 2023. If you are unable to demo your solution to the instructor, continue to work on the lab Only if you upload a version of your code to D2L during the lab session on April 12th, you may upload a completed version to the assigned D2L folder by Sunday, April 16th at 11:59 PM.
Question 1: Draw the memory image for evaluating the following code: >>> lst1 = [1, 2, 3] >>> lst2 = [lst1 for i in range(3)] >>> lst2[0][0] = 10 >>> print(lst2) Question 2: a. Write a function def shift(lst, k)that is given a list of N numbers, and some positive integer k (where k>> v1 = Vector(5) >>> v1[1] = 10 >>> v1[−1] = 10 >>> print(v1) >>> v2 = Vector([2, 4, 6, 8, 10]) >>> print(v2) >>> u1 = v1 + v2 >>> print(u1) >>> u2 = -v2 >>> print(u2) >>> u3 = 3 * v2 >>> print(u3) >>> u4 = v2 * 3 >>> print(u4) >>> u5 = v1 * v2 >>> print(u5) 140
Part 1. Sorting an array of integers In this part of the lab, you will use test the selection sort method and, then, you will modify the method to sort in descending order. 1- To start, create a new Java class in your project, called SortingDriver, that includes the main method. 2- Copy the selectionSort method from the lecture12 slides and paste it inside SortingDriver. 3- Do the following in the main method: a. Declare an array of integers, called myNumbers, and initialize it with an initializer list with any numbers of your choice but make sure that the numbers are not sorted. b. Write a for loop to print the array on where all the numbers in one line tabseparated. c. Call the selectionSort method with myNumbers array as input. d. Write a for loop to print the array again after sorting and make sure the numbers are sorted in ascending order. 4- Copy the selectionSort method and paste it again in SortingDriver class, change the method name to be selectionSortDescending. 5- Change the code in the selectionSortDescending method such that the method sorts the array in descending order instead of ascending order. 6- In main, call the selectionSortDescending method with myNumbers array as input, then print the array after the method and make sure that the numbers are sorted in descending order. Part 2. Sorting an array of Objects In this part of the lab, you will use the selection sort algorithm to sort an array of Employee objects. 1- Create a new class or copy the Employee class that you used in Assignment2. 2- Implement the compareTo method in the Employee by implementing the Comparable class. Make sure to implement the compareTo method to compare objects based on at least two instance variables. For example, use can compare two employees based on name, and hours (i.e., if two Employees have the same name, then they will be sorted on hours). 3- Add another class, called ObjectSortingDriver, to Lab9 project and this class should include a main method. 4- Copy the selectionSort method and paste it in the ObjectSortingDriver class. Then, change the method input to be an Employee[] instead of int[]. Also, change the method code to use the compareTo method and change any other data types as appropriate. 5- In the main method, create an Employee array of size 6 and fill it with 6 objects. Then write a for loop to print the array. 6- In main method, call the selectionSort method with the Employee array you created in the previous step as input. Then, print the array again to make sure that the objects are sorted. Upload your work to D2L For this lab, you need to submit the following: 1- A zip file that includes all .java files that you created in Lab9 project directory as explained above. NOTE: You will be working in groups. To receive credit for this lab assignment, you are expected to work with another student and to demonstrate your solution (even if it is partially completed) to the instructor before you leave class on Wednesday, April, 5th, 2023. If you are unable to demo your solution to the instructor, continue to work on the lab Only if you upload a version of your code to D2L during the lab session on April 5th, you may upload a completed version to the assigned D2L folder by Sunday, April 9th at 11:59 PM.
Part 1. Understanding Inheritance and Polymorphism In this assignment, you be working in a group. You cannot receive help from the ICS tutors. Research by reading chapters 80, 81 and 82 of the online book by Bradley Kjell, link here: https://programmedlessons.org/Java9/index.html#part09 1. Answer the questions below and upload your responses to the drop box before the due date. 2. What is your understanding of inheritance in Java? Briefly describe or provide an example 3. Why do we use inheritance? Can you recall a time that we use inheritance for any of the labs or assignments? Provide an example. 4. What are the two types of class relationships in Java discussed in the reading? 5. Which class is the root class of all the classes in Java? What is another name for this class? 6. Describe Polymorphism? If possible, give an example that relates to the real-world. 7. What’s the difference between methods overloading vs. overriding? Provide more than just the definition. Part 2. Implementing Inheritance and Polymorphism To make sure you understand Inheritance based on the reading, lecture demo and class discussion. You and your group member(s) come up with a Single inheritance relationship and implement the code. You must test your code by instantiating objects and calling the methods you implement. Based on the Class Hierarchy, a child has access to the parent’s methods so call a method in the parent class on a child class and verify it works. Test the reverse. What happens? Do you know why? Submission Instructions Create a java project and call it Lab8 (e.g., mine will be called DillonLab8) Create one.java files to solve the problem described above. Export your .java file into a zip file using Eclipse using the following steps: o In Eclipse Project Explorer, right click on the src folder of the project and click on Export. o Choose General then Archive File and click Next. o Use the Browse key to choose a folder to store the archive file on your hard drive and give the file the same name as your project (e.g., DillonLab8.zip), then click Save, then click Finish. o Upload the .zip file you created to the D2L folder called Lab8. It is important that you upload only one zip file. Your assignment will not be graded if you upload individual .java files to the drop box.
Part 1: Switch Statement 1. Complete the rest of the Calculator code based on class discussion on the Switch statement and the starter code provided. Part 2: If, else-if 1. Complete the rest of the Calculator code based on class discussion on the If, else-if statement and the starter code provided. Part 4: Creating objects that contains another object 1. Discuss with your group members and come up with a list of Objects that contain other objects. List 5 objects that fit into this category. Discuss what it knows and can do. 2. Add a package to the SelectionAndRepetition project; name it ‘ObjectsWithinObjects’. 3. Choose one of the objects from your list and come up with an implementation: 1. Base on the discussion; select one of your objects. i Add a class to the ‘ObjectsWithinObjects’ package for the selected object. ii Add 3 instance variables to represent what the object knows. iii Getters and Setters iv 3 methods for what the object can do. v Add a toString() to print the details. 2. Implement another class which MUST contain the previous class from #1. i Add 2 instance variables to represent what the object knows. 1 One of the instance variables MUST be the data type of the class in the previous step #1. ii Add two methods for what the object can do based on the contained class from #1. 3. Add the toString() to print the details. 4. Create a Driver class and test your code. 1. Instantiate 2 objects: One for the class created in step #1 and the second from the class created in step 2. Call all the methods for both classes. Part 3: For loops 1. Add another package to the ‘SelectionAndRepetion’ project, name the package ‘forloops’ and create a class call ‘ForLoops’ inside the package. 2. Create a DriverForLoops class inside the ‘forloops’ package and add each for loop below and respond to the question inside of your code using comments. 3. Write the following loop inside the main() method of your class for (int i=1; i
Goals: Implement and invoke methods The goal of ‘Lab5’ is to help reinforce Class(es), Objects and Methods. Part 1: Describing a class 1. Find an object in the real-world; your object cannot be a Car, an Animal a Book or any of the objects covered in class or any of the recordings. 2. Create a Class with the name of your object. 3. Describe the class by adding 3 instance variables. 4. Add a parameterized Constructor that takes in 3 inputs to initialize the instance variables. 5. Add Getters and Setters for all the variables. 6. Add a toString() method to print the details of your object. Part 2: Programmer Design methods 1. Considering the real-world object you selected in Part1, create 4 additional methods. a. One method of type void. b. One method of type int. c. One of type String. d. One Static method to be call on the class. Part 3: Creating objects 1. Create a ThingDriver class. (*the driver class is the name of your object + the word Driver) 2. Instantiate 2 objects using the parameterized constructor. 3. Print the details of both objects. Part 4: Respond to these questions in your code using comments 1. What are the similarities between a Class, Object and Method? 2. What are the differences between a Class, Object and Method? 3. What is the importance of using a UML? 4. What happens when we add static to a method? 5. Can we instantiate an object if our class doesn’t have a constructor? What does adding a constructor to a class do? 6. How is a constructor different from a class? Part 4: Respond to the questions in your code – do some research 1. Right click on the src folder and export your code. Create a zip with your name i.e. DillonLab5 and upload it to D2L Lab5 drop box.
Goals : Implement and invoke methods Copy ‘Lab3’ and rename it ‘Lab4’. Update ‘Lab4’, and add a new class call Method to implement Part1. Part 1 : Practicing using methods 1. In the Method class, declare a private static int variable call count. 2. Implement a static method call multiConcat, which takes two input parameters of types String and int, and returns a String that is the parameter string concatenated with itself x number of times (where x is the second int parameter). For example, if the parameters are “hi” and 4, the return value is “hihihihi”. 3. Divide your work into step as follows: a) Write the method header. You need to answer the following questions to find out the different parts of the method header: i What is the data type of the method output? ii What is the method name? iii What is the data type of the first input parameter? iv What is the data type of the second input parameter? b) Write the method body as follows: i Declare a local String variable that will be used to hold the output. ii Write a loop and the number of iterations should equal to the method’s second input parameter. iii Inside the loop’s body, append the first input parameter to the output string. iv Write a return statement to return the output string. c) Add statements in the main method to test your method as follows: i Ask the user to enter a string and read the string. ii Ask the user to enter the number of repetitions and read the number. iii In the DogDriver, call the muliConcat method on the Method class pass in the user inputs as parameters. Store the results from the method call in a variable. iv Print the variable. Part 2 : Writing and invoking methods After completing Part1, Make changes to the ‘Dog’ class and add the methods below in Part2. In the `DogDriver` class, test the method by calling each method on any of the ‘Dog’ objects. Submit the updated code in the Lab4 drop box. 1. Add a method call price, which returns a double that takes in two inputs of type int call quantity and type double call price. 2. Add a method call greetings, which returns a String that takes in one input of type String call greet. 3. Add a void method call makeSound, which prints a sound when call from the DogDriver. 4. Add a void method call eat, which takes in one input of type String call brand and prints the food brand the dog likes. CHECKPOINT: Show the output of your completed program to your lab instructor. Part 3. Upload your work to D2L 1. Right click on the src folder and choose the Export… option.2. When asked to choose an Export Wizard, double click on General. 3. Then click Archive File and Next. Make sure the radio button next to Save in zip format is selected. 4. Use the Browse function to navigate to the H: drive, then make up a name for your file. You can name your archive file anything but it helps me find your work if you use your last name and the name of the lab so choose something like DillonLab04. Click Finish. 5. Now login to D2L. From the home page, click on the Assessments drop down menu and select Assignments. 6. From the Assignment Submission Folders page, select the Lab4 drop box. 7. Click on Add a File, browse for the archive (.zip) file you created with Eclipse and Upload it. You can add a note if you like but you don’t have to. Click Submit to finish up. NOTE: To receive credit for this lab assignment, demonstrate your solution to your lab instructor before you leave. Work is to be completed during the face-to-face lab session today.
Part 1. Declaring ‘Dog’ and ‘DogDriver’ classes In this Lab, you will implement a Java class, called ‘Dog’, which can be used to represent dog objects in an application to be used, for example, in an animal hospital. You will then test your class by implementing another class, called ‘DogDriver’. To start, Open Eclipse and create a new project and name it ‘DogApplication’ then follow the following steps: 1. Create a class called ‘Dog’ inside the ‘DogApplication ‘ project. 2. Declare the following two instance variables in ‘Dog’. Remember that instance variables must be declared as private. a. name (of type String). b. age (of type int). 3. Declare a constructor for the ‘Dog’ class that takes two input parameters and uses these input parameters to initialize the instance variables. 4. Now create another class in your project and call it ‘DogDriver’. You will use this class to test the ‘Dog’ class. The ‘DogDriver’ class should include only the main method. 5. Inside the driver’s main method, declare two variables of type ‘Dog’ and call them ‘myDog’ and ‘yourDog’, then, assign these two variables to two instances of ‘Dog’ with any values of your choice for name and age. (Note: you have to use new to instantiate the dog objects). 6. Go back to the ‘Dog’ class and implement the ‘toString’ method and then call this method from ‘DogDriver’ to print the dogs’ information. CHECKPOINT 1: Make sure the information about your dogs is printed correctly and show the output to the instructor. Part 2. Adding more methods to the ‘Dog’ class. In this part, you are going to add (and test) more functionality to your ‘Dog’ class. 7. Assume that, in the ‘DogDriver’ class, you tried to print only the names of the two dogs that you created in step #5 using the following statements: System.out.println(myDog.name); System.out.println(yourDog.name); Write down the error message you get when you type these statements? 8. In order to be able to print only the dog name, go back to the ‘Dog’ class and implement a getter method for the dog’s name instance variable. 9. In the DogDriver class, print the dogs’ names. 10. Assume now you want to change the age of ‘myDog’ using the following statement: myDog.age = 20; 11. The previous statement will not work. You must implement a setAge method in order to be able to change the dog’s age. So, go back to the ‘Dog’ class and implement the setAge method. Then, call the setAge method from the ‘DogDriver’ class two times to change the age of both dogs. 12. Call the toString() method to print the dogs’ information again to make sure that the ages are correctly changed. 13. Draw the UML diagram of the Dog class. CHECKPOINT 2: Show the output of your completed program and your UML to either the instructor. Part 3. Upload your work to D2L 1. Right click on the src folder and choose the Export… option.2. When asked to choose an Export Wizard, double click on General. 3. Then click Archive File and Next. Make sure the radio button next to Save in zip format is selected. 4. Use the Browse function to navigate to the H: drive, then make up a name for your file. You can name your archive file anything but it helps me find your work if you use your last name and the name of the lab so choose something like GhanemLab03. Click Finish. 5. Now login to D2L. From the home page, click on the Assessments drop down menu and select Assignments. 6. From the Assignment Submission Folders page, select the Lab3 drop box. 7. Click on Add a File, browse for the archive (.zip) file you created with Eclipse and Upload it. You can add a note if you like but you don’t have to. Click Submit to finish up. 8. Draw the UML on a word document and upload that document to the Lab 3 drop box on D2L. NOTE: To receive credit for this lab assignment, demonstrate your solution (even if it is partially completed) to the instructor before you leave.
Part 1. Practicing the counting loop Open Eclipse and create a new project ‘Lab3’. Rename the src folder to ‘Lab3’. Copy the ‘Dog’ and the `DogDriver` classes from ‘Lab2’ and paste them in the Lab3 src folder. If you encounter a package error, update the package at the top of each class. 1. Using a counting loop as demonstrated in the recording; create as many Dog objects based on the user input. 2. What part of the loop or the code was confusing? Use a single or multiline comment to explain any issues you encounter in with writing the solution to this question. CHECKPOINT: Show the output of your completed program to your lab instructor. Part 2. Practicing the sentinel loop 1. Using a sentinel loop as demonstrated in the recording continue to prompt the user if they would like to enter details for another dog. 2. After writing the sentinel loop, can you tell what the mean differences between the two loops? Which one do you feel more comfortable writing? Can you write either one directly from memory? Use a single or multiline comment to explain your answer. CHECKPOINT: Show the output of your completed program to your lab instructor. Part 3. Upload your work to D2L 1. Right click on the src folder and choose the Export… option.2. When asked to choose an Export Wizard, double click on General. 3. Then click Archive File and Next. Make sure the radio button next to Save in zip format is selected. 4. Use the Browse function to navigate to the H: drive, then make up a name for your file. You can name your archive file anything but it helps me find your work if you use your last name and the name of the lab so choose something like DillonLab03. Click Finish. 5. Now login to D2L. From the home page, click on the Assessments drop down menu and select Assignments. 6. From the Assignment Submission Folders page, select the Lab3 drop box. 7. Click on Add a File, browse for the archive (.zip) file you created with Eclipse and Upload it. You can add a note if you like but you don’t have to. Click Submit to finish up. NOTE: To receive credit for this lab assignment, demonstrate your solution to your lab instructor before you leave. Work is to be completed during the face-to-face lab session today.
In this assignment, you will write a Java application to analyze data about users who write movie reviews on a certain movie review web site. The data is stored in a text file where each line in the file has five tab-separated fields that represent: user identifier, age, sex, occupation, and zip code. For example, the following are the first few lines of the file: 1 24 M technician 85711 2 53 F other 94043 3 23 M writer 32067 4 24 M technician 43537 5 33 F other 15213 6 42 M executive 98101 7 57 M administrator 91344 8 36 M administrator 05201 9 29 M student 01002 In order to process this data, you will upload the data from the text file into an array of User objects. Then, you will write several methods to process the array of objects. Basically, these are the implementation steps that you will follow: 1- Define the User class that is used to represent one user. 2- Declare an array that can store up to 200 User objects’ references (because there are 200 lines in the file). 3- Read the text file line-by-line then, for each line, use the five fields in that line to instantiate a User object and insert a reference to that object in the array. 4- Write four methods where each method takes the user array as input and perform some analysis on the data, for example, find the average user age or the number of ‘student’ users. Implementation steps Step 1: Implement User class As explained above, you will read the data from the text file and store it in an array of User objects where each line in the text file is used to construct one User object. Hence, the first step is to define the User class. Start by creating an Eclipse project, called Assignment6. Then, create a class, called User, inside Assignment6 project. As per the data file description above, the User object is to be defined using the following five private instance variables: • userID: of type int • age: of type int • sex: of type String • occupation: of type String • zipCode: of type String Implement the following methods in the User class: • getters and setters for all the instance variables. • toString method that returns a String representation of a User where all the instance variables are in one line and separated by tabs. Step 2: Upload data from the text file into an array of User objects • The input data is in a file called ‘Assignment-6-user-data.txt’ • Create another class in your project, called UserDataProcessingDriver, that includes only the main method. • In the main method, declare an array, called usersArr, that can hold up to 200 Users. • In the main method, write a loop to read the text file. Note that, similar to Lab 9, you need to read one field from the file at a time using the appropriate next method. Basically, inside your ‘while’ loop, you will read the five fields in each row in the following order: nextInt, nextInt, next, next, and nextLine. • Inside the ‘while’ loop, and after reading the five fields, instantiate a User object using the five fields and insert that object in usersArr. • After the while loop completes reading the file, write a ‘for’ loop to print on the screen all objects in usersArr to make sure that the data to uploaded correctly.Step 3: Methods to process the users array In this part, you are asked to implement the following four methods in the UserDataProcessingDriver file. Then, test the methods by calling them from the main method. 1- avgAge: a method that takes an array of User objects as input parameter and returns as output the average age of all users in the array. 2- countOccupation: a method that takes two input parameters where the first input is an array of User objects and the second parameter is a String that represents an occupation. The method then returns as output the number of users whose occupation is the same as the input occupation. For example, the call countOccupation(usersArr,”educator”) returns how many users are there in the array usersArr whose occupation is ‘educator’. 3- avgOccupationAge: a method that takes two input parameters where the first input is an array of User objects and the second parameter is a String that represents an occupation. The method then returns as output the average age of users whose occupation is the same as the input occupation. For example, the call avgOccupationAge(usersArr,”student”) returns the average age of student users in usersArr. 4- countMaleBelowAge: a method that takes two input parameters where the first input is an array of user objects and the second input parameter is an integer that represents a person’s age. The method returns as output the number of male users who are below the input age. For example, the call countMaleBelowAge(usersArr, 50) returns as output the number of users whose sex is ‘M’ and age Archive File and click Next. • Use the Browse key to choose a folder to store the archive file on your hard drive and give the file the same name as your project (e.g., DillonAssginment6.zip), then click Save, then click Finish. • Upload the .zip file you created to the D2L folder called Assignment 6. • It is important that you upload only one zip file. Your assignment will not be graded if you upload individual .java files to D2L.
In this assignment, you will implement a collection class to manage a group of things of your choice. Requirements Part A: Implement your Thing class In this assignment, you will implement a Thing class. Your Thing class to meet the following requirements: • You thing must have exactly 3 instance variables such that: o one instance variable must be integer (i.e, int) and this variable will be used to find aggregate information (e.g., total or max) about Things that are stored in a collection class as will be explained later. o one instance variable must be String and this variable will be used as a categorization attribute that will be used to divide your collection into groups. You are going to use this attribute to count. For example, for a collection of cars, then the cars can be categorized based on color or brand. o The third instance variable can be either int or String type based on the semantics of your Thing. • All instance variables must be private. • Implement getters and setters for all the instance variables of your Thing. • Implement toString method that returns a String representation of your Thing class where all the instance variables are in one line and separated by tabs. • Implement the equals method for your Thing where two things are considered equal when they have the same values in the three instance variables. Note that, the equality of String attributes should be case insensitive. For example, “MATH”, “math” and “Math” match each other. In order to compare strings in Java use the String’s equalsIgnoreCase method. For example, the following code prints true: String str1 = “Hello”; String str2 = “hello”; System.out.println(str1.equalsIgnoreCase(str2)); Part B: Implement a Collection class • Implement a collection class of Things using an array. 1. You may NOT use any of the collection classes in Java library like ArrayList or Vector or any other java collection class. 2. You must use simple java Arrays as we discussed in class during the BookCollection demo. • The name of your collection class should include the name of your Thing. For example, if your Thing is called Country, then your collection class should be called CountryCollection. • Your collection class should include three instance variables as follows: 1. name: a String that represents a given name to a collection. 2. numItems: an int that represents the current number of items in the collection. 3. items: Thing[] which is an array that stores references to Thing objects. • Implement a constructor for your collection class that takes two input parameters that represent (1) the collection name, and the maximum number of elements that can be stored in your collection. • Implement the following methods in your collection class: 1. add: a method that takes one input parameter of type Thing. The method adds the input thing to the collection. 2. add: overload the add method by implementing another add method that takes three input parameters and the method uses these inputs to instantiate an object of type Thing and adds it to the collection. 3. size: a method that returns the number of objects in the collection. 4. toString: a method that returns a String representation of the collection that includes all elements that are stored in the collection. The output string must be nicely formatted in a tabular format. For example, a list of students is to be displayed as follows: name grade major ————————— John 20 CS Eric 25 CIT Hanna 30 Math Reem 27 CS5. total: this method uses the int instance variable of the Thing class. Basically, the method calculates and returns the sum of the int instance variable of all objects stored in the collection. For example, in the student collection, this method finds the sum of age of all students in the list. 6. greatest: this method returns the object with the maximum value in the int attribute. 7. countCategory: this method takes one input parameter of type String that represent one category of things in your collection (e.g., the input is ‘red’ in a collection of Cars with ‘color’ attribute). The method counts and returns the number of objects in the collection that falls in this category (e.g., the number of ‘red’ cars). Note that String comparison must be case insensitive. 8. contains: this method takes one input parameter of type Thing. The method searches for the input thing in the collection and returns true or false based on whether the thing is found or no. Note, that you have to use the equals method to compare the equality of classes. 9. countOccurances: this method takes one input parameter of type Thing and returns as output how many copies of the input thing exist in the collection. Note that things must be compares using the equals method. Part C: Implement your Driver class Implement a Driver class that works as follows: • creates a collection class that can hold up to 10 things. • uses the add methods to insert 5 items in the collection. You may use any arbitrary values in in the objects to be inserted. • The driver then calls the methods 3 through 9 in order. Note that you do not have to use a Scanner to read any inputs from the user. On the other hand, use hard coded values for the different methods’ inputs. Grading Your grade in this assignment is based on the following: • Your submission meets specifications as described above. • Add appropriate comments to your code. • Variable names should convey meaning. • At the top of each Java file, include your name, a brief description of the program and what it does and the due date. • All code blocks must be indented consistently and correctly. Blocks are delimited by opening and closing curly braces. Opening and closing curly braces must be aligned consistently. • You must use the exact same name (including upper case and lower-case letter) for all methods as specified in the above description. • The output of our program must be nicely formatted. • You must follow the method requirements in terms of the number and data type of input parameters and the output data type. • The program is robust with no runtime errors or problems. • The programs should display your name. Part 2 Instructions • Zip up Part1 and name it i.e. DillonArraysOfObjectCollectionPart1, but Do Not submit it. Continue to Part2. • Part2 is going to build on Part 1. • After completion of Part2 and testing all your methods in the ThingDriverCollection, follow the steps in Part2 to submit your project. • Part1 and Part 2 will be in separate .zip folders, but the final submission will in one project folder. • If you have questions, please email me way before the deadline. Do Not email 1 or 2 fays before the due date. Email me in advance so I can have ample time to respond.
In this assignment, you will implement a Java application, called RetailStoreApplication, that can be used in a retail store. The application is to be implemented using three classes, called RetailItem, CashRegister, and RetailStoreDriver. Name the default package retail. The description of these classes is below. Problem Description class RetailItem The RetailItem class holds data about an item in the retail store. The class should have the following instance variables: 1. description: a String variable that holds a brief description of the item. 2. unitsOnHand: an int variable that holds the number of units currently in inventory. 3. price: a double variable that holds the item’s retail price in dollars. Implement the following methods in the RetailItem class: 1. A constructor that accepts only two arguments to initialize only the description and price instance variables and it sets the unitsOnHand to zero. Note that the order of inputs to the constructor must be in the same order as the field are listed above. 2. Getter (i.e., accessor) methods for each one of the instance variables. 3. toString:amethodthatreturnsanicelyformattedstringdescriptionoftheitem where all the item’s attributes are displayed in one line separated by tabs. For example: Jacket 12 59.54. addUnits: a method than takes a positive number (of type int) and adds that number of items to unitsOnHand. The method does not return anything. 5. getUnits: a method than takes a number (of type int) and subtracts that number from the item’s unitsOnHand. The method should return true or false based on whether the input quantity is less than or greater than the current number of units on hand. For example, if the number units on hand is 10 and the input quantity is 5, then the method updates the units on hand to be 5 (or 10-5) and returns true. On the other hand, if the current number of units on hand is 10 and the required quantity is 12, then the method does not update the units on hand and returns false. 6. changePrice:amethodthattakesanamount(oftypedouble)asinputandthe method then adds the input amount to the item’s price. The method does not return anything. Note that the input amount can be either positive or negative to increase or decrease the item’s price. Note also that the method should display an error message and do not change the price if changing the price will cause the price to be equal to or less than zero. 7. equals: a method to test the equality of two retail items where two items are considered to be equal if they have the same description and the same price. 8. totalValue: a method that calculates and returns the total inventory value for the retail item where the total value equals to the number of units on hand multiplied by the unit’s price. Important Requirements • The output of our program must be nicely formatted. • Method names and variable names must exactly match (case sensitive) the assignment requirements. • The program should display your name at the end. • At the top of the Java files, include a comment with your name, a brief description of the program and what it does and the due date. • Add appropriate comments to your code. • All code blocks must be indented consistently and correctly. Blocks are delimited by opening and closing curly braces. Opening and closing curly braces must be aligned consistently. • Variable names should convey meaning. • The program must be written in Java and submitted via D2L. Test and verify • Test your Retail class by adding a RetailStoreDriver to the RetailStoreApplication and instantiating 2 RetailItem objects. Print the details of the objects. Invoke all the methods of the RetailItem class on one of the objects. • If you are at this point, and have successfully completed Part1. Please move on to Part2.Problem Description Building on Part1, follow the instructions below to add the CashRegister to the RetailStoreApplication class. At this point you should already have a RetailStoreDriver from Part1 and have test the methods in the RetailItem class.. The CashRegister and the RetailStoreDriver should both be in the retail package. To receive full credits, create a video recording less than 10 minutes with your face on camera describing the additional changes to the code. Also upload the java source code. class CashRegister The CashRegister simulates the sale of a retail item where a cash register is identified by the following instance variables: 1. clerk: a String that represents the name of the employees who processes the purchase. 2. item: a RetailItem that represents the item being sold. 3. quantity: an int variable that represents the number of units being sold of that item. Implement the following methods for the CashRegister class: 1. A constructor that takes as input (1) the clerk’s name, (2) a RetailItem Data type, and (3) a number to represents the number of units to be purchased. You can assume that the input quantity is always less than the number of units on hand for the given item. The constructor should use the item’s getUnits method to modify the item’s units on hand by subtracting the quantity to be purchased. 2. Getter methods for all the instance variables. 3. getSubTotal: a method that calculates and returns the sub total of the sale which the quantity being sold multiplied by the item’s price. 4. getItemAvailabilty: this method returns the number of available unitsOnHand of the items being purchased.5. modifyQuantity: a method that takes a number as input and the method adds this number to the current quantity. Note that the input number may be positive or negative to either increase or decrease the purchased quantity. This method should modify the item’s units on hand accordingly. For example, if 2 more units are added on the quantity, then 2 units should be subtracted from the item’s units on hand. Similarly, if 2 units to be subtracted from the quantity, then the 2 units should be added back to the item’s units on hand. 6. getTax: a method that takes a double input that represents the tax rate (e.g., 0.03 for 3% tax) and the method then calculates and returns the amount of sales tax on the current purchase. 7. getTotal: a method that returns the total of the sale which is the sum of the subtotal and tax. The method should take a double input that represents the tax. 8. toString: a method that returns a string representation of the cash register item that includes clerk’s name, details of the item, quantity to be sold, and the sub total sale price. Note that the output string must be nicely formatted with all the data listed in one line. Class RetailStoreDriver If you haven’t already, crate a driver class to test all the methods that you implemented in both the RetailItem and CashRegister classes. Basically, the driver should include the following actions: • Creates two items with your choice of description and price. • Add 1000 units to the first item and 2000 units to the second item. • Test all the methods of the RetailItem class on the two items. • Create two cash registers, for each one of the items that are created in the previous step. • Test all of the methods of the CashRegister class on the two objects that are created in the previous step. Important Requirements • The output of our program must be nicely formatted. • Method names and variable names must exactly match the assignment requirements. • The program should display your name at the end. • At the top of the Java files, include a comment with your your name, a brief description of the program and what it does and the due date. • Add appropriate comments to your code. • All code blocks must be indented consistently and correctly. Blocks are delimited by opening and closing curly braces. Opening and closing curly braces must be aligned consistently. • Variable names should convey meaning. • The program must be written in Java and submitted via D2L.Submission Instructions • Draw a UML diagram of your application that includes the RetailItem and CashRegister classes but not the RetailStoreDriver class. Draw the UML in a word document and upload that document to D2L. • Follow the following steps to upload your code to D2L: o Create a java project and call it RetailStoreApplication (e.g., mine will be called DillonRetailStoreApplication). o Create three.java files as described above. o Archive only your .java files into one zip file using Eclipse using the following steps: ▪ In Eclipse Project Explorer, right click on the src folder of the project and click on Export. Note that you just include only the src folder and do not include the bin or any other folder. ▪ Choose General->Archive File and click Next. Use the Browse key to choose a folder to store the archive file on your hard drive and give the file the same name as your project (e.g., DillonAssginment4.zip), then click Save, then click Finish. ▪ Upload the .zip file you created to the D2L folder called Assignment 4. It is important that you upload only one zip file. Your assignment will not be graded if you upload individual .java files to the drop box.
Problem Description class Music Download the MyMusicApp project from D2L week#7 folder and import it into your Eclipse IDE. Review the Music class details to familiarize yourself with the implementation. Base on your knowledge of Objects, add a toString() method to the class. Note: Make sure that the completed assignment passes the “is-a” relationship test of superclass and subclasses: Note that all of these are valid superclass and subclasses relationship. Relative (superclass); Sister, Brother, Aunt, Uncle (subclasses) Parent (superclass); Mom, Dad (subclasses) Appliance (superclass); Stove, Refrigerator, Oven, Dishwasher (subclasses) Animal (superclass); Dog, Cat, Hamster, Tiger (subclasses) Publication (superclass); Book, Magazine, Newspaper (subclasses) class SubClass1 Choose any genre of music (i.e. Pop, Jazz, Rock etc.); however, it MUST extend the parent class. Your subclass should contain 2 – 3 additional variables relevant to the genre. The subclass must have a parameterize constructor that calls the Music class constructor and pass the necessary variables to initialize the parents instance variables. The constructor should also initialize the variables within Suclass1. Override the toString() method of the parent class and print the details of both the parent class and Subclass1. Override the increaseVolume() method in the Music class and change the implementation so that it is specific for this class. Implement a method call nameThatTune(), that returns the title of the Subcass1. In this assignment, you will implement a Java application, called MyMusicApp, which can be used to manage a playlist. The application is to be implemented using three classes, a superclass Music, which will be provided. Base on the class lecture you’ll create two subclasses. The description of these classes is below. To receive full credits, create a video recording less than 10 minutes with your face on camera describing your code step by step. Upload the java package as well. class SubClass2 Choose any genre of music (i.e. Pop, Jazz, Rock etc.); however, it MUST extend the parent class. Your subclass should contain 2 – 3 additional variables relevant to the genre. This must be different from the previous variable established for SubClass1. The subclass must have a parameterize constructor that calls the Music class constructor and pass the necessary variables to initialize the parents instance variables. The constructor should also initialize the variables within Suclass2. Override the toString() method of the parent class and print the details of both the parent class and subclass1. Implement a method call nameThatTune(), that returns the title of the Subcass2. class PlaylistDriver Your driver class should do the following actions: Instantiate three objects: One of data type Music. One of data type Subclass1. (i.e. Pop, Jazz, Rock etc.) One of data type Subclass2, (i.e. Pop, Jazz, Rock etc.) Call/invoke all the method in the Music class. Call/invoke all the method in Subclass1. Call/invoke all the method in Subclass2. Call/invoke the Music methods on Subclass1 and vice versa. Describe what happens? Instantiate a Music object and assign it to the Subclass1 reference variable. o Call all the methods in the Subclass1 again. o What happens? Add comments in your code to describe any errors the code encounters. Comment out the line of code with the error. Instantiate a Subclass2 object and assign it to the Music reference variable. o Call the methods in the Music class again. o What happens? Add comments in your code to describe any errors the code encounters. Comment out the line of code with the error. Note: Hover your mouse over any code underline with a red line to display the error. Important Requirements The output of our program must be nicely formatted. The programs should display your name. At the top of the program include your name, a brief description of the program and what it does and the due date. Add appropriate comments to your code. All code blocks must be indented consistently and correctly. Blocks are delimited by opening and closing curly braces. Opening and closing curly braces must be aligned consistently. Variable names should convey meaning. The program must be written in Java and submitted via D2L. Submission Instructions Follow the following steps to upload your code to D2L: o Create a java project and call it Assignment4 (e.g., mine will be called DillonAssignment4) o Create one.java files to solve the problem described above. Export your .java file into a zip file using Eclipse using the following steps: In Eclipse Project Explorer, right click on the src folder of the project and click on Export. Choose General then Archive File and click Next. Use the Browse key to choose a folder to store the archive file on your hard drive and give the file the same name as your project (e.g., DillonAssignment4.zip), then click Save, then click Finish. Upload the .zip file you created to the D2L folder called Assignment4. It is important that you upload only one zip file. Your assignment will not be graded if you upload individual .java files to the drop box.