- 4
Meaning and usage of the word "option"
Java/usage of options
20 Answers
+ 1
Your question is not clear and also it does not make sense.
+ 1
Where is it used in Java?
Never heard of it.
+ 1
There is no keyword as "option" in Java and whatever you have watched in the video may be is a program where he might have declared a variable option.
How are we the people on QA suppose to know what it means or what it does?
+ 1
Ok, soon
+ 1
That's all
+ 1
Farrux To`laganov
Please see in your second reply, first line:
char option = '\0';
And a few lines underneath:
option = scanner.next.charAt(0);
And also below that line:
switch(option)
{
// more codes here
}
Can you see now what Avinesh meant when he said "he might have declared a variable option"?
+ 1
Farrux To`laganov
For the next time please save the code in your profile and share the code link instead. Especially if the code is big (like more than 15 lines).
It is more comfortable for everyone to review a code rather than raw text like that. Hope you understand.
Follow this guide so your next question can gain better responses 👍
https://www.sololearn.com/Discuss/333866/?ref=app
https://www.sololearn.com/post/74857/?ref=app
+ 1
Good a job, 10Q
+ 1
char option = '\0'
option = scanner.next().charAt(0);
option is a variable, not an element.
0
Can you explain me when to use it
0
I've faced with this while watching a video about making bank account
0
Let's wait for others views
0
I think this doubt can be solved if you can share the code with the people here, or at least a portion of the code where you saw that 'option' word is being used.
I guess that would be the best way to clear up ambiguity in the question, and prevent misunderstanding Farrux To`laganov
0
package project;
import java.util.Scanner;
public class teamproj {
public static void main(String[] args) {
// TODO Auto-generated method stub
BankAccount obj1= new BankAccount("XYZ", "BA0001");
obj1.showMenu();
}
}
class BankAccount
{
int balance;
int previousTransaction;
String customerName;
String customerID;
BankAccount(String name, String ID)
{
customerName=name;
customerID=ID;
}
void deposit(int amount)
{
if(amount !=0)
{
balance=balance+amount;
previousTransaction=amount;
}
}
void withdraw(int amount)
{
if(amount !=0)
{
balance=balance-amount;
previousTransaction=-amount;
}
}
void getPreviousTransaction()
{
if(previousTransaction>0)
{
System.out.println("Deposited: "+previousTransaction);
}
else if(previousTransaction<0)
{
System.out.println("Withdrawn: "+Math.abs(previousTransaction));
}
else
{
System.out.println("No transaction occured");
}
}
0
void showMenu()
{
char option='\0';
Scanner scanner = new Scanner(System.in);
System.out.println("Welcome "+customerName);
System.out.println("Your ID "+customerID);
System.out.println("\n");
System.out.println("A. Check Balance");
System.out.println("B.Deposit");
System.out.println("C.Withdrow");
System.out.println("D.Previous Transaction");
System.out.println("E.Exit");
do
{
System.out.println("============================================");
System.out.println("Enter an option");
System.out.println("============================================");
option = scanner.next().charAt(0);
System.out.println("\n");
switch(option)
{
case 'A':
System.out.println("- - - - - - - - - - - - - - - - - - - - - - - ");
System.out.println("Balance"+balance);
System.out.println("- - - - - - - - - - - - - - - - - - - - - - - ");
System.out.println("\n");
break;
case 'B':
System.out.println("- - - - - - - - - - - - - - - - - - - - - - - ");
System.
0
case 'B':
System.out.println("- - - - - - - - - - - - - - - - - - - - - - - ");
System.out.println("Enter an amount to deposit: ");
System.out.println("- - - - - - - - - - - - - - - - - - - - - - - ");
int amount = scanner.nextInt();
deposit(amount);
System.out.println("\n");
break;
case 'C':
System.out.println("- - - - - - - - - - - - - - - - - - - - - - - ");
System.out.println("Enter an amount to withdraw");
System.out.println("- - - - - - - - - - - - - - - - - - - - - - - ");
int amount2=scanner.nextInt();
withdraw(amount2);
System.out.println("\n");
break;
case 'D':
System.out.println("- - - - - - - - - - - - - - - - - - - - - - - ");
getPreviousTransaction();
System.out.println("- - - - - - - - - - - - - - - - - - - - - - - ");
System.out.println("\n");
break;
case 'E':
System.out.println("***********************************************");
break;
default:
System.out.println("Invalid Option!!!. Pleease enter a
0
System.out.println("Invalid Option!!!. Pleease enter again");
break;
}
}
while(option !='E');
System.out.println("Thank you for using our services");
}}
0
Well char is variable and option is the name of the variable.
Variables are containers for storing data values.
All java variable must be identified with unique names.
These unique names are called identifier.
Identifier can be short name (like x and y) or more descriptive name (age, sum, totalValue)
Note: it is recommended to use more descriptive name to create Maintainable and understandable code.
0
Option?
In html
Or what
0
It was in java, fortunately I understood