My problem is getting snum in the main class to transfer over to the sub class, so that the snum in that class = snum from the main class
The code is;

package workstation; 
import java.util.Random; 
import javax.swing.*; 

public class Main 
{ public static void main(String[] args) { 
int swip,ewip,number; 
final int snum1; 
swip = 1000; //Starting work in progress 
number =0; //Given it a default value otherwise errors occur Random dice = new Random(); 

for(int counter=0; counter<1;counter++)
{ number =1+dice.nextInt(6); } //end counter/number 

System.out.println("RM Dice number= "+number);//Check ewip=swip - number; //End WIP = Start WIP - random number 

snum1=number; //Send number =random number 

System.out.println("End WIP="+ewip); //Check 

System.out.println("Sent number= "+snum1); //Check class 

raw_material extends Main{ 
int swip,snum,ewip,number; 
{ 
swip= 4; 
Random dice = new Random(); 
for(int counter=0; counter<1;counter++)
{ number =1+dice.nextInt(6); //Creates the random number of counters to pass 

System.out.println("WS1 dice roll "+number); 
snum = number;//send counters = dice roll 
ewip =swip-number+snum1; // End work in progress is calculated System.out.println("Snum1 "+snum1); } } } } }

Edited 6 Years Ago by ~s.o.s~: Fixed code tags

im not familiar with setter method :s Can you show me what one would look like for this?

Hi Bob,
Firstly, please google getters and setters in java, you will understand what I am talking about.

The way you would write a setter method is, firstly assuming you have written your subclass. in your subclass you need create a new method such as:

public void setNum(int num){
    this.snum = num; //where number is the variable which you would like to have the value of the variable in the main class(transfer from the main class)
}

//in your main class you need to create an instance of your subclass such as:
raw_material raw = new raw_material();

//now raw would have the method i created above so, you would:

raw.setNum(snum1);


//that should do it.
This article has been dead for over six months. Start a new discussion instead.