I am just learning to use Java and I am trying to make a simple Yards to feet or Inches to CM converter. I have made the Yards to feet converter and it works but now I want the user to get an option to pick between using the Y/f or the I/C converter. How do I make them pick an option between the two. Here's what I have coded so far:
import java.util.Scanner;
public class yardcalc {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
double Feet = 0;
double yard = 0;
int format = 3;
System.out.println("Enter yard(s): "); //Asks the user for the amount of yards
Drhu actually is teaching me Java right now. He gave me a project to do yesterday which was pretty simple and I wanted to try something harder. I can the two different converters very easily its just combining them that is hard for me to figure out. I am trying to use "if" but I can't really figure it out.
String input;
Scanner keyboard = new Scanner(System.in);
System.out.println("Type \"f\" for yards to feet or \"c\" for inches to cm");
input = keyboard.nextLine();
if(input.equalsIgnoreCase("f" )){
//code for yards to feet
}
else if(input.equalsIgnoreCase("c")){
//code for inches to cm.
}
else
System.out.println("Try again");
Utilize the jframe, very useful for this sort of thing.
Code:
Object[] options = {"Yards/Feet", "Inch/Cm"};
int response = JOptionPane.showOptionDialog(frame,
"Which Conversion would you like to use?",
"Conversion Type",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[0]);
Utilize the jframe, very useful for this sort of thing.
Code:
Object[] options = {"Yards/Feet", "Inch/Cm"};
int response = JOptionPane.showOptionDialog(frame,
"Which Conversion would you like to use?",
"Conversion Type",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[0]);