Results 1 to 2 of 2
  1. #1
    MrOrson is offline Member
    Join Date
    Mar 2017
    Rep Power

    Post Java Functions and Sub-Routines

    I am currently working on a homework set in a computer science class that i'm having trouble with. I am quite new to java and so this seems quite complex to me, although i'm aware it's very basic.
    I was given pseudocode and told to build a program based off of it.
    This is the code i have written based off of the pseudocode i was given.

    Java Code:
    public class slotsGamrMain {
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Scanner input = new Scanner(;
    		int plays;
    		System.out.println("Welcome to the super slots game.");
    		System.out.println("Enter number of plays you want, you must enter at least one play.");
    		plays = input.nextInt();
    		if(plays == 0){
    			System.out.println("No plays chosen");
    			else if (plays >=1){
    				plays = plays -1;
    	public static void DisplayOnScreen(){
    		int LeftVal = GenerateNumber();
            int MidVal = GenerateNumber();
            int RightVal = GenerateNumber();
            FruitVal1 = strFruitArr[LeftVal];
            FruitVal2 = showFruit[MidVal];
            FruitVal3 = showFruit[RightVal];
            System.out.println("               |",FruitVal1, "|", FruitVal2, "|", FruitVal3, "|           ");
            ShowWinner(LeftVal, MidVal, RightVal);
    	public int ShowWinner(inLeft, inMid, inRight){
    		if(inLeft == 1){
    			System.out.println("You win 3 more goes!");
    			plays = plays + 3;
    		else if(inMid == 1 && inRight ==2){
    			System.out.println("You win 6 more goes!");
    			plays = plays + 6;
    		else if(inLeft == 4 && inMid == 4 && inRight == 4){
    			System.out.println("You win 10 more goes!");
    			plays = plays + 10;
    	public String showFruit(int inVal) {
    		String[] strFruitArr = new String[6];
    		strFruitArr[0] = "Orange";
    		strFruitArr[1] = "Pear";
    		strFruitArr[2] = "Banana";
    		strFruitArr[3] = "Cherry";
    		strFruitArr[4] = "Lemon";
    		strFruitArr[5] = "Apple";
    		strFruitArr[6] = "Bar";
    		while(inVal > 0){
    			if(inVal == 0){
    				return strFruitArr[0];
    			else if (inVal == 7){
    				return strFruitArr[6];
    				return strFruitArr[inVal];
    	static int GenerateNumber() {
    		int generated = (int) (7 * Math.random() +1);
    		return generated;
    My initial thoughts is that each function/subroutine wont link because of the way in which i have assigned them. For example, "public String showFruit(int inVal)" probably isn't the right way to go about this section of code.
    I was hoping someone could explain the different functions in java and how to assign them properly. Also, my theory that it isnt working because of the functions may be completely incorrect of course, and so please do correct me if i'm wrong .
    Any help is appreciated.
    Last edited by MrOrson; 03-12-2017 at 05:09 PM. Reason: Forgot to attach document

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default Re: Java Functions and Sub-Routines

    the different functions in java
    Here is a link to the tutorial on java methods(what you've called functions): Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Accessing java routines from jsp
    By avcaballero in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 12-02-2013, 10:50 AM
  2. Java functions
    By victorq in forum New To Java
    Replies: 5
    Last Post: 10-26-2011, 08:40 PM
  3. Calling java functions from c++
    By khajalid in forum New To Java
    Replies: 13
    Last Post: 10-12-2010, 10:50 PM
  4. Can C++ routines be called from Java program
    By gkk in forum New To Java
    Replies: 2
    Last Post: 07-20-2010, 09:43 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts