Only i cant find a tutorial on it,
Now i could ask in a java forum but you will find, just like i did, that no one can make a coherent forum for java that makes sense is well written and easy to use!
What I wanted to do is have an object that had a member function that i could store any amount of strings on, it also has a name in which i could refer to that list with.
so i would have a cuisine object, it would have its title and recipie.
so in the main menu i could add a title followed by the recipe, this object would be stored on a list, i could also enter the name of the recipe and get said list.
This is the ugly monster I created, this is my first java program please font laugh at my spelling it hurts deep, way down in my soul.
Oh yeah and i know its fundementally flawed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
import java.util.*;
public class meals extends recipie {
static int clue = 0;
ArrayList<recipie> objlist = new ArrayList<recipie>();
recipie Robj = new recipie();
ListIterator objitr = objlist.listIterator();
Scanner input = new Scanner(System.in);
public void addobject() {//this is all wrong i know, here is where
Robj.setname(); //i wanted to add new objects on
Robj.addrecipie(); //i was hoping i could use some sort of
objlist.add(Robj); //static variable in order to move objlist
} //ahead by one before add object is called again, just how??
try {
int num = 0;
while (!compare.equals(temp)) { //im not sure exactly whats wrong
System.out.printf("%s", clue); //here, i know it runs past the
recipie obj1 = (recipie) objlist.get(num); //array and...boom
num++;
compare = obj1.getname();
}
System.out.printf("the recipe for %s is", objlist.get(num).getname());
objlist.get(num).printrecipie();
} catch (Exception e) {
System.out.printf("nah we don't have that, or ... %s", e);
}
}
}
|
I call it all wierdly in main too
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
public class panel {
public static void main(String[] args) {
meals numeal = new meals();
boolean flag = true;
while (flag) {
System.out.println("do you wnt to 1 add a recipie or two get one or 3 quit?");
Scanner option = new Scanner(System.in);
int num = option.nextInt();
switch (num) {
case 1: {
numeal.addobject();
break;
}
case 2: {
System.out.println("enter the meal you are after");
String temp;
temp = option.next();
numeal.getobjrecipie(temp);
}
case 3:
flag = false;
break;
}
}
}
}
|
lastly im sure this class is fine and is basic stuff, im just putting it here cos i know you guys can still find things in it that i could do better...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
import java.util.*;
public class recipie {
ArrayList<String> item = new ArrayList<String>();
String temp, name;
int number = 0;
Scanner input = new Scanner(System.in);
public void setname() {
String x;
System.out.printf("whats the meal called");
x = input.next();
x = name;
}
public String getname() {
return name;
}
public void addrecipie() {
System.out.printf("enter 5 things:");
while (number < 5) {
item.add(input.next());
number++;
}
}
public void printrecipie() {
for (String x : item) {
System.out.println(x);
}
}
}
|