New set of files to work with, will upload code, and will look back on to optimize the code for returning the getName function.
package decisionrandom;
import java.util.Random;
import java.util.ArrayList;
public class Randomm {
static int weight;
static String name;
static int totval = 0;
static ArrayList<Randomm> total = new ArrayList<Randomm>();
static Randomm alg = new Randomm(30,"algorithms");
static Randomm PHP = new Randomm(5,"PHP");
static Randomm Javascript = new Randomm(5,"Javascript");
static Randomm sql = new Randomm(5,"SQL");
Random rand = new Random();
public static void loop(){
for(int i=0;i<total.size();i++){
totval += getWeight(total.get(i));
}
}
public Randomm(int i1,String s1){
weight = i1;
name = s1;
}
public static int getWeight(Randomm r1){
return weight;
}
public static String getName(Randomm r1){
return name;
}
public static String checker(){
if(totval <= 30)
return(getName(alg));
else if(totval<=35)
return(getName(PHP));
else if(totval<=40)
return(getName(Javascript));
else if(totval<=45)
return(getName(sql));
else
return("noresult");
}
public static void main(String[] args){
total.add(alg);
total.add(PHP);
total.add(Javascript);
total.add(sql);
loop();
System.out.println(checker());
}
}
It is sobering to know that I have declined this much in my programming skills. I cam incapable of making a very simple program to randomly generate a very simple result. I have to modify quickly.
ReplyDeletehave resolved the issue, most likely. hopefully it works out.
ReplyDeletetesting comment
ReplyDeleteresolved issue, error due to the static clause of the weight and name values, allowing access to the other class in the package.
ReplyDelete