Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Assignment Tasks Note1: Students can start to work now on partial tasks. Other tasks need the knowledge in 2/1 lecture. After we cover 2/1 lecture,
Assignment Tasks Note1: Students can start to work now on partial tasks. Other tasks need the knowledge in 2/1 lecture. After we cover 2/1 lecture, you can complete the leftover tasks in the entire assignment. Note2: In Java, the result of division between two integers rounds to the nearest integer. For example, the result of 12/5 is 2 if 12 and 5 are int type. To get the correct result 2.4 in practice, you need to use the Type Casting in Java, which explicitly converts one type to another type. For example, (double) 12/5 will result in 2.4 by adding (double) before 12. For example, 1 Part1: Design and implement a Java program to read the travel length and time to calculate the travel speed in m/s (meter per second) and km/h (kilometer per hour). Check the following section for the detailed requirements of your program. The requirements are as follows: 1. The name of the class is called SpeedCalc (also means the file name is SpeedCalc.java) 2. The class has at least two integer variables to store the input travel length and time 3. The class has at least two methods: 1. readlnput(): This method should use Scanner class to read the two input variables: travel length and travel time 2. calcSpeed(): This method should calculate the speed in m/s and km/h, and then output to console. 3. The class has at least two methods: 1. readlnput(): This method should use Scanner class to read the two input variables: travel length and travel time 2. calcSpeed(): This method should calculate the speed in m/s and km/h, and then output to console. 3. Note: A main() method should also be included in the class. 4. Program Design and Good Coding Style Requirements: Your source code must be properly indented and contain adequately comments for class, methods, variables, etc. o In the beginning of your Java class file, specify the following items: Your name, the assignment number for this program, the date you create the file . The problem description that defines your application Enumerate (list) the goals of your application Enumerate (list) the inputs of your application Enumerate (list) the outputs of your application o Before each method in your class, specify the following items: . Specify the purpose of the corresponding method Enumerate the possible inputs and outputs of the corresponding method . Write down the pseudocode to implement the corresponding method o Others comments if need for variables, inside method implementation A template for the above specification in a comment block is shown as follows. Please fill in right after the colon. . /* * Class name: ur app . 1 ale (is) Enumerate (list) the outputs of your application o Before each method in your class, specify the following items: Specify the purpose of the corresponding method Enumerate the possible inputs and outputs of the corresponding method . Write down the pseudocode to implement the corresponding method Others comments if need for variables, inside method implementation A template for the above specification in a comment block is shown as follows. Please fill in right after the colon. /* * Class name: * Author: * Date: * Problem: * Goals: * Inputs: * Outputs: * Required packages: * Inputs: * Outputs: * Required packages: * Test cases: * Pseudo code: Step 1: ... * Step 2: ... * Step 3: ... */ 5. Output: Here is a sample output Problems @ Javadoc Declaration Search 2 Console X Speed Calc (Java Application] /Library/Java/JavaVirtualMachir Enter the road length (km): 100 Enter the travel time (hour): 2 The travel speed in (km/h) is 50.0 The travel speed in (m/s) is 13.888889 num1 = nl ; num2 = n2 ; } public int add() { return num1 + num2; } public int subtract() { //TODO: add missing code after this line } public int multiply() { //TODO: add missing code after this line } public double divide() { //TODO: add missing code after this line } public static void main(String args []) { //TODO: add missing code after this line } } Check the following section for the detailed specifications of your program. public double divide() { //TODO: add missing code after this line } public static void main(String args []) { //TODO: add missing code after this line } } Check the following section for the detailed specifications of your program. 2.2 Class Design Specification 1. The name of the class is called SimpleMath (also means the file name is SimpleMath.java) 2. The class has two integer variables (num1 and num2) to store the two input operators 3. The class has five methods: a. SimpleMath(): This constructor method has two input arguments to initialize the values of num1 and num2. This method is already completed. b. add(): This method calculate the addition of two numbers num1 and num2. This method is already completed. C. substract(): This method calculate the subtract of two numbers: num1 - num 2. This method is not completed. d. multiply(): This method calculate the multiplication of two numbers num1 and num2. This method is not completed. e. divide(): This method calculate the division of two numbers: num1 / num2. Different from the other methods, this method need to return a double because the division operator on two integers can result to a decimal number. This method is not method is not completed. d. multiply(): This method calculate the multiplication of two numbers num1 and num2. This method is not completed. e. divide(): This method calculate the division of two numbers: num1 / num2. Different from the other methods, this method need to return a double because the division operator on two integers can result to a decimal number. This method is not completed. Hint: you need to cast either one of the two operators into float or double to get the correct result. f. main(): This method will create at least one instance of the SimpleMath class with two input integers (you can choose any numbers). Then using System.out.println to print the results of addition, subtraction, multiplication, and division of those two numbers by using the four methods above. This method is not completed. 4. Output: Here is a sample output Problems @ Javadoc Declaration Search Console X Simple Math (Java Application] /Library/Java/JavaVirtual Machi 12 + 5 = 17 12 - 5 = 7 12 * 5 = 60 12 / 5 = 2.4000000953674316 2.3 Program Design and Good Coding Style Requirements Your source code must be properly indented and contain adequately comments for class, methods, variables, etc. In the beggining of your Java class file, specify the following items: o Your name, the assignment number for this program, the date you create the file SimpleMath (Java Application) /Library/Java/JavaVirtual Machi 12 + 5 = 17 12 - 5 = 7 12 * 5 = 60 12 / 5 = 2.4000000953674316 2.3 Program Design and Good Coding Style Requirements Your source code must be properly indented and contain adequately comments for class, methods, variables, etc. In the beggining of your Java class file, specify the following items: Your name, the assignment number for this program, the date you create the file The problem description that defines your application Enumerate (list) the goals of your application Enumerate (list) the inputs of your application Enumerate (list) the outputs of your application Before each method in your class, specify the following items: Specify the purpose of the corresponding method Enumerate the possible inputs and outputs of the corresponding method o Write down the pseudocode to implement the corresponding method Others comments if need for variables, inside method implementation o o Submission You need to submit the following results: 1. Capture the outputs in Eclipse Console for the above 2 parts using screenshot. Put the captured images in a PDF file called output.pdf 2. Source code: Submit exported project Assignment1 folder (DO NOT compress it into .zip) Assignment Tasks Note1: Students can start to work now on partial tasks. Other tasks need the knowledge in 2/1 lecture. After we cover 2/1 lecture, you can complete the leftover tasks in the entire assignment. Note2: In Java, the result of division between two integers rounds to the nearest integer. For example, the result of 12/5 is 2 if 12 and 5 are int type. To get the correct result 2.4 in practice, you need to use the Type Casting in Java, which explicitly converts one type to another type. For example, (double) 12/5 will result in 2.4 by adding (double) before 12. For example, 1 Part1: Design and implement a Java program to read the travel length and time to calculate the travel speed in m/s (meter per second) and km/h (kilometer per hour). Check the following section for the detailed requirements of your program. The requirements are as follows: 1. The name of the class is called SpeedCalc (also means the file name is SpeedCalc.java) 2. The class has at least two integer variables to store the input travel length and time 3. The class has at least two methods: 1. readlnput(): This method should use Scanner class to read the two input variables: travel length and travel time 2. calcSpeed(): This method should calculate the speed in m/s and km/h, and then output to console. 3. The class has at least two methods: 1. readlnput(): This method should use Scanner class to read the two input variables: travel length and travel time 2. calcSpeed(): This method should calculate the speed in m/s and km/h, and then output to console. 3. Note: A main() method should also be included in the class. 4. Program Design and Good Coding Style Requirements: Your source code must be properly indented and contain adequately comments for class, methods, variables, etc. o In the beginning of your Java class file, specify the following items: Your name, the assignment number for this program, the date you create the file . The problem description that defines your application Enumerate (list) the goals of your application Enumerate (list) the inputs of your application Enumerate (list) the outputs of your application o Before each method in your class, specify the following items: . Specify the purpose of the corresponding method Enumerate the possible inputs and outputs of the corresponding method . Write down the pseudocode to implement the corresponding method o Others comments if need for variables, inside method implementation A template for the above specification in a comment block is shown as follows. Please fill in right after the colon. . /* * Class name: ur app . 1 ale (is) Enumerate (list) the outputs of your application o Before each method in your class, specify the following items: Specify the purpose of the corresponding method Enumerate the possible inputs and outputs of the corresponding method . Write down the pseudocode to implement the corresponding method Others comments if need for variables, inside method implementation A template for the above specification in a comment block is shown as follows. Please fill in right after the colon. /* * Class name: * Author: * Date: * Problem: * Goals: * Inputs: * Outputs: * Required packages: * Inputs: * Outputs: * Required packages: * Test cases: * Pseudo code: Step 1: ... * Step 2: ... * Step 3: ... */ 5. Output: Here is a sample output Problems @ Javadoc Declaration Search 2 Console X Speed Calc (Java Application] /Library/Java/JavaVirtualMachir Enter the road length (km): 100 Enter the travel time (hour): 2 The travel speed in (km/h) is 50.0 The travel speed in (m/s) is 13.888889 num1 = nl ; num2 = n2 ; } public int add() { return num1 + num2; } public int subtract() { //TODO: add missing code after this line } public int multiply() { //TODO: add missing code after this line } public double divide() { //TODO: add missing code after this line } public static void main(String args []) { //TODO: add missing code after this line } } Check the following section for the detailed specifications of your program. public double divide() { //TODO: add missing code after this line } public static void main(String args []) { //TODO: add missing code after this line } } Check the following section for the detailed specifications of your program. 2.2 Class Design Specification 1. The name of the class is called SimpleMath (also means the file name is SimpleMath.java) 2. The class has two integer variables (num1 and num2) to store the two input operators 3. The class has five methods: a. SimpleMath(): This constructor method has two input arguments to initialize the values of num1 and num2. This method is already completed. b. add(): This method calculate the addition of two numbers num1 and num2. This method is already completed. C. substract(): This method calculate the subtract of two numbers: num1 - num 2. This method is not completed. d. multiply(): This method calculate the multiplication of two numbers num1 and num2. This method is not completed. e. divide(): This method calculate the division of two numbers: num1 / num2. Different from the other methods, this method need to return a double because the division operator on two integers can result to a decimal number. This method is not method is not completed. d. multiply(): This method calculate the multiplication of two numbers num1 and num2. This method is not completed. e. divide(): This method calculate the division of two numbers: num1 / num2. Different from the other methods, this method need to return a double because the division operator on two integers can result to a decimal number. This method is not completed. Hint: you need to cast either one of the two operators into float or double to get the correct result. f. main(): This method will create at least one instance of the SimpleMath class with two input integers (you can choose any numbers). Then using System.out.println to print the results of addition, subtraction, multiplication, and division of those two numbers by using the four methods above. This method is not completed. 4. Output: Here is a sample output Problems @ Javadoc Declaration Search Console X Simple Math (Java Application] /Library/Java/JavaVirtual Machi 12 + 5 = 17 12 - 5 = 7 12 * 5 = 60 12 / 5 = 2.4000000953674316 2.3 Program Design and Good Coding Style Requirements Your source code must be properly indented and contain adequately comments for class, methods, variables, etc. In the beggining of your Java class file, specify the following items: o Your name, the assignment number for this program, the date you create the file SimpleMath (Java Application) /Library/Java/JavaVirtual Machi 12 + 5 = 17 12 - 5 = 7 12 * 5 = 60 12 / 5 = 2.4000000953674316 2.3 Program Design and Good Coding Style Requirements Your source code must be properly indented and contain adequately comments for class, methods, variables, etc. In the beggining of your Java class file, specify the following items: Your name, the assignment number for this program, the date you create the file The problem description that defines your application Enumerate (list) the goals of your application Enumerate (list) the inputs of your application Enumerate (list) the outputs of your application Before each method in your class, specify the following items: Specify the purpose of the corresponding method Enumerate the possible inputs and outputs of the corresponding method o Write down the pseudocode to implement the corresponding method Others comments if need for variables, inside method implementation o o Submission You need to submit the following results: 1. Capture the outputs in Eclipse Console for the above 2 parts using screenshot. Put the captured images in a PDF file called output.pdf 2. Source code: Submit exported project Assignment1 folder (DO NOT compress it into .zip)
Step 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