package labs1301;
import java.util.Scanner;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax. swing.JOptionPane;
import java.util.Scanner;
import java.util.Scanner;
import java.util.Scanner;
import java.util.Scanner;
public class Java1301lab6 {
private static String Operand2 = null;
public static void main(String[] args) {
JFrame frame = new JFrame("My Lab6 Calculator");
String author = "Khandoker Rahad"; // TASK 1: this requires your attention ***********************
JOptionPane.showMessageDialog(frame, "Welcome to " + author + "'s calculator!");
// Now, let's ask the user to pick an operation among a set (bulk memory) of defined operators
String[] operators = {"+", "-", "*", "/"};
// Selecting an operator *******************************************************************************
String chosenOperator = (String) JOptionPane.showInputDialog(frame,
"Which operation do you want to use?",
"Chosen Operator",
JOptionPane.QUESTION_MESSAGE,
null,
operators,
operators[0]);
while (chosenOperator == null) {
chosenOperator = (String) JOptionPane.showInputDialog(frame,
"Please select an operator",
"Chosen Operator",
JOptionPane.QUESTION_MESSAGE,
null,
operators,
operators[0]);
}
// Selecting operands ***********************************************************************************
String Operand1 = (String) JOptionPane.showInputDialog(frame,
"What's your first operand?",
"Operand 1",
JOptionPane.QUESTION_MESSAGE
);
Operand2 = (String) JOptionPane.showInputDialog(frame,
"What's your second operand?",
"Operand 2",
JOptionPane.QUESTION_MESSAGE );
float operand1 = Float.valueOf(Operand1);
// float operand2;
division();
//float operand2 = 5000;
while(operand2==0){
JOptionPane.showMessageDialog(frame, "Enter a valid value " );
operand2 = Float.valueOf(Operand2);
}
//System.out.print("Enter valid value");
//operand2 = float.valueOf(Operand2);
//}
// TASK 2 ************************************************************************************************
// Here you should get operand2 in the same fashion as you got operand1 in the first place
// TASK 3 ************************************************************************************************
// Now think of it: if your operator is a division, you should not accept 0 as the second operand
// So you have to put in place a while loop (similar to the one about the choice of operator) that keeps
// prompting the user to enter a second operand while the user enters 0
if (chosenOperator.compareTo("/") == 0)
JOptionPane.showMessageDialog(frame, "Your result is " + ( operand1 /operand2) + "!");
// TASK 4 ************************************************************************************************
// Here you need to add the other operators
// System.exit(0);
}
public static void division()
{
// <-- Note that Java is case sensitive :)
float operand2 = Float.valueOf(Operand2);
//Scanner sc=new Scanner(System.in);
// int operand=sc.nextInt();
// return operand;
}
}