23 Jun Java – RentalCar – Homework 10, INBOX FOR SOLUTION
General description for homework 10: In this homework, you need to first develop a class using these two OOP principles: data abstraction and encapsulation, and then create an application class to make use of the encapsulated class developed above. After finishing this homework, you will demonstrate your skill in creating and using OOP class. Here is the detail description for homework 10: Create a Java project in Eclipse. This project has two java files (classes): RentalCar.java and JohnDoeHw10.java First, create a new java file named RentalCar.java. At the beginning of this file, add an appropriate program header similar to what you did in “homework 1–part B–step 3”. Then, right after the program header is the definition line for public class RentalCar. Then in the body of this class RentalCar, do the following: 1. define two private data members: car type, which is String type, and the possible value of supported car types may include: “sedan”, “minivan”, “suv”, etc; miles traveled, which is double type. 2. define a private static type variable which records down the total number of cars that have been rented. The initial value of this variable is 0. 3. define a public constant (i.e., public static final) variable of double type, which holds the charges per mile traveled by the rental car. The value is 0.25, i.e., 0.25 dollars will be charged for every mile traveled. 4. define two public constructors, the first one is the default constructor with no parameter, and the second one has two parameters to initialize the two non-static private data members of the class, and you are required to use java keyword this in the constructor with parameters. Inside each constructor, you need to increase the total number of rental cars variable by one. 5. for each private non-static data member, provide one public getter and one public setter. For the private static variable, provide only a getter. Notice that the getter of static variable must be a static method. Refer to textbook sec 8.9 source file “CircleWithPrivateDataFields.java” on how to create getter for static data. You are required to use java keyword this in the setters. 6. provide a public method named calcRentalFee . This method returns the rental fee for each rental car, which is calculated by multiplying the miles travelled with the charge per mile. The charge per mile is the public constant variable defined of this class defined in step 3 above. This method does NOT need any formal parameter, and it returns a double type. This method is a non-static method. 7. provide a public method named isOilChangeNeeded. This method returns a boolean type value, which indicates whether an oil change is needed or not. This method needs only ONE formal parameter, which is a double type variable named milesThreshold. The logic of this method is here: if the miles traveled is more than or equal to the milesThreshold, then an oil change is needed; otherwise, it is not needed. Attention: milesThreshold is a formal parameter of method isOilChangeNeeded, and it is NOT a data member of the RentalCar class, therefore, do not make the mistake of setting milesThreshold as a private data member of the RentalCar class, and if you do so, you are in the wrong track!!!! Secondly, create a new java file named JohnDoeHw10.java, which has the application class JohnDoeHw10 (replace JohnDoe with your first and last name). At the beginning of JohnDoeHw10.java, add an appropriate program header as what you did in “homework 1–part B — step 3”. This class has only one method name main, and in the first line of the main method, insert a statement to output your name, course section and semester info, and refer to “homework 1 — part B — step 4” for the same requirement of this output line. Then do the following: 1. create two RentalCar objects using the constructor with two parameters, plug in the data below as the actual parameters of the constructor. Each line below contains the two actual parameters for one object: “suv” 500.0 “sedan” 1200.0 , where the 1st column is car type, and the 2nd column is miles traveled. Refer to the modified file TestLoanClass.java in Moodle file “lesson10SrcDemo.zip”, on how myLoan object is created. 2. create the third RentalCar object using the default constructor. Then ask the user to input the two parameters with a Scanner type variable, and no GUI input is needed. Then use the setters to set the user input values into the third object. No data type or range checking of the input parameters is needed. Refer to the modified TestLoanClass.java in Moodle “lesson10SrcDemo.zip”, on how hisLoan is created. 3. ask the user to input a miles threshold, which is of double type. For example, a user input of 1200.0 means if a car travels 1200 miles or above, then an oil change is needed, otherwise, no need to perform oil change. This miles threshold value will be used in the next step to determine whether a car needs an oil change or not, for all the three rental car objects. 4. For each RentalCar object, invoke two methods: calcRentalFee () and isOilChangeNeeded () and store the results in two local variables, respectively. For method isOilChangeNeeded, you need to plug in the miles threshold variable obtained in step 3 above. In summary, you have 6 variables that store the results for three RentalCar objects. 5. For each of the three RentalCar objects, output its car type, its miles traveled, its rental fee, and whether an oil change is needed for this car. If the output information exceeds 80 columns, you need to output them in multiple lines, with each line less than 80 columns. Use System.out.printf() method, and format the rental fee with two digits after the decimal point, and miles travel with one digit after the decimal point. 6. Output the charge per mile for class RentalCar, and you need to use ClassName.publicStaticVariableName to access a public constant variable of a class. 7. Output the total number of cars created, and you need to use ClassName.publicStaticMethod() to invoke the getter for a private static variable. Thirdly, use Visual Paradigm for UML, Community Edition to create an UML class diagram for class RentalCar, and in this diagram, all data members and all method members should appear in the class diagram. Refer to document “DownloadAndUseVisualParadigmUML.docx” on how to create UML class diagram with Visual Paradigm for UML. Pay attention to how static members are being indicated in UML class diagram. Attention: create UML class diagram ONLY for class RentalCar, and no need to create UML class diagram for JohnDoeHw10. After the UML class diagram in created in VP for UML, export the diagram to an image file, and the required file name is RentalCar.jpg. Implementation requirements: • No need to use array in this homework. • File RentalCar.java contains only one class named RentalCar, and file JohnDoeHw10.java contains only one class named JohnDoeHw10. File RentalCar.java and file JohnDoeHw10.java are two different files. • In file RentalCar.java, you need to have two private non-static data members, and one private static member, and one public static final member. All methods are public, including: two constructors; one setter and one getter for each private non-static data member; one getter for the private static data member, and method calcRentalFee () and method isOilChangeNeeded (). • When coding House.java, please refer to file “CorrectSequence.java” in folder “chap8” from “lesson8SrcDemo.zip” for the correct sequence of components in an encapsulated class. The modified Loan.java follows the correct sequence strictly, which also serves as a reference for you. • In file JohnDoeHw10.java, you have only one method: the main method. • The signature and return type of the methods in these two classes have already been defined in the homework requirements, and you cannot change the signature and the return type of any method. • Add suitable comments in the source code. • Please read the above implementation details carefully BEFORE start coding. • In the constructor and setters, please use keyword this to point to object’s data fields in the heap. You can refer to the modified Loan.java on how keyword this keyword is used. • After finishing coding, you need to debug your program and test it multiple times with different input parameters supplied for each test run. This assignment has 20 points. Grading components is listed in the table below: Rental class created correctly main method implemented correctly Correct UMLclass diagram Code indent & align Header & code comment Naming convention Submit file format Program logic 4 4 3 4 1 1 1 2 The grading components are, but not limited to: code alignment and indentation, variable/method/class naming convention, programmer header, suitable comments, submitted file format, overall program logic. REMIND: If the submitted program does not compile or does not run, the highest grade you can earn is 5pts. What and where to submit: there are three files that you need to zip into file JohnDoeHw10.zip: • RentalCar.java • RentalCar.jpg (this is the exported image file of the UML class diagram for class RentalCar) • JohnDoeHw10.java Submit this zip file to Moodle homework 10 drop box. After submission, be sure to follow the VERIFICATION process: download your .zip file to a local folder in your computer, unzip the zip file and compile then run the Java program in Eclipse. If the verification process works correctly, then you have submitted the .zip file successfully in Moodle; if not, you need to fix the problem and re-submit. DO NOT zip any eclipse project folder into your submission zip file. How to zip multiple files: First, for all the three files that you need to zip, move or copy them into the same folder. Then hold the ctrl key in the keyboard, then left-click the mouse to select the three required files (two java files and one jpg file), and then right-click on any one of the selected java files to show the context menu, and then zip the selected files from the context menu. If the generated zip file name is not JohnDoeHw10.zip, then you need to change the zip file to the required name before submitting the zip file. I do not copy and paste file content from “RulesForIndentAndAlignCode.docx” here, but all the 5 rules in the document are still valid, and you should follow these 5 rules and write code with these 5 rules built into your coding habit. The naming convention in textbook Sec 2.8 should also be observed.
Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.
About Writedemy
We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.
How It Works
To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Are there Discounts?
All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.
