What's new
  • 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)

renigmaticx

Addict
Established
Joined
Sep 11, 2016
Messages
348
Reaction score
87
Age
19
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);


}
}
 

Zyzz

Forum Guru
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.
 

Arcturus

Forum Guru
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(); ?
 

Zyzz

Forum Guru
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.
 

Zyzz

Forum Guru
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(); ?
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.
 
T
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.
Thank you po, galing nyo po master dami ko po natutunan sige po itatry ko po idebug ulit. Salamat po sa tulong.
 
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(); ?
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.
 

Trending Topics

Trending On This Forum

New Topics On This Forum

Top