Results 1 to 3 of 3
  1. #1
    Juukamen is offline Member
    Join Date
    Oct 2011
    Location
    Tromsø
    Posts
    54
    Rep Power
    0

    Default array copy in class constructor.

    I got this code so far.

    Java Code:
    class Skosamling{
    	private final String merke;
    	private final String farge;
    	private final Integer prisPerPar;
    	private final Integer minsteStørrelse;
    	private final Integer[] left;
    	private final Integer[] right;
    
    	public Skosamling(String merke, String farge, Integer prisPerPar, Integer minsteStørrelse, Integer[] left, Integer[] right) {
    		this.merke = merke;
    		this.farge = farge;
    		this.prisPerPar = prisPerPar;
    		this.minsteStørrelse = minsteStørrelse;
    		this.left[] = left[];
    		for(int i=0; i < left.length ; i++) {
    			right[i] = left[i];
    		}
    		this.right[] = right[];
    	}
    }
    I want right to have the same values as left.

    and here is the error messages I'm getting so far.

    Java Code:
    G:\Coding\Skole\Øving 9\tabeller.java:20: error: illegal start of expression
    		this.left[] = left[];
    		          ^
    G:\Coding\Skole\Øving 9\tabeller.java:20: error: '.class' expected
    		this.left[] = left[];
    		                    ^
    G:\Coding\Skole\Øving 9\tabeller.java:24: error: illegal start of expression
    		this.right[] = right[];
    		           ^
    G:\Coding\Skole\Øving 9\tabeller.java:24: error: '.class' expected
    		this.right[] = right[];
    		                      ^
    4 errors
    
    Tool completed with exit code 1

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,965
    Rep Power
    8

    Default Re: array copy in class constructor.

    Those aren't valid variable names. Notice you're declaring them as Integer[] left, not Integer[] left[].
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Juukamen is offline Member
    Join Date
    Oct 2011
    Location
    Tromsø
    Posts
    54
    Rep Power
    0

    Default Re: array copy in class constructor.

    ok new try on this one.

    i got two arrays that i got on the class. and when enabling it only one of those will be declared, since the last one will do one deep copy of the other one.

    Java Code:
    class shoes{
    	private final String brand;
    	private final String colour;
    	private final double price;
    	private final int minSize;
    	private final int[] left;
    	private final int[] right;
    
    	public shoes(String brand, String colour, double price, int minSize, int[] left, int[] right) {
    		this.brand = brand;
    		this.colour = colour;
    		this.price = price;
    		this.minSize = minSize;
    		this.left = new int[] left;
    		this.right = new int[] right;   // thisone shall be one deep copy of the left array.
    	}
    }
    now, ideas on what to google for and examples that i can study to fix this ?
    googleing java array kinda sucks :P
    Last edited by Juukamen; 10-29-2011 at 12:09 AM.

Similar Threads

  1. Array copy
    By lakshmibvaraprasad in forum New To Java
    Replies: 16
    Last Post: 07-21-2011, 09:17 PM
  2. Replies: 16
    Last Post: 07-08-2010, 09:13 PM
  3. copy constructor
    By shadow7 in forum New To Java
    Replies: 6
    Last Post: 12-29-2009, 06:56 PM
  4. Replies: 0
    Last Post: 12-19-2007, 09:10 AM
  5. Replies: 0
    Last Post: 12-19-2007, 09:01 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •