Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package music;
- import javax.swing.JOptionPane;
- public class musicc {
- public static void main(String[] args) throws Exception {
- int noteid;
- int notechange;
- boolean direction; //true = up, false = down
- int newnoteid;
- boolean debug = true; //PRINTS DEBUG INFO
- //GETS USER INPUT!
- noteid = musicc.getNoteId(); //gets noteid
- if (debug == true) {
- System.out.println("Note id: " + noteid); //debug
- }
- notechange = musicc.getNoteChange(); //gets note change
- if (debug == true) {
- System.out.println("Note change: " + notechange); //debug
- }
- direction = getDirection();
- if (debug == true) {
- System.out.println("Note direction: " + direction); //debug
- }
- //CALCULATIONS
- System.out.println("Starting Calculations...");
- notechange = notechange - 1;
- if (direction == false) {
- notechange = notechange * -1;
- }
- if (debug == true) {
- System.out.println("Note change/direction togther: " + notechange); //debug
- }
- newnoteid = noteid + notechange;
- if (debug == true) {
- System.out.println("Raw newnoteid: " + newnoteid); //debug
- }
- newnoteid = newnoteid % 7;
- if (debug == true) {
- System.out.println("Note id pre NF: " + newnoteid); //NF = negative fix //debug
- }
- while (newnoteid < 0) {
- newnoteid = newnoteid + 7; //brings value above negative by the octave
- }
- if (debug == true) {
- System.out.println("Note id post NF: " + newnoteid); //debug
- }
- String result = getNewNote(newnoteid);
- if (debug == true) {
- System.out.println("result: " + result); //debug
- }
- //RESULTS
- JOptionPane.showMessageDialog(null,"The note you landed on is " + result,"Results", JOptionPane.INFORMATION_MESSAGE);
- }
- public static int getNoteId() {
- String note;
- //asks for note
- Object[] possibilities = {"A", "B", "C", "D", "E", "F", "G"};
- note = (String)JOptionPane.showInputDialog(null,"What note do you want to start on?","Music Scale",JOptionPane.PLAIN_MESSAGE,null,possibilities,"A");
- while (note == null) { //makes sure if cancel is pressed it tries again
- JOptionPane.showMessageDialog(null,"Enter a note!", "Error!", JOptionPane.ERROR_MESSAGE);
- note = (String)JOptionPane.showInputDialog(null,"What note do you want to start on?","Music Scale",JOptionPane.PLAIN_MESSAGE,null,possibilities,"A");
- }
- switch(note) { //note to number
- case "A":return 1;
- case "B":return 2;
- case "C":return 3;
- case "D":return 4;
- case "E":return 5;
- case "F":return 6;
- case "G":return 7;
- }
- return 0;
- }
- public static int getNoteChange() {
- String change;
- int changeInt = 0; //declare int
- boolean ischangeint = false;
- change = (String)JOptionPane.showInputDialog(null,"How much do you want to go up or down?","Music Scale",JOptionPane.PLAIN_MESSAGE,null,null,"1"); //inital input
- while (ischangeint == false) {
- try {
- changeInt = Integer.parseInt(change); //converts string answer to integer
- //goes to catch if it's not
- if (changeInt >= 1) { //checks if its greater than or equal to 1
- ischangeint = true; //if all conditions satisfied, change ischangeint to true, breaking the while loop
- } else { //less than 1
- JOptionPane.showMessageDialog(null,"That is not a positive number!", "Error!", JOptionPane.ERROR_MESSAGE); //error
- change = (String)JOptionPane.showInputDialog(null,"How much do you want to go up or down?","Music Scale",JOptionPane.PLAIN_MESSAGE,null,null,"1"); //asks again
- }
- } catch (NumberFormatException e) { //goes to this instead of error if not integer
- JOptionPane.showMessageDialog(null,"That is not a valid number!", "Error!", JOptionPane.ERROR_MESSAGE); //error
- change = (String)JOptionPane.showInputDialog(null,"How much do you want to go up or down?","Music Scale",JOptionPane.PLAIN_MESSAGE,null,null,"1"); //asks again
- }
- }
- return changeInt; //after checking if it is a valid int, it returns it
- }
- public static boolean getDirection() {
- String directionS;
- Object[] possibilities = {"Up","Down"};
- directionS = (String)JOptionPane.showInputDialog(null,"Which direction do you want to count in?","Music Scale",JOptionPane.PLAIN_MESSAGE,null,possibilities,"Up");
- while (directionS == null) { //makes sure if cancel is pressed it tries again
- JOptionPane.showMessageDialog(null,"Enter a direction!", "Error!", JOptionPane.ERROR_MESSAGE);
- directionS = (String)JOptionPane.showInputDialog(null,"Which direction do you want to count in?","Music Scale",JOptionPane.PLAIN_MESSAGE,null,possibilities,"Up");
- }
- if (directionS == "Up") {
- return true;
- } else {
- return false;
- }
- }
- public static String getNewNote(int id) {
- switch(id) { //note to number
- case 1:return "A";
- case 2:return "B";
- case 3:return "C";
- case 4:return "D";
- case 5:return "E";
- case 6:return "F";
- case 0:return "G";
- }
- return "error";
- }
- }
- //Created by Hexbugman213
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement