package GuitarWorld; import java.util.HashMap; import java.util.Scanner; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * Player class stores the players name and experience in a constructor. * @author sarah */ class Player{ String name; String experience; Player(String playersName, String playersExperience){ name = playersName; experience = playersExperience; }// player constructor /** * Frequency stores 6 notes on a guitar and each note has the frequency in hertz that is associated with it. This is all stored in a Hash Map. It returns the hash map so that it can be called upon. * @param note * @return */ public static double frequency(String note){ HashMap freq = new HashMap(); freq.put("Low E",82.407); freq.put("A",110.00); freq.put("D",146.832); freq.put("G",195.998); freq.put("B",246.942); freq.put("E",329.628); return freq.put(note, Double.NaN); } // close frequency hashmap } // close player class /** * class electric guitar stores 3 member variables including type, color and price. These are stored inside of a constructor. * @author sarah */ class ElectricGuitar { // member variables describing guitar String type; String color; double price; ElectricGuitar (String guitarType,String guitarColor,double guitarPrice){ type = guitarType; color = guitarColor; price = guitarPrice; } // close electric guitar constructor /** * Get guitar info uses the constructor to access the type, color and price of the specific guitar. This method returns the guitar information and this is located within a local variable. * @return */ public String getGuitarInfo(){ String guitarInfo; guitarInfo = "Guitar Type: " + type + "\nGuitar Color: " + color + "\nGuitar Price: " + price; return guitarInfo; } // close get method } // close public Electric Guitar class /** * Class Price initiates a single member variable guitar price that is used in the array. * @author sarah */ class Price{ double guitarPrice; /** * The price array is a double array of 5 bins that holds different guitar prices. The for loop initiates the prices into different categories * These categories include; Affordable guitar prices, Expensive Guitar Prices, and the final average of the guitar prices. This algorithm calculates the average price. */ public void priceArray(){ double[] prices; prices = new double[5]; // array to hold 5 prices prices[0] = 36.94; prices[1] = 120.50; prices[2] = 279.0; prices[3] = 600.0; prices[4] = 5899.20; for(int i = 0; i < prices.length; i++ ){ if(prices[i] <= 300){ System.out.println("Affordable Guitar Price: " + prices[i]); } // close if } // close for for(int i = 0; i < prices.length; i++ ){ if(prices[i] >300){ System.out.println("Expensive Guitar Price: " + prices[i]); } // close if } // close for double sum = 0; for(int i = 0; i< prices.length; i++){ sum = sum + prices[i]; } // close for // space to seperate System.out.println(); // average local variable to store the sum of the prices divided by the array index double average = sum / prices.length; // call to store the guitar average price System.out.println("Average Guitar Price: " + average); } // close price array /** * Price of guitar uses user input and classifies their number into one of the categories within the if statement. Then it will print out the string associated with that price. */ public void priceOfGuitar(){ if (guitarPrice < 50){ System.out.println("You just purchased a Beginners Acoustic from Walmart!"); } if ( guitarPrice > 50 && guitarPrice < 200) { System.out.println("You just purchased a guitar from target!"); } if ( guitarPrice >= 200 && guitarPrice < 400){ System.out.println("You just purchased a Squier Affinity Electric Guitar!"); } if ( guitarPrice >= 400 && guitarPrice < 4000){ System.out.println("You just purchased a Fender Stratocaster"); } if ( guitarPrice >= 4000 && guitarPrice < 80000){ System.out.println("You just purchased a Gibson Guitar!"); } if(guitarPrice >= 80000){ System.out.println("Since you are rich, you just purchased every guitar in existance!"); } else { System.out.println(); }// close if } // close price of guitar method } // close price class /** * Public class guitar world is the main class that stores the main method. This class calls every method and initiates String and code. * @author sarah */ public class Guitarworld{ double guitarPrices; public static void main(String[] args) throws IOException{ // local variables String playersName; String playersExperience; Double guitars; // creating guitar object ElectricGuitar guitar = new ElectricGuitar("Fender Stratocaster","Candy Apple Red", 279.00); // call to access the type of guitar System.out.println("The guitars type is: " + guitar.type); System.out.println("****************************************"); // creating userr input BufferedReader player = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter your name: "); // setting local variable players name equal to user input playersName = player.readLine(); System.out.println("Enter your guitar experience: "); // setting players experience equal to user input playersExperience = player.readLine(); // creating play object Player play = new Player(playersName,playersExperience); // calling the names and experience and storing name with user input System.out.println(play.name + ", your guitar experience is: " + play.experience); System.out.println("****************************************"); // calling the hash map to find the frequency for A System.out.println("You will now play the note A!"); System.out.println("The freqency that is played is: " + Player.frequency("A") + " hertz"); System.out.println(); // initiatining the price Price prices = new Price(); prices.priceArray(); //space System.out.println(); // creating the scanner for user input Scanner scan = new Scanner(System.in); System.out.println("What price would you pay for a guitar? "); // storing user input in guitar price prices.guitarPrice = scan.nextDouble(); prices.priceOfGuitar(); } // close main } // close guitar world