Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Issue with setting up different class with arrays

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    2
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Issue with setting up different class with arrays

    I know it's not complete yet... but if possible can someone tell me what I am doing wrong here.

    -----------------------------------------------------------------------------------------------------------------
     
    class Violin {
     
    	String[] ViolinStrings = new String[4]; 
     
    	ViolinStrings[0] = "E";
    	ViolinStrings[1] = "A";
    	ViolinStrings[2] = "D";
    	ViolinStrings[3] = "G";
     
    	boolean ViolinTuned = false;
    	boolean ViolinPlaying = false;
    	boolean ViolinMusician = false;
    	boolean ViolinStopPlaying = false;
     
    	public violin() {
     
    	}
     
    	public void VTuned() {
    	ViolinTuned = true;
    	System.out.println("The violin is now tuned.");
    	}
     
    	public void VPlaying() {
    	ViolinPlaying = true;
    	System.out.println("The violin is now playing.");
    	}
     
    	public void VMusician() {
    	ViolinMusician = true;
    	System.out.println("The violin musician is ready to play.");
     
    	public void VStopPlaying() {
    	ViolinStopPlaying = true;
    	System.out.println("The violin has stopped playing.");
    	}
     
     
    }
     
     
    public class ArrayandClass1 {
     
    	public static void man(String[] args) {
     
    	Violin Violin1 = new Violin();
     
    	Violin1.ViolinTuned();
     
     
     
    	}
     
    }
    Last edited by D-COD3R; April 4th, 2011 at 03:37 PM.


  2. #2
    Junior Member
    Join Date
    Apr 2011
    Posts
    2
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Issue with setting up different class with arrays

    ok.. I have work a few of the errors down. I still need assistance with this class. I am receiving error with the array.

    public class Violin {
     
    	String[] ViolinStrings = new String[4]; 
     
    	ViolinStrings[0] = "E";
    	ViolinStrings[1] = "A";
    	ViolinStrings[2] = "D";
    	ViolinStrings[3] = "G";
     
    	boolean ViolinTuned = false;
    	boolean ViolinPlaying = false;
    	boolean ViolinMusician = false;
    	boolean ViolinStopPlaying = false;
     
    	public Violin() {
     
    	}
     
    	public void VTuned() {
    	ViolinTuned = true;
    	System.out.println("The violin is now tuned.");
    	}
     
    	public void VPlaying() {
    	ViolinPlaying = true;
    	System.out.println("The violin is now playing.");
    	}
     
    	public void VMusician() {
    	ViolinMusician = true;
    	System.out.println("The violin musician is ready to play.");
    	}
     
     
    	public void VStopPlaying() {
    	ViolinStopPlaying = true;
    	System.out.println("The violin has stopped playing.");
     
    	}
     
     
    }

  3. #3
    Junior Member
    Join Date
    Apr 2011
    Posts
    6
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Issue with setting up different class with arrays

    What are you trying to achieve?

    You need to place the initialisation in the constructor.

    A couple of pointers, think about the type you are using. Since you are storing a single character for each string maybe char would be better. Also method and variable names in java begin with a lowercase. While this isn't an issue when you are doing a program for yourself it is good practice to get into early. Also if you were to be developing and API this would be what people expect.

    Suisse

Similar Threads

  1. How to Sort an Array using the java.util.Arrays class
    By JavaPF in forum Java SE API Tutorials
    Replies: 2
    Last Post: May 17th, 2014, 01:16 AM
  2. Setting a transparency level of a picture issue
    By Asido in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 18th, 2012, 05:42 AM
  3. Replies: 1
    Last Post: December 22nd, 2011, 09:55 AM
  4. [SOLVED] issue with Character.isUpperCase class
    By suxen in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 24th, 2011, 09:30 PM
  5. Help setting a private static class variable
    By kyuss in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 26th, 2010, 08:09 AM