Homework Help! Guitar Class [on hold]











up vote
-5
down vote

favorite












I have been working on a homework assignment involving different aspects of a guitar.




  • A private int data field named numStrings that defines the number of strings on the guitar. The default value should be 6.


  • A private double data field named guitarLength that defines the length of the guitar in inches. The default value should be 28.2



-A private String data field named guitarManufacturer that defines the manufacturer of the guitar. The default value should be “Gibson”.



-A private Color data field named guitarColor that defines the color of the guitar. The default value should be Color.Red.




  • A no argument constructor that creates a Guitar using the default number of strings, length, manufacturer and color.
    -A constructor that creates a Guitar using a specified number of strings, length, manufacturer and color.


-Getter methods for all data fields.



-A playGuitar() method that returns a string representation of 16 randomly selected musical notes of random duration. For example, the first part of the string returned might look like this: [A(2), G(3), B(0.5), C(1), C(1), D(0.25), …]. You can assume one octave in the key of C where valid notes include A, B, C, D, E, F and G and duration values are .25, .5, 1, 2, and 4 representing sixteenth notes, eighth notes, quarter notes, half notes and whole notes, respectively.



-A toString() method that displays the number of strings, length, manufacturer and color in String format.



Here is my code so far, but when I compile it through javac, I get an error at the very end of the program because of "public class TestGuitar"



 import java.io.*;
import java.awt.*;
import java.util.*;

class Guitar {
private int num_strings;
private double len;
private String manufacturer;
private Color color;
public Guitar(){
num_strings = 6;
len = 28.2;
manufacturer = "Gibson";
color = Color.RED;
}
public Guitar(int a, double b,String c, Color d){
num_strings = a;
len = b;
manufacturer = c;
color = d;
}
public int getNumStrings(){
return num_strings;
}
public double getLength(){
return len;
}
public String getManufacturer(){
return manufacturer;
}
public Color getColor(){
return color;
}
public String toString(){

String name = "";
if (color == Color.RED){
name = "Red";
}
if (color == Color.BLUE){
name = "Blue";
}
if (color == Color.BLACK){
name = "Black";
}
if (color == Color.CYAN){
name = "Cyan";
}
if (color == Color.YELLOW){
name = "Yellow";
}
if (color == Color.WHITE){
name = "White";
}
return "Guitar with " + String.valueOf(num_strings) + ", length of " + String.valueOf(len) + ", manufactured by " + manufacturer + " with a color of " + name;
}
public void playGuitar(){
Random rand = new Random();
System.out.print("[ ");
for (int i = 0; i<16; i++){
System.out.print(('A' + rand.nextInt(7)));
System.out.print("(");
switch (rand.nextInt(5)){
case 0 : System.out.print("0.25");
break;
case 1 : System.out.print("0.5");
break;
case 2 : System.out.print("1");
break;
case 3 : System.out.print("2");
break;
case 4 : System.out.print("4");
break;
}
System.out.print(")");
if (i < 15)
System.out.print(",");
}
System.out.print(" ]");
}
}
public class TestGuitar {
public static void main(String args){
Guitar g1 = new Guitar(8,30.3,"Gibson",Color.blue);
Guitar g2 = new Guitar(7,25.3,"Gibson",Color.black);
Guitar g3 = new Guitar(7,20.3,"Gibson",Color.green);
System.out.println(g1.toString());
g1.playGuitar();
}
}









share|improve this question







New contributor




user185524 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by πάντα ῥεῖ, Martin R, t3chb0t, Mast, 200_success 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Martin R, t3chb0t, Mast, 200_success

If this question can be reworded to fit the rules in the help center, please edit the question.

















    up vote
    -5
    down vote

    favorite












    I have been working on a homework assignment involving different aspects of a guitar.




    • A private int data field named numStrings that defines the number of strings on the guitar. The default value should be 6.


    • A private double data field named guitarLength that defines the length of the guitar in inches. The default value should be 28.2



    -A private String data field named guitarManufacturer that defines the manufacturer of the guitar. The default value should be “Gibson”.



    -A private Color data field named guitarColor that defines the color of the guitar. The default value should be Color.Red.




    • A no argument constructor that creates a Guitar using the default number of strings, length, manufacturer and color.
      -A constructor that creates a Guitar using a specified number of strings, length, manufacturer and color.


    -Getter methods for all data fields.



    -A playGuitar() method that returns a string representation of 16 randomly selected musical notes of random duration. For example, the first part of the string returned might look like this: [A(2), G(3), B(0.5), C(1), C(1), D(0.25), …]. You can assume one octave in the key of C where valid notes include A, B, C, D, E, F and G and duration values are .25, .5, 1, 2, and 4 representing sixteenth notes, eighth notes, quarter notes, half notes and whole notes, respectively.



    -A toString() method that displays the number of strings, length, manufacturer and color in String format.



    Here is my code so far, but when I compile it through javac, I get an error at the very end of the program because of "public class TestGuitar"



     import java.io.*;
    import java.awt.*;
    import java.util.*;

    class Guitar {
    private int num_strings;
    private double len;
    private String manufacturer;
    private Color color;
    public Guitar(){
    num_strings = 6;
    len = 28.2;
    manufacturer = "Gibson";
    color = Color.RED;
    }
    public Guitar(int a, double b,String c, Color d){
    num_strings = a;
    len = b;
    manufacturer = c;
    color = d;
    }
    public int getNumStrings(){
    return num_strings;
    }
    public double getLength(){
    return len;
    }
    public String getManufacturer(){
    return manufacturer;
    }
    public Color getColor(){
    return color;
    }
    public String toString(){

    String name = "";
    if (color == Color.RED){
    name = "Red";
    }
    if (color == Color.BLUE){
    name = "Blue";
    }
    if (color == Color.BLACK){
    name = "Black";
    }
    if (color == Color.CYAN){
    name = "Cyan";
    }
    if (color == Color.YELLOW){
    name = "Yellow";
    }
    if (color == Color.WHITE){
    name = "White";
    }
    return "Guitar with " + String.valueOf(num_strings) + ", length of " + String.valueOf(len) + ", manufactured by " + manufacturer + " with a color of " + name;
    }
    public void playGuitar(){
    Random rand = new Random();
    System.out.print("[ ");
    for (int i = 0; i<16; i++){
    System.out.print(('A' + rand.nextInt(7)));
    System.out.print("(");
    switch (rand.nextInt(5)){
    case 0 : System.out.print("0.25");
    break;
    case 1 : System.out.print("0.5");
    break;
    case 2 : System.out.print("1");
    break;
    case 3 : System.out.print("2");
    break;
    case 4 : System.out.print("4");
    break;
    }
    System.out.print(")");
    if (i < 15)
    System.out.print(",");
    }
    System.out.print(" ]");
    }
    }
    public class TestGuitar {
    public static void main(String args){
    Guitar g1 = new Guitar(8,30.3,"Gibson",Color.blue);
    Guitar g2 = new Guitar(7,25.3,"Gibson",Color.black);
    Guitar g3 = new Guitar(7,20.3,"Gibson",Color.green);
    System.out.println(g1.toString());
    g1.playGuitar();
    }
    }









    share|improve this question







    New contributor




    user185524 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.











    put on hold as off-topic by πάντα ῥεῖ, Martin R, t3chb0t, Mast, 200_success 2 days ago


    This question appears to be off-topic. The users who voted to close gave this specific reason:


    • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Martin R, t3chb0t, Mast, 200_success

    If this question can be reworded to fit the rules in the help center, please edit the question.















      up vote
      -5
      down vote

      favorite









      up vote
      -5
      down vote

      favorite











      I have been working on a homework assignment involving different aspects of a guitar.




      • A private int data field named numStrings that defines the number of strings on the guitar. The default value should be 6.


      • A private double data field named guitarLength that defines the length of the guitar in inches. The default value should be 28.2



      -A private String data field named guitarManufacturer that defines the manufacturer of the guitar. The default value should be “Gibson”.



      -A private Color data field named guitarColor that defines the color of the guitar. The default value should be Color.Red.




      • A no argument constructor that creates a Guitar using the default number of strings, length, manufacturer and color.
        -A constructor that creates a Guitar using a specified number of strings, length, manufacturer and color.


      -Getter methods for all data fields.



      -A playGuitar() method that returns a string representation of 16 randomly selected musical notes of random duration. For example, the first part of the string returned might look like this: [A(2), G(3), B(0.5), C(1), C(1), D(0.25), …]. You can assume one octave in the key of C where valid notes include A, B, C, D, E, F and G and duration values are .25, .5, 1, 2, and 4 representing sixteenth notes, eighth notes, quarter notes, half notes and whole notes, respectively.



      -A toString() method that displays the number of strings, length, manufacturer and color in String format.



      Here is my code so far, but when I compile it through javac, I get an error at the very end of the program because of "public class TestGuitar"



       import java.io.*;
      import java.awt.*;
      import java.util.*;

      class Guitar {
      private int num_strings;
      private double len;
      private String manufacturer;
      private Color color;
      public Guitar(){
      num_strings = 6;
      len = 28.2;
      manufacturer = "Gibson";
      color = Color.RED;
      }
      public Guitar(int a, double b,String c, Color d){
      num_strings = a;
      len = b;
      manufacturer = c;
      color = d;
      }
      public int getNumStrings(){
      return num_strings;
      }
      public double getLength(){
      return len;
      }
      public String getManufacturer(){
      return manufacturer;
      }
      public Color getColor(){
      return color;
      }
      public String toString(){

      String name = "";
      if (color == Color.RED){
      name = "Red";
      }
      if (color == Color.BLUE){
      name = "Blue";
      }
      if (color == Color.BLACK){
      name = "Black";
      }
      if (color == Color.CYAN){
      name = "Cyan";
      }
      if (color == Color.YELLOW){
      name = "Yellow";
      }
      if (color == Color.WHITE){
      name = "White";
      }
      return "Guitar with " + String.valueOf(num_strings) + ", length of " + String.valueOf(len) + ", manufactured by " + manufacturer + " with a color of " + name;
      }
      public void playGuitar(){
      Random rand = new Random();
      System.out.print("[ ");
      for (int i = 0; i<16; i++){
      System.out.print(('A' + rand.nextInt(7)));
      System.out.print("(");
      switch (rand.nextInt(5)){
      case 0 : System.out.print("0.25");
      break;
      case 1 : System.out.print("0.5");
      break;
      case 2 : System.out.print("1");
      break;
      case 3 : System.out.print("2");
      break;
      case 4 : System.out.print("4");
      break;
      }
      System.out.print(")");
      if (i < 15)
      System.out.print(",");
      }
      System.out.print(" ]");
      }
      }
      public class TestGuitar {
      public static void main(String args){
      Guitar g1 = new Guitar(8,30.3,"Gibson",Color.blue);
      Guitar g2 = new Guitar(7,25.3,"Gibson",Color.black);
      Guitar g3 = new Guitar(7,20.3,"Gibson",Color.green);
      System.out.println(g1.toString());
      g1.playGuitar();
      }
      }









      share|improve this question







      New contributor




      user185524 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I have been working on a homework assignment involving different aspects of a guitar.




      • A private int data field named numStrings that defines the number of strings on the guitar. The default value should be 6.


      • A private double data field named guitarLength that defines the length of the guitar in inches. The default value should be 28.2



      -A private String data field named guitarManufacturer that defines the manufacturer of the guitar. The default value should be “Gibson”.



      -A private Color data field named guitarColor that defines the color of the guitar. The default value should be Color.Red.




      • A no argument constructor that creates a Guitar using the default number of strings, length, manufacturer and color.
        -A constructor that creates a Guitar using a specified number of strings, length, manufacturer and color.


      -Getter methods for all data fields.



      -A playGuitar() method that returns a string representation of 16 randomly selected musical notes of random duration. For example, the first part of the string returned might look like this: [A(2), G(3), B(0.5), C(1), C(1), D(0.25), …]. You can assume one octave in the key of C where valid notes include A, B, C, D, E, F and G and duration values are .25, .5, 1, 2, and 4 representing sixteenth notes, eighth notes, quarter notes, half notes and whole notes, respectively.



      -A toString() method that displays the number of strings, length, manufacturer and color in String format.



      Here is my code so far, but when I compile it through javac, I get an error at the very end of the program because of "public class TestGuitar"



       import java.io.*;
      import java.awt.*;
      import java.util.*;

      class Guitar {
      private int num_strings;
      private double len;
      private String manufacturer;
      private Color color;
      public Guitar(){
      num_strings = 6;
      len = 28.2;
      manufacturer = "Gibson";
      color = Color.RED;
      }
      public Guitar(int a, double b,String c, Color d){
      num_strings = a;
      len = b;
      manufacturer = c;
      color = d;
      }
      public int getNumStrings(){
      return num_strings;
      }
      public double getLength(){
      return len;
      }
      public String getManufacturer(){
      return manufacturer;
      }
      public Color getColor(){
      return color;
      }
      public String toString(){

      String name = "";
      if (color == Color.RED){
      name = "Red";
      }
      if (color == Color.BLUE){
      name = "Blue";
      }
      if (color == Color.BLACK){
      name = "Black";
      }
      if (color == Color.CYAN){
      name = "Cyan";
      }
      if (color == Color.YELLOW){
      name = "Yellow";
      }
      if (color == Color.WHITE){
      name = "White";
      }
      return "Guitar with " + String.valueOf(num_strings) + ", length of " + String.valueOf(len) + ", manufactured by " + manufacturer + " with a color of " + name;
      }
      public void playGuitar(){
      Random rand = new Random();
      System.out.print("[ ");
      for (int i = 0; i<16; i++){
      System.out.print(('A' + rand.nextInt(7)));
      System.out.print("(");
      switch (rand.nextInt(5)){
      case 0 : System.out.print("0.25");
      break;
      case 1 : System.out.print("0.5");
      break;
      case 2 : System.out.print("1");
      break;
      case 3 : System.out.print("2");
      break;
      case 4 : System.out.print("4");
      break;
      }
      System.out.print(")");
      if (i < 15)
      System.out.print(",");
      }
      System.out.print(" ]");
      }
      }
      public class TestGuitar {
      public static void main(String args){
      Guitar g1 = new Guitar(8,30.3,"Gibson",Color.blue);
      Guitar g2 = new Guitar(7,25.3,"Gibson",Color.black);
      Guitar g3 = new Guitar(7,20.3,"Gibson",Color.green);
      System.out.println(g1.toString());
      g1.playGuitar();
      }
      }






      java






      share|improve this question







      New contributor




      user185524 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      user185524 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      user185524 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 2 days ago









      user185524

      1




      1




      New contributor




      user185524 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      user185524 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      user185524 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      put on hold as off-topic by πάντα ῥεῖ, Martin R, t3chb0t, Mast, 200_success 2 days ago


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Martin R, t3chb0t, Mast, 200_success

      If this question can be reworded to fit the rules in the help center, please edit the question.




      put on hold as off-topic by πάντα ῥεῖ, Martin R, t3chb0t, Mast, 200_success 2 days ago


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Martin R, t3chb0t, Mast, 200_success

      If this question can be reworded to fit the rules in the help center, please edit the question.



























          active

          oldest

          votes






















          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes

          Popular posts from this blog

          Morgemoulin

          Scott Moir

          Souastre