Java. Write a call to the method majorKeyso that the println statement will not
ID: 3842875 • Letter: J
Question
Java.
Write a call to the method majorKeyso that the println statement will not generate a syntax error.
import java.util.Scanner;
public class FinalCall {
public static void main (String args[]) {
Scanner keyboard = new Scanner(System.in);
int majIndex = 7;
char majorValue, sharpe[] = {'F', 'C', 'G', 'D', 'A', 'E', 'B'};
String opusName = keyboard.nextLine();
// the call to majorKey goes here
System.out.println("Major key: " + majorValue);
}
public static char majorKey(char key[], String name, int majIndex ) {
char thiskey = key[majIndex%7];
for (int i = 1; i < key.length; i++)
if (key[i] != 'C'))
return key[i];
if (name.equals("major"));
return thiskey;
else
return 'C';
}
}
Explanation / Answer
FinalCall.java
import java.util.Scanner;
public class FinalCall {
public static void main (String args[]) {
Scanner keyboard = new Scanner(System.in);
int majIndex = 7;
char majorValue, sharpe[] = {'F', 'C', 'G', 'D', 'A', 'E', 'B'};
String opusName = keyboard.nextLine();
// the call to majorKey goes here
System.out.println("Major key: " + majorKey(sharpe,opusName,majIndex));
}
public static char majorKey(char key[], String name, int majIndex ) {
char thiskey = key[majIndex%7];
for (int i = 1; i < key.length; i++)
if (key[i] != 'C')
return key[i];
if (name.equals("major"))
return thiskey;
else
return 'C';
}
}
Output:
good morning
Major key: G
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.