View the step-by-step solution to:

ASSIGNMENT 1 COMP-202B, Winter 2013, All Sections Due: Monday, January 28, 2013 (23: Graders have the discretion to impose penalties to students who...

answer it specifically
ASSIGNMENT 1 COMP-202B, Winter 2013, All Sections Due: Monday, January 28, 2013 (23:55) You MUST do this assignment individually and, unless otherwise specified, you MUST follow all the general instructions and regulations for assignments. Graders have the discretion to impose penalties to students who deviate from the general instructions and regulations; these penalties will take the form of deductions from the marks allocated for respect of instruc- tions and regulations. Part 1, Question 1, 2, 3: 0 points Part 2, Question 1: 30 points Part 2, Question 2: 50 points Part 2, Question 3: 20 points 100 points total Part 1 (0 points) Do NOT hand in this part, as it will not be graded. However, doing this exercise might help you to do the second part of the assignment (that will be graded). If you have difficulties with the questions of Part 1, then we suggest you go to one of the office hours; the TA can help you and work with you through the warm-up questions. Warm-up Question 1 (0 points) Create a file called , and in this file, declare a class called HelloWorld . This class should define only one method called main() . In the body of this method, use System.out.println() to display “ Hello world! ”. You can find such a class in the lecture slides; make sure you can compile and run it properly. Warm-up Question 2 (0 points) Consider the following 2-d matrix: ± a b c d ² Write a Java program that first reads 4 doubles, representing a,b,c, and d from the keyboard. It then outputs to the screen the determinant of the matrix. For a 2x2 matrix, the determinant is always equal to a * d - b * c Warm-up Question 3 (0 points) Suppose you know Merlin, an all-powerful wizard who provides you with the following curious method for multiplying any two numbers between 100 and 109: 1. The most significant digit will always be 1. 2. The next two significant digits will be the summation of the least significant digits of the the inputs. 3. The final two digits will be the product of the least significant digits of the inputs. 1
Background image of page 1
Some examples: First example: 105 × 107 = 11235: First Step: The most significant digit is 1 Second Step: The next two significant digits will be 12 : 5 + 7 = 12 Third Step: The final two digits will be 3 and 5 since 5 × 7 = 35. Write a program that prompts the user to enter two integers between 100 and 109 and then computes their product using Merlin’s method and outputs the result. Hint: to extract a digit out of an integer number use the integer division and modulo operators. Part 2 (30 + 50 + 20 = 100 points) The questions in this part of the assignment will be graded. Question 1 (30 points) Professor Mirrorolvsky would like you to assist him by writing a program that lets him figure out the inverse of any particular student number. Your program should prompt the user to enter their student number (a 4-digit number) and should display the inverse. For instance, if the student number is 2650, then your program should display 0562. You may assume that the user enters a proper input in the correct format. In case you already know more about Java than what we have seen in class so far, you might be tempted to use that knowledge to solve this question. However, to make it fair for everyone, you must solve this question without using Strings, ”if” statements or any sort of loops. Save your InvertID class in a file called (make sure you get the capitalization right). Question 2 (50 points) Suppose in 2100 an astronaut bids adieu to his twin sister and travels to planet X which is at distance d from the Earth. If his space transport can travel at speed v (which is close to the speed of light) and the journey takes t number of years to complete, theory of special relativity tells us that he’d have aged less than his twin sister. Namely, instead of his sister who is t years older, he ’d have aged t * ± years where ± = q 1 - ( v 2 c 2 ) and c is the speed of light. This thought experiment is called the Twin Paradox (see paradox for more information). Write a program that prompts the user to enter in the order listed here: the speed of his shuttle in percentage of speed of light (for instance, at 85 percent of the speed of light: v = 0 . 85 c the user would type 0.85), and the distance d to planet X in light years (for instance, the user can type 6.3). Then, your program should calculate and display the time on earth that has passed: t = 2 d v the time that the astronaut has aged: Save your TwinParadox class in a file called Hint : To compute the square root of a (non-negative) number, use Math.sqrt (for instance, Math.sqrt(4) will return 2). Page 2
Background image of page 2
Show entire document
Sign up to view the entire interaction

Top Answer

PFA attached... View the full answer

computerscience_8422649.rar - Preview not available

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.


Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online