New Posts  All Forums:Forum Nav:

Need some java help

post #1 of 7
Thread Starter 
Hi, I'm a bit stuck in my program again... I'll appreciate any hint of what am I doing wrong.

The program needs to store integer sets from 0-1000 in a boolean array called data[].
Here is how I'm trying to store the values.

public IntegerSet(int a, int b, int c) {
data = new boolean [MAXSETVALUE+1];
for (int i = 0; i <= MAXSETVALUE; i++) {
data[a] = true;
data[b] = true;
data[c] = true;
}

int a, int b, int c refer to
this in main:
IntegerSet is1, is2, is3;
is1 = new IntegerSet();
is2 = new IntegerSet(1,2,5); <--------------
is3 = new IntegerSet();


Also I'm having problems picturing out how to print the sets/stored values into toString(). Any ideas will help.
Edited by Sodalink - 10/14/11 at 1:03pm
SC2 Phantom
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel i5 2500k @ 4.5Ghz  Asus P8P67 Pro Saphire 7950 3GB 8GB G.SKILL Ripjaws X Series 
Hard DriveOptical DriveOSMonitor
Temp slow hdd None Win7 Pro 64bit Asus 24 VE248H  
KeyboardPowerCaseMouse
Alien XFX 850 Silver 80 Plus NZXT Phantom Black Razer Darthbender 
Mouse Pad
Thermaltake LED 
  hide details  
Reply
SC2 Phantom
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel i5 2500k @ 4.5Ghz  Asus P8P67 Pro Saphire 7950 3GB 8GB G.SKILL Ripjaws X Series 
Hard DriveOptical DriveOSMonitor
Temp slow hdd None Win7 Pro 64bit Asus 24 VE248H  
KeyboardPowerCaseMouse
Alien XFX 850 Silver 80 Plus NZXT Phantom Black Razer Darthbender 
Mouse Pad
Thermaltake LED 
  hide details  
Reply
post #2 of 7
Thread Starter 
Quote:
Originally Posted by Sodalink View Post
data[] = new boolean [MAXSETVALUE]; which does not work and I'm lost
as how to do it since max is an int and the array is boolean.

.
Ah sorry for waisting time...

I tried it before and did not work, must have gotten some other syntax error, but I just put:

data = new boolean [MAXSETVALUE]; and it seems it compiled. Am I doing it
the right way though?
SC2 Phantom
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel i5 2500k @ 4.5Ghz  Asus P8P67 Pro Saphire 7950 3GB 8GB G.SKILL Ripjaws X Series 
Hard DriveOptical DriveOSMonitor
Temp slow hdd None Win7 Pro 64bit Asus 24 VE248H  
KeyboardPowerCaseMouse
Alien XFX 850 Silver 80 Plus NZXT Phantom Black Razer Darthbender 
Mouse Pad
Thermaltake LED 
  hide details  
Reply
SC2 Phantom
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel i5 2500k @ 4.5Ghz  Asus P8P67 Pro Saphire 7950 3GB 8GB G.SKILL Ripjaws X Series 
Hard DriveOptical DriveOSMonitor
Temp slow hdd None Win7 Pro 64bit Asus 24 VE248H  
KeyboardPowerCaseMouse
Alien XFX 850 Silver 80 Plus NZXT Phantom Black Razer Darthbender 
Mouse Pad
Thermaltake LED 
  hide details  
Reply
post #3 of 7
I'm doing this from my phone right now, but I hope this helps:

An integer can save any number from around -2000000000 to 2000000000.

An array is just a list of certain, specified variables.

When you do this:

boolean[] data = new boolean[MAXSETVALUE],

You create a list of 1000 booleans. They can be used like any ofher boolean, but instead of refrencing each one of them with an integer, you represent them like:
data[n] = .....

Where n represents the number in the array that you want to use.
I hope I am explaining this easilly enough

EDIT: yes, you are doing it right, in the second post.

In one line, creating an array would be:

boolean data[] = new boolean[MAXSETVALUE]

Sent from my DROID2 GLOBAL using Tapatalk
post #4 of 7
Thread Starter 
bump have a few more questions in the OP.
SC2 Phantom
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel i5 2500k @ 4.5Ghz  Asus P8P67 Pro Saphire 7950 3GB 8GB G.SKILL Ripjaws X Series 
Hard DriveOptical DriveOSMonitor
Temp slow hdd None Win7 Pro 64bit Asus 24 VE248H  
KeyboardPowerCaseMouse
Alien XFX 850 Silver 80 Plus NZXT Phantom Black Razer Darthbender 
Mouse Pad
Thermaltake LED 
  hide details  
Reply
SC2 Phantom
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel i5 2500k @ 4.5Ghz  Asus P8P67 Pro Saphire 7950 3GB 8GB G.SKILL Ripjaws X Series 
Hard DriveOptical DriveOSMonitor
Temp slow hdd None Win7 Pro 64bit Asus 24 VE248H  
KeyboardPowerCaseMouse
Alien XFX 850 Silver 80 Plus NZXT Phantom Black Razer Darthbender 
Mouse Pad
Thermaltake LED 
  hide details  
Reply
post #5 of 7
Thread Starter 
sorry for the early bump, but I've been stuck for hours and don't seem to find a solution...

last bump
SC2 Phantom
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel i5 2500k @ 4.5Ghz  Asus P8P67 Pro Saphire 7950 3GB 8GB G.SKILL Ripjaws X Series 
Hard DriveOptical DriveOSMonitor
Temp slow hdd None Win7 Pro 64bit Asus 24 VE248H  
KeyboardPowerCaseMouse
Alien XFX 850 Silver 80 Plus NZXT Phantom Black Razer Darthbender 
Mouse Pad
Thermaltake LED 
  hide details  
Reply
SC2 Phantom
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel i5 2500k @ 4.5Ghz  Asus P8P67 Pro Saphire 7950 3GB 8GB G.SKILL Ripjaws X Series 
Hard DriveOptical DriveOSMonitor
Temp slow hdd None Win7 Pro 64bit Asus 24 VE248H  
KeyboardPowerCaseMouse
Alien XFX 850 Silver 80 Plus NZXT Phantom Black Razer Darthbender 
Mouse Pad
Thermaltake LED 
  hide details  
Reply
post #6 of 7
ok...i kinda see what you are doing.

You are re-assigning boolean values in your array to true. The passed int variables represent the positions in the boolean array that will be changed to true.

Ok? do you have a default constructor? like this?

Code:
public IntegerSet(){

             boolean [] data = new boolean [MAXSETVALUE];
}
Also why are you adding 1 to MAXSETVALUE?

your for loop should look more like this:
Code:
public IntegerSet(int a, int b, int c) {
boolean [] data = new boolean [MAXSETVALUE];
for (int i = 0; i < MAXSETVALUE; i++) {
         data[a] = true;
         data[b] = true;
         data[c] = true;
}
For printing use in a for loop
Code:
System.out.println(Arrays.toString(data[i]));
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 10 ASUS VS24AH-P 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  hide details  
Reply
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 10 ASUS VS24AH-P 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  hide details  
Reply
post #7 of 7
Thread Starter 
Quote:
Originally Posted by surfbumb View Post
ok...i kinda see what you are doing.

You are re-assigning boolean values in your array to true. The passed int variables represent the positions in the boolean array that will be changed to true.

Ok? do you have a default constructor? like this?

Code:
public IntegerSet(){

             boolean [] data = new boolean [MAXSETVALUE];
}
Also why are you adding 1 to MAXSETVALUE?

your for loop should look more like this:
Code:
public IntegerSet(int a, int b, int c) {
boolean [] data = new boolean [MAXSETVALUE];
for (int i = 0; i < MAXSETVALUE; i++) {
         data[a] = true;
         data[b] = true;
         data[c] = true;
}
For printing use in a for loop
Code:
System.out.println(Arrays.toString(data[i]));
I have the +1 because the way i have the array it's 0-999 which is 1000 values, but I should be able to read from 0-1000 which is 0-999+1.

I had the loop that way and still something must be wrong in my code then it's do like in 20 mins so I'm just going to do minor changes and get partial credit. Thanks for your help!!

Also the way the set values are like this:

System.out.println(is3.toString()); under the Main which was given to us and we can not change or modify.
Edited by Sodalink - 10/14/11 at 5:39pm
SC2 Phantom
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel i5 2500k @ 4.5Ghz  Asus P8P67 Pro Saphire 7950 3GB 8GB G.SKILL Ripjaws X Series 
Hard DriveOptical DriveOSMonitor
Temp slow hdd None Win7 Pro 64bit Asus 24 VE248H  
KeyboardPowerCaseMouse
Alien XFX 850 Silver 80 Plus NZXT Phantom Black Razer Darthbender 
Mouse Pad
Thermaltake LED 
  hide details  
Reply
SC2 Phantom
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel i5 2500k @ 4.5Ghz  Asus P8P67 Pro Saphire 7950 3GB 8GB G.SKILL Ripjaws X Series 
Hard DriveOptical DriveOSMonitor
Temp slow hdd None Win7 Pro 64bit Asus 24 VE248H  
KeyboardPowerCaseMouse
Alien XFX 850 Silver 80 Plus NZXT Phantom Black Razer Darthbender 
Mouse Pad
Thermaltake LED 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming