Loading...

Messages

Proposals

Stuck in your homework and missing deadline? Get urgent help in $10/Page with 24 hours deadline

Get Urgent Writing Help In Your Essays, Assignments, Homeworks, Dissertation, Thesis Or Coursework & Achieve A+ Grades.

Privacy Guaranteed - 100% Plagiarism Free Writing - Free Turnitin Report - Professional And Experienced Writers - 24/7 Online Support

How to use javafx to make a calculator

23/10/2021 Client: muhammad11 Deadline: 2 Day

framework/.DS_Store
__MACOSX/framework/._.DS_Store
framework/application.css
/* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */ .vbox1 { -fx-background-color:rgb(20,64,144); -fx-padding: 20; -fx-font-size: 30; } .button{ -fx-background-color:rgb(174,184,219); } .btnEqual{ -fx-background-color:rgb(61,127,61); -fx-text-fill:white; } .btnClear{ -fx-background-color:rgb(155,56,54); -fx-text-fill:white; } .btnBackspace{ -fx-background-color:rgb(80,80,80); -fx-text-fill:white; } .vbox2 { -fx-background-color:rgb(207,59,62); -fx-padding: 20; -fx-font-size: 20; } .vbox3 { -fx-background-color:rgb(90,207,9); -fx-padding: 20; -fx-font-size: 20; } .style1 { -fx-background-color:rgb(217,144,185); } .style2 { -fx-text-fill:red; } .screen1 { -fx-background-color: #FFFFFF; -fx-min-width: 50; -fx-min-height: 50; } .screen2 { -fx-background-color: #FFFFFF; -fx-text-alignment:left ; }

__MACOSX/framework/._application.css
framework/Calculator.java
framework/Calculator.java
package application ;

import javafx . application . Application ;
import javafx . beans . binding . Bindings ;
import javafx . beans . property . DoubleProperty ;
import javafx . beans . property . SimpleDoubleProperty ;
import javafx . event . ActionEvent ;
import javafx . event . EventHandler ;
import javafx . geometry . Pos ;
import javafx . scene . Scene ;
import javafx . scene . control . Button ;
import javafx . scene . control . TextField ;
import javafx . scene . layout . TilePane ;
import javafx . scene . layout . VBox ;
import javafx . scene . text . Font ;
import javafx . stage . Stage ;
import javafx . stage . StageStyle ;

/* This is the GUI class that visualize the calculator
*
* */
public class Calculator extends Application {

private MyStack stack = new MyStack ();
private double font_size = 30 ; //by default the font size on the screen is 30

/*The keyboard key values*/
private static final String [][] key_values = {
{ "0" , "=" , "c" , "<" },
{ "1" , "2" , "3" , "-" },
{ "4" , "5" , "6" , "*" },
{ "7" , "8" , "9" , "+" }
};
private Button btn [][] = new Button [ 4 ][ 4 ]; //all the key buttons
TextField calculator_screen ; //the calculator screen


public static void main ( String [] args ) { launch ( args ); }

@ Override public void start ( Stage stage ) {

/*The outside layout*/
final VBox layout = new VBox ( 30 ); //the size vertically

/*The inside layout for keys or buttons*/
TilePane keypad = new TilePane (); //even it is called keypad, it is a layout
keypad . setVgap ( 7 );
keypad . setHgap ( 7 ); //set the gap between keys


/*Create Calculator Screen */
calculator_screen = new TextField ();
calculator_screen . getStyleClass (). add ( "screen1" ); //set the style of the screen
calculator_screen . setAlignment ( Pos . CENTER_RIGHT ); //make the screen in the center of the calculator
calculator_screen . setEditable ( false ); //make sure the screen cannot be typed in manually
calculator_screen . setPrefWidth ( 300 ); //set the windth of the screen
calculator_screen . setPrefHeight ( 30 );
calculator_screen . setFont ( Font . font ( "Verdana" , font_size ));

/*Create Calculator keyboard*/
keypad . setPrefColumns ( key_values [ 0 ]. length ); //set the preferred number of columns

for ( int i = 0 ; i < 4 ; i ++ ) {
for ( int j = 0 ; j < 4 ; j ++ ) {
btn [ i ][ j ] = new Button ( key_values [ i ][ j ]);
final int a = i ;
final int b = j ;

/*Add button event*/
btn [ i ][ j ]. setOnAction ( new EventHandler < ActionEvent > (){

@ Override
public void handle ( ActionEvent event ) {

StackNode node = new StackNode ( key_values [ a ][ b ]);


if ( a == 0 && b == 2 ) //if the key is "c"
{
stack . clear ();
calculator_screen . setFont ( Font . font ( "Verdana" , 30 ));
font_size = 30 ;
}
else if ( a == 0 && b == 3 ) //if the key is "b"
stack . pop ();
else if ( a == 0 && b == 1 ) // if the key is "="
{
stack . computeExp ();
}
else
stack . push ( node ); //otherwise push the key into the list

String math_exp = stack . getAllNodeValues ();

if ( math_exp . length () * font_size > 1.2 * calculator_screen . getPrefWidth ())
{
font_size /= 1.2 ;
calculator_screen . setFont ( Font . font ( "Verdana" , font_size ));

}

calculator_screen . setText ( math_exp );

}
}
);

//Add special style for the "=" button
if ( a == 0 && b == 1 )
btn [ i ][ j ]. getStyleClass (). add ( "btnEqual" );
else if ( a == 0 && b == 2 )
btn [ i ][ j ]. getStyleClass (). add ( "btnClear" );
else if ( a == 0 && b == 3 )
btn [ i ][ j ]. getStyleClass (). add ( "btnBackspace" );
keypad . getChildren (). add ( btn [ i ][ j ]);

}
}

/*Put the calculator screen and keypad into a VBox layout*/
layout . setAlignment ( Pos . CENTER );
layout . getChildren (). addAll ( calculator_screen , keypad );
layout . getStyleClass (). add ( "vbox1" );
calculator_screen . prefWidthProperty (). bind ( keypad . widthProperty ());


/*Show the window*/
stage . setTitle ( "Calculator" );
stage . initStyle ( StageStyle . UTILITY );
stage . setResizable ( false );
Scene scene = new Scene ( layout );
scene . getStylesheets (). add ( getClass (). getResource ( "application.css" ). toExternalForm ());

stage . setScene ( scene );
stage . show ();
}

}
__MACOSX/framework/._Calculator.java
framework/MyQueue.java
framework/MyQueue.java
package application ;

public class MyQueue < T > {

private T [] arr ; //used to store data into this array in a queue manner

private int total ; //the total number of elements in the queue
private int first ; //the location of the first element in the queue
private int rear ; //the location of the next available element (last one's next)

//Default constructor, by default the capacity is two elements of type T
public MyQueue ()
{
arr = ( T []) new Object [ 2 ];
}

//Resize the MyQueue to the capacity as the input argument specifies
private void resize ( int capacity )
{
T [] tmp = ( T []) new Object [ capacity ];

for ( int i = 0 ; i < total ; i ++ )
tmp [ i ] = arr [( first + i ) % arr . length ];

arr = tmp ;
first = 0 ;
rear = total ;
}

//Check if the queue is empty: if empty, returns true; otherwise returns false
public boolean isEmpty ()
{
//Implementation here...
return false ;
}

//Add one element "ele" into the queue
//Attention: (1) if the current queue is full, you need to resize it to twice of the current size.
// (2) if the "rear" is already pointing to the end of the queue, but there is available space
// in the beginning, you need to "loop" the rear position.
public void enqueue ( T ele )
{
//Implementation here...
}


//Delete the first (oldest) element from the queue and return this element.
//Below is just an example code, you need to modify it.
//Attention: (1) To save space, if the current number of elements is less than or equal to 1/4 of the
// the capacity, shrink the capacity to 1/2 (half) of the original size.
// (2) If the "first" is pointing to the end of the queue, but there is available space
// in the beginning, you need to consider "loop" the first position.
public T dequeue ()
{
//Implementation here...
T ele = arr [ 0 ];
return ele ;
}

}
__MACOSX/framework/._MyQueue.java
framework/MyStack.java
framework/MyStack.java
package application ;

/* Basic node element that is used by the linked list*/
class StackNode {
String data ; //the node stored value
StackNode next ; //pointing to next node

//Default constructor
public StackNode ()
{

}

//Constructor with data value assigned
public StackNode ( String value )
{
data = value ;
}

//Constructor with data value and next node assigned
public StackNode ( String value , StackNode next )
{
data = value ;
this . next = next ;
}

//Basic setters and getters
public String getData () {
return data ;
}

public void setData ( String data ) {
this . data = data ;
}

public StackNode getNext () {
return next ;
}

public void setNext ( StackNode next ) {
this . next = next ;
}


}

/* MyStack class is used to store string into the stack
* According to the stack logic, you need to implement the function members of MyStack based on the linked list structure
* */
public class MyStack {
private StackNode top_node ; //pointing to the first node

//Default constructor
public MyStack ()
{
top_node = null ; //by default, the node is empty.
}

//Constructor with the first node
public MyStack ( StackNode node ) {
top_node = node ;
}

//check if the stack is empty
public boolean isEmpty ()
{
if ( top_node == null )
return true ;
else
return false ;
}

//clear the stack
public void clear ()
{
top_node = null ;
}


//A general push() method for stack
public void pushNode ( StackNode node )
{
if ( top_node == null )
{
top_node = node ;
}
else
{
node . setNext ( top_node );
top_node = node ;
}
}


//a specific push method for this calculator project uses only
public void push ( StackNode node )
{
//if there is no any element in the stack, the calculator only accepts numbers or "-"
if ( top_node == null )
{
if ( node . getData (). matches ( "^[0-9]+$" ) || node . getData (). equals ( "-" ))
top_node = node ;
}
else if ( node . getData (). matches ( "^[0-9]+$" )) //if the inserted node is a number
{
node . setNext ( top_node );
top_node = node ;
}
else //if the inserted node is "+", "-", "*"
{
if ( top_node . getData (). matches ( "^[0-9]+$" )) //if the recently inserted node is a number, then just insert the "node" straight away
{
node . setNext ( top_node );
top_node = node ;
}
else //if recently inserted node is an operator, e.g. "+", "-", "*", then replace its value by the "node" value
{
if ( top_node . getNext () != null )
top_node . setData ( node . getData ());
}
}

}

//remove the most recently inserted node
public void pop ()
{
if ( top_node != null )
{
top_node = top_node . getNext ();
}
else
{
System . out . println ( "The stack is already empty" );
}

}

//get recently inserted node
public StackNode getTop () {
if ( top_node == null )
{
System . out . println ( "The stack is empty" );
}
else
{
return top_node ;
}

return null ;
}



//get and remove the most recently inserted node
public StackNode getTopandPop () {
if ( top_node == null )
{
System . out . println ( "The stack is empty" );
}
else
{
StackNode temp = top_node ;
top_node = top_node . getNext ();
return temp ;
}

return null ;
}

//This function will all the stored strings connected and return it as a single string
public String getAllNodeValues ()
{
StringBuilder all_strings = new StringBuilder (); //used to store all the strings from the stack

int i = 0 ;
StackNode temp = top_node ;
while ( temp != null )
{
all_strings . append ( temp . getData ());
temp = temp . getNext ();
}
all_strings . reverse ();
return all_strings . toString ();
}


/*This function will to implement the "=" key that process the expression entered by users and calculates a final number.
In addition to the calculation, the final number needs to be converted into a string format and output to the display.
So there are five basic steps involved below.
Steps 1, 4, 5 are already completed. Your tasks will focus on Step 2 and Step 3
*/
public void computeExp ()
{
String exp = getAllNodeValues (); //get the current expression

//Step 1: convert a string into an infix queue
MyQueue infix_queue = getInfixFromString ( getAllNodeValues ());

//Step 2: convert an infix queue into an postfix queue
MyQueue postfix_queue = infix2postfix ( infix_queue );

//Step 3: Compute the final value from the postfix queue
String final_value = processPostfix ( postfix_queue );

//Step 4: Clear the stack
this . clear ();

//Step 5: put the final_value into the stack
for ( int i = 0 ; i < final_value . length (); i ++ )
this . pushNode ( new StackNode ( final_value . substring ( i , i + 1 )));

}


/* Generate an infix expression according to an input String
* The infix expression is stored in a MyQueue variable, which is the returned value of the function */
private MyQueue getInfixFromString ( String exp )
{
//Declare queue to store infix
MyQueue infix_queue = new MyQueue (); //used as a temporary holder that extract operator and operand from exp

//Check if exp has at least one character
if ( exp . length () < 1 )
return infix_queue ;

// Check the first character if it is a negative sign
int j = 0 ;
if ( exp . substring ( 0 , 1 ). equals ( "-" )) {
j = 1 ;
}

// Check the last character if it is an operator, just drop it
if ( exp . substring ( exp . length () - 1 , exp . length ()). equals ( "+" )
|| exp . substring ( exp . length () - 1 , exp . length ()). equals ( "-" )
|| exp . substring ( exp . length () - 1 , exp . length ()). equals ( "*" )) {
exp = exp . substring ( 0 , exp . length () - 1 );
}

// Traverse all the characters and push an operand or operator into
// infix_queue
for ( int i = j ; i < exp . length (); i ++ ) {

String character = exp . substring ( i , i + 1 );

Homework is Completed By:

Writer Writer Name Amount Client Comments & Rating
Instant Homework Helper

ONLINE

Instant Homework Helper

$36

She helped me in last minute in a very reasonable price. She is a lifesaver, I got A+ grade in my homework, I will surely hire her again for my next assignments, Thumbs Up!

Order & Get This Solution Within 3 Hours in $25/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 3 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

Order & Get This Solution Within 6 Hours in $20/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 6 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

Order & Get This Solution Within 12 Hours in $15/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 12 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

6 writers have sent their proposals to do this homework:

Engineering Exam Guru
Quick Mentor
Pro Writer
Helping Engineer
Coursework Assignment Help
Top Class Engineers
Writer Writer Name Offer Chat
Engineering Exam Guru

ONLINE

Engineering Exam Guru

Being a Ph.D. in the Business field, I have been doing academic writing for the past 7 years and have a good command over writing research papers, essay, dissertations and all kinds of academic writing and proofreading.

$46 Chat With Writer
Quick Mentor

ONLINE

Quick Mentor

I am a professional and experienced writer and I have written research reports, proposals, essays, thesis and dissertations on a variety of topics.

$32 Chat With Writer
Pro Writer

ONLINE

Pro Writer

I am an experienced researcher here with master education. After reading your posting, I feel, you need an expert research writer to complete your project.Thank You

$30 Chat With Writer
Helping Engineer

ONLINE

Helping Engineer

I have assisted scholars, business persons, startups, entrepreneurs, marketers, managers etc in their, pitches, presentations, market research, business plans etc.

$28 Chat With Writer
Coursework Assignment Help

ONLINE

Coursework Assignment Help

I have read your project details and I can provide you QUALITY WORK within your given timeline and budget.

$45 Chat With Writer
Top Class Engineers

ONLINE

Top Class Engineers

As per my knowledge I can assist you in writing a perfect Planning, Marketing Research, Business Pitches, Business Proposals, Business Feasibility Reports and Content within your given deadline and budget.

$38 Chat With Writer

Let our expert academic writers to help you in achieving a+ grades in your homework, assignment, quiz or exam.

Similar Homework Questions

Carmex leveraging facebook for marketing research - West london church of god - Mcgraw hill economics answer key - Cloud Computing Week 4 Assignment - In "paul's case," the story suggests that paul's "dark corner" represents his - 24 ft extension ladder fire service - Engineering ethics by charles fleddermann 4th edition - Securities and international regulatory agencies eth 321 - Propaganda how not to be bamboozled summary - Taxation - What are the seven responsibilities of acecqa - Paper 9 for Jennifer - How to do adjustments in accounting worksheet - Non experimental research design ppt - Antuan company set the following standard - Gt2 belt max load - Casp uk net - Discipline vs profession nursing - Post a brief explanation of the event you selected that led to the formation of a social policy. - Post - California pizza kitchen case study - Ap biology ecology test - Providing an inclusive environment in schools for children with and without disabilities. - 6th form college pay scale - Business - Calculating iv infusion time - Prevalence of Smoking Essay - Qnt 351 week 2 individual assignment - Strayer 1 paper - Zappos case study - Http abacus bates edu ganderso biology resources writing htwsections html - Knight middle english pronunciation - Property Essay - Ifrs 3 business combinations full text - Tic tac toe java program code - Shellfish tags must be kept for servsafe - Reflection worksheet --- Due in 2 hours - U.S Health care delivery system - Gartner penetration testing magic quadrant - Vehicle overhang limits wa - Mon tues wed thurs fri sat sun - Blast and fasta in bioinformatics - Packed bed distillation column design - Retrospective analysis of personality - James shirley the glories of our blood and state - Amazon case study questions - Matcam oz pty ltd - An assembly consists of two mechanical components - Pandora box 9 game list - Similarities between active transport and facilitated diffusion - 150 words to describe the taste of food - Icem 3d mesh tutorial - Bdc entrepreneurial potential self-assessment - Cost behavior analysis and use - Cipani and shock chapter 1 - Mathisfun standard deviation - High on crack street documentary - Industrial technology timber past papers - Qdoba locations that serve breakfast - Clinical reasoning strategies in physical therapy - Electric cupcake maker recipes - Order 2207864: Legal requirements for treating HIV/AIDS patients - Growing up with the media analysis - Concrete roof tiles nz - Gog and magog ezekiel 38 39 - Rockwell integrated architecture builder - Measurable iep organizational goals - Fnb flexi fixed deposit - What role do audiences play in creating popular culture - Jeannette walls real family pictures - Ambassadored vitalsource - Gordon wood the radicalism of the american revolution pdf - Uniform gradient present worth excel - 1.97 miles in km - Types of quadrilaterals project - Northumbria university academic calendar - International plastics inc. standards and protocol review - How to write a chemistry lab report introduction - Formal organizations often widen a supervisor's span of control - Logical arrangement of facts - Critique on nutrition and pregnancy - Event security planning checklist - Strategy Assessment and Control. NO PLAGARISM!! 10 PAGES - Stress and illness - Discussion: When the People You Love Don’t Think Like You - Muslim Molvi 7340613399 OnLine No 1 FaMOUs VashIKaraN sPecIaLIsT IN Kollam - Nursing multidimensional care - Home warranty insurance contract for sale - Nasw code of ethics 2013 - Research Paper - Cow eye dissection steps - Unknown times - The relevant range refers to: - Domtar case study - Coping strategies for graduate nurses - An interesting person i know essay - The remote dns server is vulnerable to cache snooping attacks - Getta byte software resource allocation - Management Case Study - Memo introducing yourself to staff