java - Calling a class from same package and assigning variables -
i'm trying pull restaurantselector1 class cuisinechoice can able have users input choices can assign variables in restaurantselector1(if makes sense. have:
in restaurantselector1:
public class restaurantselector1 { public static string getrandom(list<string[]> list) { random random = new random(); int listaccess = random.nextint(list.size()); string[] s = list.get(listaccess); return s[random.nextint(s.length)]; } public static void main(string[] args){ arraylist<string[]> westvillagecuisine = new arraylist<string[]>(); westvillagecuisine.add(expensive.westvillage.italian); . . . westvillagecuisine.add(expensive.westvillage.greek); final string[] randomcuisine = westvillagecuisine.get(random.nextint(westvillagecuisine.size())); final string randomrestaurant = randomcuisine[random.nextint(randomcuisine.length)]; final string[] randomwvitalian = westvillagecuisine.get(0); final string westvillageitalian = r randomwvitalian[random.nextint(randomwvitalian.length)]; system.out.println(getrandom(westvillagecuisine)); system.out.println(randomrestaurant); system.out.println(westvillageitalian); }
and cuisine choice class:
class cuisinechoice{ public static void main(string[] args){ restaurantselector1 = new restaurantselector1(); system.out.println("what price range looking for? 1 = $-$$ , 2 = $$$-$$$$"); scanner scan2 = new scanner(system.in); string price = scan2.next(); if (price.equals("two")){ price = "expensive"; system.out.println("in neighborhood eat?"); scanner scan = new scanner(system.in); string location = scan.next(); if (null != location)switch (location) { case "tribeca":{ system.out.println("great! , type cuisine in " + location + " ?"); scanner scan1 = new scanner(system.in); string type = scan1.next(); system.out.print(location + " " + type + " " + price); break; } case "west village":{ system.out.println("great! , type cuisine in " + location + " ?"); scanner scan1 = new scanner(system.in); string type = scan1.next(); system.out.print(location + " " + type + " " + price); break; } case "flatiron":{ system.out.println("great! , type cuisine in " + location + " ?"); scanner scan1 = new scanner(system.in); string type = scan1.next(); system.out.print(location + " " + type + " " + price); break; } case "chelsea":{ system.out.println("great! , type cuisine in " + location + " ?"); scanner scan1 = new scanner(system.in); string type = scan1.next(); system.out.print(location + " " + type + " " + price); break; } default: break; } } else{ price= "inexpensive"; system.out.println("in neighborhood eat?"); scanner scan3 = new scanner(system.in); string location1 = scan3.next(); if (null != location1)switch (location1) { case "tribeca":{ system.out.println("great! , type cuisine in " + location1 + " ?"); scanner scan1 = new scanner(system.in); string type = scan1.next(); system.out.print(location1 + " " + type + " " + price); break; } case "west village":{ system.out.println("great! , type cuisine in " + location1 + " ?"); scanner scan1 = new scanner(system.in); string type = scan1.next(); system.out.print(location1 + " " + type + " " + price); break; } case "flatiron":{ system.out.println("great! , type cuisine in " + location1 + " ?"); scanner scan1 = new scanner(system.in); string type = scan1.next(); system.out.print(location1 + " " + type + " " + price); break; } case "chelsea":{ system.out.println("great! , type cuisine in " + location1 + " ?"); scanner scan1 = new scanner(system.in); string type = scan1.next(); system.out.print(location1 + " " + type + " " + price); break; } default: break; } } } }
i can't figure out how use user inputs of location , cuisine types inputs random restaurant of cuisine in location. i'm having trouble getting restaurantselector1 class show in cuisinechoice @ all.
any appreciated!
both have main method, 1 start point of application, , structure of application, in same package or different package? , have typo in code if statement, doesn't have "{" open statement, , in case statement don't need "{}".
if (null != location)switch (location) {
it should be:
if (null != location){ switch (location) {
Comments
Post a Comment