# Math代写 | Java代写 – Homework math

Math代写 | Java代写 – 这是一个利用java来解决数学代写问题的题目

### Homework math

Introduction

``````In this homework, you will practice writing javafunctions/methods to perform five simple pro-
ming techniques:
``````
1. Writing algorithms iteratively via while loops and/or for loops
2. Writing algorithms by recursion
3. Make good use of the reminder functions, modulo functions, and, common mathematical functions (e.g. the square root function) from Javas mathClass

### 4. Writing multiway conditional statements such as nestedif-elsestatements

1. Learn to create and access arrays to manipulate data

Guidelines

``````You must work on this homeowork individually. No teams are allowed.
Due date: Upload your submission on or before 6 pm, September 11, 2018. Our system will not
``````

Reading Onto Java , chapter 3 to 6, chapter 21 to 26, and, chapter 28.

### Programming exercise Follow the instructions given from the starting fileHW2.java, complete the

missing code. The overall requirements are divided into the following five questions:

Question 1 Compute the Leonardo numbers iteratively

The Leonardo numbers are a sequence of integers defined as follows:

### negative.) Use the functionleonardoIterto print a table of the results for inputs 0 through 9.

Question 2 Compute the Leonardo numbers by recursion

### Write a static methodpublic static int leonardoRec(int n) that computesleonardoRec(n)

by using recursion. (You may again assume that the input is always non-negative) Use the function

### leonardoRecto print a table of the results for inputs 0 through 9.

Question 3 Represent a deck of playing cards

Recall that a standard deck of playing cards are grouped into suits and ranks. We represent the 52 cards by using the numbers 0 , 1 ,… , 51 where, for the suits:

### The suits for the cards 3 , 7 , 11 , 15 ,… , 51 are spades ()

``````As for the ranks:
``````
• the rank for the card 0 , 13 , 26 , 39 are aces ( A ), the rank for the card 10 , 23 , 36 , 49 are jacks ( J ), the rank for the card 11 , 24 , 37 , 50 are queens ( Q ), and, the rank for the card 12 , 25 , 38 , 51 are kings ( K ).
• the rank for the cards 1 , 2 ,… , 9 are 2 , 3 , 4… , 10 accordingly.
• the rank for the cards 14 , 15 ,… , 22 are 2 , 3 , 4… , 10 accordingly.
• the rank for the cards 27 , 28 ,… , 35 are 2 , 3 , 4… , 10 accordingly.
• the rank for the cards 40 , 41 ,… , 48 are 2 , 3 , 4… , 10 accordingly.

Write static methods

### 2. public static String rankOf(int n)

that will, given a number from 0 ,… , 51 , compute the suit and the rank of that card (as coded by the number stated above) respectively. You may again assume that the input is always an integer lies in the range 0 to 51. After completing the two methods, follow the instructions given in the comments

### and complete the Java methodrunTestThree.

Question 4 Compute the solution(s) to a quadratic equation

An equation of the form

### ax^2 + bx + c = 0

is called a quadratic equation. The values of a , b and c represents constant values. Therefore

### represents a quadratic equation where a = 2 , b = 5 and c = 17. The values of x that satisfy a

particular quadratic equation are known as the roots of the the equation. They can be calculated by using the formula:

### b^2 4 ac

``````2 a
``````

### In the expression (1), the value b^2 4 ac is called the disriminant. When it is less than zero, the roots

of the equation, x 1 , and x 2 , are imaginary numbers.

### Write a static methoddouble quadSol(double a, double b, double c)which will return the

solution to the maximum of the quadratic equation when the discriminant is a non-negative num- ber. In this question, you are not responsible to handle the case when the discriminant is negative. In addition, you may assume the inputs a , b and c are non-zero numbers.

Question 5 Reversing the digits of an integer

### Write a static methodpublic static int reverse(int n)which will, given an integer n (which may

be negative), return a number that reverse the digits of the integer n. Your function should ensure that both non-negative and negative numbers are correctly handled. For example: