Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › need help with java assignment
New Posts  All Forums:Forum Nav:

need help with java assignment

post #1 of 4
Thread Starter 
Hi i am writing a program for a Plant

the machine has a containers per min production rate
containers are 500grams
and each storage area has a capacity that stores the products that the machine makes.


So, for t his method i have to find out how much space is left in all storage area

getAvailableStorage

public int getAvailableStorage()
Gets the total room available in all storage areas by iterating through all storage areas and adding the available room in each.
Returns:
Total available room in all storage areas.


so for example

a plant has

storage area 1 capacity = 15000
storage area 2 capacity = 2500
storage area 3 capacity = 3000

Total = 20500
machines are stored in the plant

so i have 3 machines

machine 1 = 30perMin = 30x500 = 15000
machine 2 = 5perMin = 2500
machine 3 = 5perMin = 2500

Total = 20000

get Available Storage should output 500 space left

old code :

int availableStorage;
for (StorageArea getStorage: arealocation){
storageSpace += getStorage.getCapacity();
}
availableStorage = storageSpace - total;
return availableStorage;
}

my old code outputs 500 space left, but this is not what he's asking for he wants me to iterate trhough all storage areas, and add avaiable room in each

so machine 1 produce 30 containers a min which is 15000, so storage area 1 is filled
storage 2 is also filled

storage area 3 has 500 space left


how would i iterate through allt he storage area and add how much rooms are left in each?
so that

