1. Welcome to PHCorner Forums. Take a moment to Sign up and gain unlimited access and extra privileges that guests are not entitled to, such as:

    All that and more! Registration is quick, simple and absolutely free. Join our community today!

Help Java programming (debug, return value)

Discussion started by renigmaticx, Dec 7, 2018 at 6:10 PM.

  1. renigmaticx

    renigmaticx Addict Established

    Hello po mga master patulong naman po ako sa codes ko, hindi ko po kasi matukoy kung pano ko makukuha yung return value nung methods na [1]FindHighest [2]FindLowest [3] FindMiddle na gagamitin ko sa method na ShowMenu. Baguhan lang ako at halos hindi ko alam pasikot sikot sa Java. Nahihirapan na ko kakaisip. Kaya sa mabait na master dyan patulong naman po ng techniques sa codes at error dito sa code. Thank you so much.

    import java.io.*;

    public class labhehe
    {
    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    public static int GetInput() throws IOException
    {
    int num;
    System.out.print("Enter a value: ");
    num = Integer.parseInt(in.readLine());
    return num;
    }

    public static boolean CheckValues(int num1, int num2, int num3) throws IOException
    {
    boolean checking = true;
    if (num1 == num2 && num1 == num3)
    {
    System.out.println("All numbers are equal");
    }
    else if (num1 == num2 || num1 == num3)
    {
    System.out.println("Neither all are equal or different");
    }
    else
    {
    checking = false;
    checking = ShowMenu();
    }
    return checking;
    }

    public static void ShowMenu(int num1, int num2, int num3, int category) throws IOException
    {
    int choice;
    boolean checking;
    if (checking == false)
    {
    System.out.print("Press [1] HIGHEST \nPress [2] MIDDLE \nPress [3] LOWEST \nPlease enter your choice: ");
    choice = Integer.parseInt(in.readLine());
    switch (choice)
    {
    case 1:
    {
    System.out.print("The highest value between " + num1 + ", " + num2 + ", " + num3 + ", is " + category);
    break;
    }
    case 2:
    {
    System.out.print("The middle value between " + num1 + ", " + num2 + ", " + num3 + ", is " + category);
    break;
    }
    case 3:
    {
    System.out.print("The lowest value between " + num1 + ", " + num2 + ", " + num3 + ", is " + category);
    break;
    }
    default:
    {
    System.out.print("Invalid");
    }
    }
    }
    }

    public static int FindHighest(int num1, int num2, int num3)
    {
    int category;
    if (num1 > num2 && num1 > num3)
    {
    category = num1;
    }
    else if (num2 > num1 && num2 > 3)
    {
    category = num2;
    }
    else
    {
    category = num3;
    }
    return category;
    }

    public static int FindMiddle(int num1, int num2, int num3)
    {
    int category;
    if (num1 < num2 && num1 < num3)
    {
    category = num1;
    }
    else if (num2 < num1 && num2 < 3)
    {
    category = num2;
    }
    else
    {
    category = num3;
    }
    return category;
    }

    public static int FindLowest(int num1, int num2, int num3)
    {
    int category;
    if (num1 < num2 && num1 < num3)
    {
    category = num1;
    }
    else if (num2 < num1 && num2 < 3)
    {
    category = num2;
    }
    else
    {
    category = num3;
    }
    return category;
    }

    public static void main(String[] args) throws IOException
    {
    int num1, num2, num3, category = 0;
    num1 = GetInput();
    num2 = GetInput();
    num3 = GetInput();
    CheckValues(num1, num2, num3);
    ShowMenu(num1, num2, num3, category);


    }
    }
     
  2. renigmaticx

    renigmaticx Addict Established

  3. Zyzz

    Zyzz Forum Veteran Established

  4. Zyzz

    Zyzz Forum Veteran Established

    Yung pag call mo ng ShowMenu() method within CheckValues() method ay walang parameters which is error kasi based sa method declaration mo ng ShowMenu naglagay ka ng paramaters.
     
    renigmaticx likes this.
  5. Code:
    ublic static boolean CheckValues(int num1, int num2, int num3) throws IOException
    {
    boolean checking = true;
    if (num1 == num2 && num1 == num3)
    {
    System.out.println("All numbers are equal");
    }
    else if (num1 == num2 || num1 == num3)
    {
    System.out.println("Neither all are equal or different");
    }
    else
    {
    checking = false;
    checking = ShowMenu();
    }
    return checking;
    }
    Bakit hindi return ShowMenu(); ?
     
    renigmaticx likes this.
  6. Zyzz

    Zyzz Forum Veteran Established

    Once na mag de-declare ka ng variables sa java, accessible lang siya within the scope, halimbawa: nag declare ka ng variable inside the method then accesible lang siya within that method; nag declare ka ng variables inside a class then accessible lang siya within that class.
     
    renigmaticx likes this.
  7. Zyzz

    Zyzz Forum Veteran Established

    Mali din siya sa part na:
    checking = ShowMenu();

    Si checking ay boolean data types then inassigned niya ng value sa ShowMenu() method which is void na hindi nag re-return ng value, isa pa gaya ng nasabi ko kanina yung pag call niya ng ShowMenu() ay walang parameters which is sa declaration niya ay meron.
     
    renigmaticx and PHC-Jeremy like this.
  8. renigmaticx

    renigmaticx Addict Established

    T
    Thank you po, galing nyo po master dami ko po natutunan sige po itatry ko po idebug ulit. Salamat po sa tulong.
     
  9. renigmaticx

    renigmaticx Addict Established

    Gusto ko po kasi ireturn yung value nung bool checking which is gagamitin ko po sa show menu para magtrigger yung code na magexecute kapag nag false yung checking. E hindi ko pa po kasi alam kung pano magreturn ng value from one method to another. Nalilito po kasi ako.
     
Tags:
  1. PHCorner uses cookies to help personalise content and tailor your experience. By continuing to use this site, you are consenting to our use of cookies. Accept Learn More
    Dismiss Notice