Question

In: Computer Science

*In JAVA and JavaFX please!! CSE1322 – Assignment 8 – GUI General User Interface Assignment 8...

*In JAVA and JavaFX please!!

CSE1322 – Assignment 8 – GUI
General User Interface
Assignment 8
Objectives
• Build a GUI application similar to a calculator.
• Create an application that acts as a simple calculator. Create buttons for 0-9 and a text
field that displays the concatenation of the current digits as they are clicked.
• Add buttons for operators “+”, “-“, “*”, and “/”.
• Add a final button for “=” that calculates the computed value with the value entered in
the text field. For instance, clicking buttons 7, +, 8, = should display 15.
Tasks
This assignment has two parts (one for the front-end and another for the back-end):
1. Front-End: Building the window (Making the GUI buttons and the Label).
2. Back-End: Making the variables to store the values and event handlers that are
responsible for handling the actions of the Label and Buttons.
Overall Objective: You will need create a calculator with the that can add, subtract, divide, and
multiply numbers. This calculator should not rely on textboxes to enter in values but should have
an array of buttons one through nine for the numbers and buttons for the operations.
Logical Insight: How Should the Program Work?
When a numerical or operator button is clicked it should concatenate its number or operator to
the current calculation. For example, it should show the value “98” if the buttons “9” and “8”
were clicked. However, if an operator button was clicked between two numbers then it should
show that operator between the values. For example, it should show “9 / 8” if the buttons “9”,
then “/”, and then “8” were clicked. It is important to note that if we click “9”, then “8”, then “/”,
and finally “8” we would get “98 / 8”.
The equal (=) button is special in that if it is clicked after a valid operation occurs it should
replace the whole equation with the result of the calculation. Therefore, we should never see the
“=” in the label. For instance, “98 / 8” evaluates to 12.25, so the label should show “12.25” after
the equal sign button is clicked.
NOTE: Assume that the equal sign is only pressed after at least two separate numbers and an
operator are entered and that the user will want to use that as their first number for the next
operation. That means if a new number is pressed, then it will be added to the end (as the last
digit) of the result from the last operation. Also, this should work for at least two (2) digits, but
your calculations do not need to work for more than that.
Page 2 of 4
Front-End – Building the Window
Using the knowledge acquired in the Lab 8, construct a GUI window with buttons for the
numbers zero (0) through nine (9), and buttons for addition (+), subtraction (-), multiplication
(*), division (/) and finally equality (=). Also add a label object in your window that will fill up
with the numbers/operator buttons being pressed (this text field should show the complete
formula before pressing the “=” button). You should be familiar with this as a result of doing Lab
8.
Back-End – Make the Event Handlers and the Variables to Store Values
In Java you will need to create variables to store the values in the Controller Class as well
as variables to store what will appear in the Label; Event Handlers should also be created that
will take care of what happens when buttons are pressed. How to do this is mentioned in detail in
the explanation sections in Lab 8.
In C# you will need to create variables that should store the values for when the buttons
are pressed in the GUI in the Form1.cs file. In addition, Event Handlers (in the form of methods)
should also be created to handle what these button presses do on a per button by button bases.
Labels should be created and named in the GUI portion. How to do this is mentioned in detail in
the explanation sections in Lab 8.
For example, for when the equality (=) is clicked, ideally one of these variables will be
the result variable that will hold the final solution. There should be an event handler (event and
event listener for C#) that is triggered by the clicking of the equality (=) button that goes and
retrieves the value in the result variable and displays it on the label instead of the previous
function that was being displayed.
Intentionally Left Blank
Below is some possible sample output (note: ∃ simply means, “there exists”):
The last button pressed has a dark blue highlight around the edges.

Solutions

Expert Solution

• Build a GUI application similar to a calculator.
import java.util.Scanner;
public class Calculator {
   public static void main(String[] args) {
      double num1;
      double num2;
      double ans;
      char op;
      Scanner reader = new Scanner(System.in);
      System.out.print("Enter two numbers: ");
      num1 = reader.nextDouble();
      num2 = reader.nextDouble();
      System.out.print("\nEnter an operator (+, -, *, /): ");
      op = reader.next().charAt(0);
      switch(op) {
         case '+': ans = num1 + num2;
            break;
         case '-': ans = num1 - num2;
            break;
         case '*': ans = num1 * num2;
            break;
         case '/': ans = num1 / num2;
            break;
      default: System.out.printf("Error! Enter correct operator");
         return;
      }
      System.out.print("\nThe result is given as follows:\n");
      System.out.printf(num1 + " " + op + " " + num2 + " = " + ans);
   }
}

If you need python code i wil provide also,Thank you


Related Solutions

Develop a JavaFX GUI application called Registration that implements a user interface for registering for a...
Develop a JavaFX GUI application called Registration that implements a user interface for registering for a web site. The application should have labeled text fields for the Full Name, User Name, Password, Student Id, and a TextAreafor About Me. Include a button labeled Send. When the Send button is clicked, your program should print the contents of all fields (with labels) to standard output using println()statements.
Use the below info to create a java program A GUI interface to ensure a user...
Use the below info to create a java program A GUI interface to ensure a user is old enough to play a game. Properly formatted prompts to input name, address, phone number, and age. Remember that name, address, phone number, etc. can be broken out in additional fields. Refer to the tutorial from this week’s Reading Assignment Multiple vs. Single Field Capture for Phone Number Form Input for help with this. Instructions to ensure that the information is displayed back...
The purpose of this problem is to use graphic user interface (GUI) to interactively store grades...
The purpose of this problem is to use graphic user interface (GUI) to interactively store grades in a text file, rather than adding them manually to a script. Follow these steps to complete the program: Step 1. Use a question dialog box and ask the user “Do you want to run this Program?” with two options for “yes” and “no”. If the user’s answer is “yes”, go to the next step, otherwise, go to Step 6. Step 2. Create a...
Using matlab: Build a graphical user interface (GUI) the will read the two corners of a...
Using matlab: Build a graphical user interface (GUI) the will read the two corners of a rectangle (from the GUI interface) and show the following: A plot of the rectangle (you should have display for it) Show the centroid (the center of the rectangle) on the graph. Calculate the area and the circumference of the triangle (you need to write a function for that). The interface should have at least the following: Four textboxes to read the ( 2 for...
Using a (GUI interface), write a Java program that simulates an ATM machine with the following...
Using a (GUI interface), write a Java program that simulates an ATM machine with the following options menu: "Welcome" 1. Deposit to account 2. Withdraw 3. Exit
Im trying to get a GUI interface in java where there is four text fields for...
Im trying to get a GUI interface in java where there is four text fields for the first name, last name, department, and phone number of employee in a program. Then also have a radio button below for Gender (Male/Female/Other) and a list for the Title (Mr./Ms./Mrs./Dr./Col./Prof.). At the very bottom of the frame there has to be buttons for printing, submitting and exiting but for whatever reason when I tried it nothing appears in the frame regardless of what...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java Swing GUI application in a new Netbeans project called FortuneTeller. Your project will have a FortuneTellerFrame.java class (which inherits from JFrame) and a java main class: FortuneTellerViewer.java. Your application should have and use the following components: Top panel: A JLabel with text “Fortune Teller” (or something similar!) and an ImageIcon. Find an appropriate non-commercial Fortune Teller image for your ImageIcon. (The JLabel has a...
Apply JavaFX and exception handling to design a CircleApp class using proper JavaFX GUI components, such...
Apply JavaFX and exception handling to design a CircleApp class using proper JavaFX GUI components, such as labels, text fields and buttons(Submit, Clear, and Exit) to compute the area of circle and display the radius user entered in the text field and computing result in a proper location in the application windows. It will also verify invalid data entries for radius(No letters and must be a postive real number) using expection handling. Your code will also have a custom-designed exception...
Create in java an interactive GUI application program that will prompt the user to use one...
Create in java an interactive GUI application program that will prompt the user to use one of three calculators, label project name MEDCALC. You can use any color you want for your background other than grey. Be sure to label main java box with “MEDCALC” and include text of “For use only by students” On all three calculators create an alert and signature area for each user. The alert should be something like “All calculations must be confirmed by user...
Java program Statement: Provide a user interface to the invoice program in Section 12.3 that allows...
Java program Statement: Provide a user interface to the invoice program in Section 12.3 that allows a user to enter and print an arbitrary invoice. Do not modify any of the existing classes. ..... ..... ..... /** Describes an invoice for a set of purchased products. */ public class Invoice { /** Adds a charge for a product to this invoice. @param aProduct the product that the customer ordered @param quantity the quantity of the product */ public void add(Product...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT