HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavaMinor

Music note interval trainer

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
musictrainernoteinterval

Problem

This gives you one note and asks you go up or down the scale for a certain number:

```
///////////////////////////////
//// ClearConsole.java
///////////////////////////////

/**
* Created by IDEA on 06/12/14.
*/
public final class ClearConsole {
static void clear() {
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i new String[size]);
private String note;
public static BiMap noteMap = HashBiMap.create();
public static BiMap numberMap;

static {
for(int i=0; i 0) {
throw new IllegalArgumentException("You can only add to low notes (ABCDEFG)");
}
if(!this.isHigh() && number octaveNumber) {
throw new IllegalArgumentException(String.format("Maximum amount of increase or decrease is %d", octaveNumber));
}

int newNumber = getNumber() + number;
return new Note(newNumber);
}

@Override
public String toString() {
return String.format("Note('%s')", note);
}

// test
// public static void main(String[] args) throws Exception {
// Note n1 = new Note("A");
// Note n2 = n1.add(3);
// Note n3 = new Note(13);
// Note n4 = n3.add(-7);
// System.out.println(n1);
// System.out.println(n2);
// System.out.println(n3);
// System.out.println(n4);
// }

}

///////////////////////////////
//// Sheet.java
///////////////////////////////

import com.google.common.base.Joiner;

import java.util.ArrayList;
import java.util.List;

/**
* Created by IDEA on 06/12/14.
*/
public class Sheet {
private final static int lineLength = 70;
private final static int extraLineLength = 35;
private final static int notePos = 18;
private static String line;
private static String space;
private static String extraLine;
private static String extraSpace;
private List template = initTemplate();
private List sheet;

private static List initTemplate() {

Solution

-
I find this to be an effective, but smelly way to clear the console:

public final class ClearConsole {
    static void clear() {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < 1000; i++) {
            stringBuilder.append(String.format("%n"));
        }
        String s = stringBuilder.toString();
        System.out.println(s);
    }
}


There are better ways to go about this.

-
The real musical scale has half-steps. This code ignores that.

-
Looks like you've got a typo here:

hightNotes

Code Snippets

public final class ClearConsole {
    static void clear() {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < 1000; i++) {
            stringBuilder.append(String.format("%n"));
        }
        String s = stringBuilder.toString();
        System.out.println(s);
    }
}

Context

StackExchange Code Review Q#71916, answer score: 4

Revisions (0)

No revisions yet.