+ 2
How could I put 2 program in one code in Java?
Linking Program. A code in Java wherein a two different type of program is being put together. For example, Simple calculator and Temperature convertion in one code. Output might be like this: Choose a program(click 1 for simple calculator and 2 for temperature convertion) /**for example I choose 1. 1 /**then the simple calculator will appear on the screen
9 Réponses
+ 10
For code clarity define two separate functions and call them according to the initial input value.
+ 7
I had in mind something like:
import java.util.*;
public class Main
{
public static void main(String[] args)
{
System.out.println("Choose '1' or '2':");
System.out.println("1. Calculator");
System.out.println("2. Converter");
Scanner input = new Scanner(System.in);
String app = input.nextLine();
if (app == "1")
{
Calculator();
}
if (app == "2")
{
Converter();
}
}
}
/* you just need to define the functions themselves, as each of them will be doing a different thing, probably asking for different types of data, ultimately */
+ 6
I realize, but the logic will be the same whether GUI or non-GUI. Although for GUI this actually would be an event-based code structure, most likely.
+ 4
Use switch, in this case.
+ 4
@kuba ,
he is thinking that it is java (gui) here where we can make forms to take input
but its java (non-gui) here ....he needs to understand this
+ 3
hey bro u need to take a single input
then apply method1 on input //for temperature , let it be from celcius to kelvin
then apply method2 on input//for calaculator , let it be u need its sum with 2
and print output though each method
note : here , it is java (non-gui)
&might u be usinv java (gui) through netbeans , thats why u r asking this question
+ 1
Mr. Siekierzyński, what function should I use in able to do it?
+ 1
not on here dude best you use gui for that type of interface.
i made a very simple tempture converter if you like to see might get an idea how java works on here
i could intergate a calculator but would have to run both thorough the scanner.