+ 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

18th Aug 2017, 10:29 AM
Michael Gilbert Acuña
Michael Gilbert Acuña - avatar
9 odpowiedzi
+ 10
For code clarity define two separate functions and call them according to the initial input value.
18th Aug 2017, 10:31 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 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 */
18th Aug 2017, 11:57 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 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.
18th Aug 2017, 12:45 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 4
Use switch, in this case.
18th Aug 2017, 10:32 AM
Dragon Slayer Xavier
Dragon Slayer Xavier - avatar
+ 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
18th Aug 2017, 12:04 PM
Changed
Changed - avatar
+ 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
18th Aug 2017, 10:53 AM
Changed
Changed - avatar
+ 1
Mr. Siekierzyński, what function should I use in able to do it?
18th Aug 2017, 10:33 AM
Michael Gilbert Acuña
Michael Gilbert Acuña - avatar
+ 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.
18th Aug 2017, 11:00 AM
D_Stark
D_Stark - avatar
18th Aug 2017, 11:03 AM
D_Stark
D_Stark - avatar