Answered You can hire a professional tutor to get the answer.
it has more info and examples Instructions: Java files will be compiled and tested using the following syntax on a Windows desktop: javac Problem1.
I can send you the attachment as well... it has more info and examples
Instructions:
Java files will be compiled and tested using the following syntax on a Windows desktop:
javac Problem1.java
java Problem1
All java files must compile using the command line and using java version 1.8.0_151
Each java file submitted is to include commented code as well as your name, course number
and date.
All java source files should be submitted in a zip package. For Homework 2, you will submit one
file called homework2.zip to d2l. The file homework2.zip should contain the following files:
Problem1.java
Problem2.java
Problem2.java
Problem4.java
Problems will be graded on the following:
● Commenting of code including but not limited to variables, classes
● Functions correctly based on tested use cases
● Neatly formatted code and conciseness.
Programs that do not compile will not receive credit.
Problem 1 (20 points)
Write class that contains the following two methods:
/** Convert from Celsius to Fahrenheit */
public static double celsiusToFahrenheit(double celsius)
/** Convert from Fahrenheit to Celsius */
public static double fahrenheitToCelsius(double fahrenheit)
The formula for the conversion is:
fahrenheit = (9.0 / 5) * celsius + 32
celsius = (5.0 / 9) * (fahrenheit - 32)
ICS 141 - Spring 2018
Homework 2
Due 2/27/17
Chapters 6-8
80 points
The user should be asked for two command line input arguments, the first being either C or F for
celsius and fahrenheit and the next for the temperature. The program should then output the
appropriate conversion. Here is a sample command line output of the program:
Problem 2 (20 points)
Credit card numbers follow certain patterns. A credit card number must have between 13
and 16 digits. It must start with:
4 for Visa cards
5 for Master cards
37 for American Express cards
6 for Discover cards
In 1954, Hans Luhn of IBM proposed an algorithm for validating credit card numbers.
The algorithm is useful to determine if a card number is entered correctly or if a credit
card is scanned correctly by a scanner. Almost all credit card numbers are generated
following this validity check, commonly known as the Luhn check or the Mod 10 check,
which can be described as follows (for illustration, consider the card number
ICS 141 - Spring 2018
Homework 2
Due 2/27/17
Chapters 6-8
80 points
4388576018402626):
Step 1) Double every second digit from right to left. If doubling of a digit results in a two-digit
number, add up the two digits to get a single-digit number.
2 * 2 = 4
2 * 2 = 4
4 * 2 = 8
1 * 2 = 2
6 * 2 = 12 (1 + 2 = 3)
5 * 2 = 10 (1 + 0 = 1)
8 * 2 = 16 (1 + 6 = 7)
4 * 2 = 8
Step 2) Now add all single-digit numbers from Step 1.
4 + 4 + 8 + 2 + 3 + 1 + 7 + 8 = 37
Step 3) Add all digits in the odd places from right to left in the card number.
6 + 6 + 0 + 8 + 0 + 7 + 8 + 3 = 38
Step 4) Sum the results from Step 2 and Step 3.
37 + 38 = 75
Step 5) If the result from Step 4 is divisible by 10 and the card starts with an acceptable digit,
the card number is valid. Otherwise, it is invalid..
Write program that prompts the user to enter a credit card number as a long integer.
Display whether the number is valid or invalid.
Here are sample runs of the program:
ICS 141 - Spring 2018
Homework 2
Due 2/27/17
Chapters 6-8
80 points
Problem 3 (20 points)
A school has 100 lockers and 100 students. All lockers are closed on the first day of
school. As the students enter, the first student, denoted S1, opens every locker. Then the
second student, S2, begins with the second locker, denoted L2, and closes every other
locker. Student S3 begins with the third locker and changes every third locker (closes it if
it was open, and opens it if it was closed). Student S4 begins with locker L4 and changes
every fourth locker. Student S5 starts with L5 and changes every fifth locker, and so on,
until student S100 changes L100.
After all the students have passed through the building and changed the lockers, which
lockers are open?
Write program to find your answer.
(Hint: Use an array of 100 boolean elements, each of which indicates whether a locker is
open (true) or closed (false). Initially, all lockers are closed.)
Here is a sample run of the program with some of the lockers partially blurred out:
ICS 141 - Spring 2018
Problem 4 (20 points)
Write the following function that tests whether a two-dimensional list has four consecutive
numbers of the same value, either horizontally, vertically, or diagonally.
public static boolean isConsecutiveFour(int[][] values)
Write test program that prompts the user to enter a 6x6 matrix consisting of numbers 0-9. The
program displays true if the list contains four consecutive numbers with the same value.
Otherwise, the program displays false.
Here are some sample runs of the program:
7s diagonally
ICS 141 - Spring 2018
Homework 2
Due 2/27/17
Chapters 6-8
80 points
2s horizontally
0s vertically
No 4 in a row found