index 0 has 0 space left
index 1 has 0 space left
index 2 has 500 space left
Edited by turbonerds - 4/8/12 at 2:04pm
sig rig
(17 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k 4.4ghz ASRock P67 Extreme4 (B3) Gigabyte GTX 560 Ti SoC Patriot Viper DDR3 2x4gb 1600 MHZ CL9 
Hard DriveHard DriveHard DriveOS
WD 500GB BLACK Samsung 840 Maxtor 320 GB Windows 7 Home Prenium 64 bit 
MonitorMonitorKeyboardPower
ASUS VS247 Samsung BX2431 Razer BlackWidow OCZ STEALTHXSTREAM 2 600W 
CaseMouseMouse PadAudio
COOLERMASTER HAF 922 Logitech G9X SteelSeries QcK Creative X-Fi Titanium Fatality - Audio Techn... 
  hide details  
Reply
sig rig
(17 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k 4.4ghz ASRock P67 Extreme4 (B3) Gigabyte GTX 560 Ti SoC Patriot Viper DDR3 2x4gb 1600 MHZ CL9 
Hard DriveHard DriveHard DriveOS
WD 500GB BLACK Samsung 840 Maxtor 320 GB Windows 7 Home Prenium 64 bit 
MonitorMonitorKeyboardPower
ASUS VS247 Samsung BX2431 Razer BlackWidow OCZ STEALTHXSTREAM 2 600W 
CaseMouseMouse PadAudio
COOLERMASTER HAF 922 Logitech G9X SteelSeries QcK Creative X-Fi Titanium Fatality - Audio Techn... 
  hide details  
Reply
post #2 of 4
Thread Starter 
sig rig
(17 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k 4.4ghz ASRock P67 Extreme4 (B3) Gigabyte GTX 560 Ti SoC Patriot Viper DDR3 2x4gb 1600 MHZ CL9 
Hard DriveHard DriveHard DriveOS
WD 500GB BLACK Samsung 840 Maxtor 320 GB Windows 7 Home Prenium 64 bit 
MonitorMonitorKeyboardPower
ASUS VS247 Samsung BX2431 Razer BlackWidow OCZ STEALTHXSTREAM 2 600W 
CaseMouseMouse PadAudio
COOLERMASTER HAF 922 Logitech G9X SteelSeries QcK Creative X-Fi Titanium Fatality - Audio Techn... 
  hide details  
Reply
sig rig
(17 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k 4.4ghz ASRock P67 Extreme4 (B3) Gigabyte GTX 560 Ti SoC Patriot Viper DDR3 2x4gb 1600 MHZ CL9 
Hard DriveHard DriveHard DriveOS
WD 500GB BLACK Samsung 840 Maxtor 320 GB Windows 7 Home Prenium 64 bit 
MonitorMonitorKeyboardPower
ASUS VS247 Samsung BX2431 Razer BlackWidow OCZ STEALTHXSTREAM 2 600W 
CaseMouseMouse PadAudio
COOLERMASTER HAF 922 Logitech G9X SteelSeries QcK Creative X-Fi Titanium Fatality - Audio Techn... 
  hide details  
Reply
post #3 of 4
Thread Starter 
i did

public int getAvailableStorage(){

StorageArea sItem = null;
int totalrm = 0;

for (Iterator e = arealocation.iterator(); e.hasNext()wink.gif {

// We don't have to cast since we know the arraylist cannot contain
// anything other than a ShoppingItem
sItem = e.next();
totalrm += sItem.getCapacity();

}
return totalrm - total;
}

but i don't know if this adds all avaliable rooms in each storage area.. but it does output 500.. lol i wasn't paying attention in class for this part of lecture on iterate..

please help!
sig rig
(17 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k 4.4ghz ASRock P67 Extreme4 (B3) Gigabyte GTX 560 Ti SoC Patriot Viper DDR3 2x4gb 1600 MHZ CL9 
Hard DriveHard DriveHard DriveOS
WD 500GB BLACK Samsung 840 Maxtor 320 GB Windows 7 Home Prenium 64 bit 
MonitorMonitorKeyboardPower
ASUS VS247 Samsung BX2431 Razer BlackWidow OCZ STEALTHXSTREAM 2 600W 
CaseMouseMouse PadAudio
COOLERMASTER HAF 922 Logitech G9X SteelSeries QcK Creative X-Fi Titanium Fatality - Audio Techn... 
  hide details  
Reply
sig rig
(17 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k 4.4ghz ASRock P67 Extreme4 (B3) Gigabyte GTX 560 Ti SoC Patriot Viper DDR3 2x4gb 1600 MHZ CL9 
Hard DriveHard DriveHard DriveOS
WD 500GB BLACK Samsung 840 Maxtor 320 GB Windows 7 Home Prenium 64 bit 
MonitorMonitorKeyboardPower
ASUS VS247 Samsung BX2431 Razer BlackWidow OCZ STEALTHXSTREAM 2 600W 
CaseMouseMouse PadAudio
COOLERMASTER HAF 922 Logitech G9X SteelSeries QcK Creative X-Fi Titanium Fatality - Audio Techn... 
  hide details  
Reply
post #4 of 4
Thread Starter 
i figured it out, now i need help on

Method will attempt to ship parts from the storage areas. It will accomplish this by decrementing each storage area starting from index 0 until the total amount decremented is equal to count.
Example a: StorageArea 0 has 100 units and StorageArea 1 has 50 If a request is made to ship 120 parts then StorageArea 0 is decremented to 0 (emptied) and Area 1 is decremented by 20.
Example b: StorageArea 0 has 200 units and StorageArea 1 has 50 If a request is made to ship 120 parts then StorageArea 0 is decremented by 120 to leave 80. Area 1 is not changed.
Example c: StorageArea 0 has 60 units and StorageArea 1 has 50 If a request is made to ship 120 parts then no changes are made to either Area 0 or 1 but a NotEnoughPartsException is thrown.
sig rig
(17 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k 4.4ghz ASRock P67 Extreme4 (B3) Gigabyte GTX 560 Ti SoC Patriot Viper DDR3 2x4gb 1600 MHZ CL9 
Hard DriveHard DriveHard DriveOS
WD 500GB BLACK Samsung 840 Maxtor 320 GB Windows 7 Home Prenium 64 bit 
MonitorMonitorKeyboardPower
ASUS VS247 Samsung BX2431 Razer BlackWidow OCZ STEALTHXSTREAM 2 600W 
CaseMouseMouse PadAudio
COOLERMASTER HAF 922 Logitech G9X SteelSeries QcK Creative X-Fi Titanium Fatality - Audio Techn... 
  hide details  
Reply
sig rig
(17 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k 4.4ghz ASRock P67 Extreme4 (B3) Gigabyte GTX 560 Ti SoC Patriot Viper DDR3 2x4gb 1600 MHZ CL9 
Hard DriveHard DriveHard DriveOS
WD 500GB BLACK Samsung 840 Maxtor 320 GB Windows 7 Home Prenium 64 bit 
MonitorMonitorKeyboardPower
ASUS VS247 Samsung BX2431 Razer BlackWidow OCZ STEALTHXSTREAM 2 600W 
CaseMouseMouse PadAudio
COOLERMASTER HAF 922 Logitech G9X SteelSeries QcK Creative X-Fi Titanium Fatality - Audio Techn... 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › need help with java assignment