Question
Your lab is to write code in the class below the numbered comments in your project. Here are the instructions and do them in the
Your lab is to write code in the class below the numbered comments in your project. Here are the instructions and do them in the order given.
1 . Write statement(s) that will get an input of a name from TextInputDialog object and assign the input to the object/variable (which is already declared and created) nameString
2. Write statement(s) that will get an input of a integer from Scanner object and assign the input to the variable (which is already declared and created) number1Integer.
3. Write statement(s) that will get an input of a integer from Scanner object and assign the input to the variable (which is already declared and created) number2Integer .
4. Write statement(s) that will now that will add the variables number1Integer and number2Integer and assign the result to the variable (which is already declared and created) sumInteger.
5. Write statement(s) that will now that will subtract the variables number1Integer and number2Integer and assign the result to the variable (which is already declared and created) differenceInteger.
6. Write statement(s) that will now that will multiply the variables number1Integer and number2Integer and assign the result to the variable (which is already declared and created) productInteger.
7. Write statement(s) (figure out a mathematical expression) that will give you the hours that are in totalMinutesInteger (which is already declared and created and holds the number 215) assign the hours to the variable (which is already declared and created) hoursInteger.
8. Write statement(s) (figure out a mathematical expression) that will give you the remaining minutes from the hours calculate that are in totalMinutesInteger (which is already declared and created and holds the number 215) assign the remaining minutes to the variable (which is already declared and created) minutesInteger.
8. Now you will be writing code to display what you have processed. The addition operation is done for you. You must follow the same format for subtract, multiply and find the hours and minutes under the respective comments
9. Write statement(s) that will display the results that you have calculated. The nameString and sumInteger are already displayed in the their respective labels
a. Write statement(s) that will display differenceInteger in differenceLabel
b. Write statement(s) that will display productInteger in multiplyLabel
c. Write statement(s) that will display hoursInteger in hoursLabel
d. Write statement(s) that will display minutesInteger in minutesLabel
Here is the code provided:
import java.util.*; // this is to access Optional class import javafx.application.Application; // entry point for all javafx classes import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.layout.GridPane; import javafx.scene.text.Font; //access to Font style import javafx.scene.text.FontWeight; //access Font regular and italic import javafx.scene.control.TextInputDialog; import javafx.scene.control.Label;
public class LabArithmeticOperators extends Application { // components (objects) to view in the window GridPane mainGridPane = new GridPane(); Label titleLabel = new Label(" Learning Operators "); Label namePromptLabel = new Label("Name "); Label nameLabel = new Label(" "); Label sumPromptLabel = new Label("Sum of two numbers "); Label sumLabel = new Label(" "); Label differencePromptLabel = new Label("Difference of two numbers "); Label differenceLabel = new Label(" "); Label multiplyPromptLabel = new Label("Product of two numbers "); Label multiplyLabel = new Label(" "); Label hoursPromptLabel = new Label("Hours from minutes "); Label hoursLabel = new Label(" "); Label minutesPromptLabel = new Label("Minutes Remaining "); Label minutesLabel = new Label(" "); // This is the first method called in an application //We will write object of ourselves to call the //constructor and then execute the start public static void main(String[] args) { // create object of the class and execute the start method launch(args);
} //This is the constructor for this class. It will be called from main //This method will call the super's constructor, get your input from the text input dialog // and the Scanner object, process the input, and add components to the main pane public LabArithmeticOperators() { //Local variables String nameString =""; Scanner myScanner = new Scanner(System.in); int number1Integer= 0 , number2Integer = 0; int sumInteger = 0, differenceInteger, productInteger, totalMinutesInteger = 215; //You will be writing your code here //Getting Input /*1. Get your name through a text input dialog assign the your name to nameString*/ /*2. Get the first integer through Scanner assign the first integer to number1Integer*/ /*3. Get the second integer through Scanner assign the second integer to number2Integer*/ //Closing the Scanner object as all the input is gathered myScanner.close(); //Processing the input /*4. Add the number1Integer and number2Integer * where first and second integer are stored * assign the to sumInteger*/ /*5. Subtract the number1Integer and number2Integer * where first and second integer are stored * assign the to differenceInteger*/ /*6. Multiply the number1Integer and number2Integer * where first and second integer are stored * assign the to productInteger*/ /*7. Find the hours in totalMinutesInteger * and assign to hoursInteger*/ /*8. Find the remaining minutes in totalMinutesInteger * and assign to minutesInteger*/ //Displaying the output nameLabel.setText(nameString); sumLabel.setText("" + sumInteger); /* 9. Write code to display * differenceInteger, productInteger, hoursInteger * and minutesInteger */ //add the label objects to the mainPane mainGridPane.add(titleLabel,0,0); mainGridPane.add(namePromptLabel,0,1); mainGridPane.add(nameLabel,1,1); mainGridPane.add(sumPromptLabel,0,2); mainGridPane.add(sumLabel,1,2); mainGridPane.add(differencePromptLabel,0,3); mainGridPane.add(differenceLabel,1,3); mainGridPane.add(multiplyPromptLabel,0,4); mainGridPane.add(multiplyLabel,1,4); mainGridPane.add(new Label("Total minutes are 215"),0,5); mainGridPane.add(hoursPromptLabel,0,6); mainGridPane.add(hoursLabel,1,6); mainGridPane.add(minutesPromptLabel,0,7); mainGridPane.add(minutesLabel,1,7); } // add the main pane to the Scene object, and set the Stage properties for display public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("Learning my Operators"); Scene scene= new Scene(mainGridPane, 200, 200); primaryStage.setScene(scene); primaryStage.show(); }
}
Step by Step Solution
3.43 Rating (150 Votes )
There are 3 Steps involved in it
Step: 1
Heres the code with the completed sections incorporating best practices and comments Java import javautil import javafxapplicationApplication import j...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started