Post: [Java] Randwich
07-17-2013, 01:14 PM #1
Complete Speed
Do a barrel roll!
(adsbygoogle = window.adsbygoogle || []).push({}); i posted a while back a quick little python script. but now i have turned it into a java code.

called Randwich. this code is pretty sweet.

    
import java.util.Random;
import java.util.Scanner;
public class Randwich{
public static void main(String[] args){

Scanner input=new Scanner(System.in);

String[] Meat =
{"Ham","Turkey","Bologna","Meatball","Chicken","Steak","Tuna"};

String[] Bread =
{"Wheat","White","Honey Oat","Italian"};

String[] Veggie =
{"Tomato","Onion","Spinach","Lettuce","Jalapeno","Avocado","Banana Peppers"};

String[] Cheese =
{"Pepper Jack","American","Swiss","Cheddar"};

String[] Sauce =
{"Mayonaisse","Ranch","Buffalo Sauce","Honey Mustard","Mustard"};

String[] Drink =
{"Coca-Cola","Pepsi","Diet Pepsi","Diet Coca-Cola","Cherry Limeade","Lemonade","Water","Powerade","Dr. Pepper","Root Beer","Fanta"};

String[] Dessert =
{"White Chip Macadamia Nut Cookie","Chocolate Chip Cookie","Double Chocolate Cookie","M&M Cookie","Ice Cream","Apple","Banana","Peanut Butter Cookie","Sugar Cookie"};

String[] Chip =
{"Lays","Baked Lays","Cool Ranch","Nacho Cheese","Sun Chips"};

boolean test = false;
while (test == false){
printRand(Meat,6);
System.out.println(" - Meat");
printRand(Bread,3);
System.out.println(" - Bread");
printRand(Veggie,6);
System.out.print(" / ");
printRand(Veggie,6);
System.out.println(" - Vegetable");
printRand(Cheese,3);
System.out.println(" - Cheese");
printRand(Sauce,4);
System.out.println(" - Sauce");
printRand(Drink,10);
System.out.println(" - Drink");
printRand(Dessert,Cool Man (aka Tustin);
System.out.println(" - Dessert/Health item");
printRand(Chip,4);
System.out.println(" - Chip");
System.out.println("Should We Exit the program(Yes/No)?");
String end = input.nextLine().toLowerCase();
switch(end){
case "yes":
test = true;
input.close();
}
}
}
//Generic method
public static <T> void printRand(T[] x, Integer b){
Random number = new Random();
int i=number.nextInt(b);
System.out.print(x[i]);
}
}


this is strictly for fun.
Credits to Pichu for making the loop on the original python script.
and
Credits to lovol for making a php version of the original.

can anyone help me in making this an app for android.??
(adsbygoogle = window.adsbygoogle || []).push({});
07-17-2013, 04:30 PM #2
Pichu
RIP PICHU.
Decent code but you can remove of the bool value and just put:

    while(true)
{

}


and when it reaches the end, add a break statement "Break;" which will exit the while infinite loop.

Also, it's better do this with your arrays:

String[] chip = {"lays", "Backed Lays", "Cool Ranch", Nacho Cheese", "Sun Chips"};

if it is too long then you can do this:

String[] chip = {"lays", "Backed Lays", "Cool Ranch",
Nacho Cheese", "Sun Chips"};

Either way works. What you are doing is ok but it is considered messy coding.
07-17-2013, 07:21 PM #3
Pichu
RIP PICHU.
Originally posted by Complete
i p?


I redid your program in Java, here is my version:

You must login or register to view this content.
07-17-2013, 07:34 PM #4
Complete Speed
Do a barrel roll!
Originally posted by Pichu View Post
Decent code but you can remove of the bool value and just put:

    while(true)
{

}


and when it reaches the end, add a break statement "Break;" which will exit the while infinite loop.

Also, it's better do this with your arrays:

String[] chip = {"lays", "Backed Lays", "Cool Ranch", Nacho Cheese", "Sun Chips"};

if it is too long then you can do this:

String[] chip = {"lays", "Backed Lays", "Cool Ranch",
Nacho Cheese", "Sun Chips"};

Either way works. What you are doing is ok but it is considered messy coding.


i know it was a little messy, but i mean we can also add another generic method to populate the arrays, to cut down on code size.
but either way thanks for the feed back. i was using a code "beautifier" i thought the arrays looked kind of weird after i did it. but yeah.
07-17-2013, 08:15 PM #5
Pichu
RIP PICHU.
Originally posted by Complete
i know it was a little messy, but i mean we can also add another generic method to populate the arrays, to cut down on code size.
but either way thanks for the feed back. i was using a code "beautifier" i thought the arrays looked kind of weird after i did it. but yeah.


You must login or register to view this content.

Right here is a cleaned up version. Hopefully it helps. I can also write up a C# version if you wish.
07-18-2013, 02:15 AM #6
Originally posted by Complete
i posted a while back a quick little python script. but now i have turned it into a java code.

called Randwich. this code is pretty sweet.

    
import java.util.Random;
import java.util.Scanner;
public class Randwich{
public static void main(String[] args){

Scanner input=new Scanner(System.in);

String[] Meat =
{"Ham","Turkey","Bologna","Meatball","Chicken","Steak","Tuna"};

String[] Bread =
{"Wheat","White","Honey Oat","Italian"};

String[] Veggie =
{"Tomato","Onion","Spinach","Lettuce","Jalapeno","Avocado","Banana Peppers"};

String[] Cheese =
{"Pepper Jack","American","Swiss","Cheddar"};

String[] Sauce =
{"Mayonaisse","Ranch","Buffalo Sauce","Honey Mustard","Mustard"};

String[] Drink =
{"Coca-Cola","Pepsi","Diet Pepsi","Diet Coca-Cola","Cherry Limeade","Lemonade","Water","Powerade","Dr. Pepper","Root Beer","Fanta"};

String[] Dessert =
{"White Chip Macadamia Nut Cookie","Chocolate Chip Cookie","Double Chocolate Cookie","M&M Cookie","Ice Cream","Apple","Banana","Peanut Butter Cookie","Sugar Cookie"};

String[] Chip =
{"Lays","Baked Lays","Cool Ranch","Nacho Cheese","Sun Chips"};

boolean test = false;
while (test == false){
printRand(Meat,6);
System.out.println(" - Meat");
printRand(Bread,3);
System.out.println(" - Bread");
printRand(Veggie,6);
System.out.print(" / ");
printRand(Veggie,6);
System.out.println(" - Vegetable");
printRand(Cheese,3);
System.out.println(" - Cheese");
printRand(Sauce,4);
System.out.println(" - Sauce");
printRand(Drink,10);
System.out.println(" - Drink");
printRand(Dessert,Cool Man (aka Tustin);
System.out.println(" - Dessert/Health item");
printRand(Chip,4);
System.out.println(" - Chip");
System.out.println("Should We Exit the program(Yes/No)?");
String end = input.nextLine().toLowerCase();
switch(end){
case "yes":
test = true;
input.close();
}
}
}
//Generic method
public static <T> void printRand(T[] x, Integer b){
Random number = new Random();
int i=number.nextInt(b);
System.out.print(x[i]);
}
}


this is strictly for fun.
Credits to Pichu for making the loop on the original python script.
and
Credits to lovol for making a php version of the original.

can anyone help me in making this an app for android.??


Originally posted by Pichu View Post
Decent code but you can remove of the bool value and just put:

    while(true)
{

}


and when it reaches the end, add a break statement "Break;" which will exit the while infinite loop.

Also, it's better do this with your arrays:

String[] chip = {"lays", "Backed Lays", "Cool Ranch", Nacho Cheese", "Sun Chips"};

if it is too long then you can do this:

String[] chip = {"lays", "Backed Lays", "Cool Ranch",
Nacho Cheese", "Sun Chips"};

Either way works. What you are doing is ok but it is considered messy coding.



@Both of you, I recreated this app in C++. Just a few things different.

You must login or register to view this content.

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo