Posts

Showing posts with the label Java

Displaying Text in a Dialog Box

Image
In this program, will we be showing you how to use JAVA program to display a text using JAVA GUI (Graphics User Interface) in a dialog box. Typically,dialog boxes are windows in which programs display important messages to the user of the program.  This application uses Java's Class JOptionPane which provides prepackaged dialog boxes that enables programs to display windows containing messages to its user. we will be using the  import  javax.swing. JOptionPane which  is an import declaration and is part of the  Java API .  Programmers use import declarations to identify the predefined classes used in Java Program. The import declaration help the compiler locate the classes you intend to use, this tells the compiler that our program uses class JOptionPane from package javax.swing and this package helps programmers create graphical user interfaces (GUI) for applications. The program below illustrates how to create a text in a dialog box...

Arithmetic, Smallest and Largest

Image
We will be writing an application that  inputs three integers from the user and displays the sum, average, product, smallest and largest of the numbers using a java application GUI (Graphics User Interface) So the first step of the program will be to import javax.swing.JOptionPane which is part of the java packages and which has the capability of displaying and inputting text in dialog box. usually when inputting digits in java applications, it is entered as strings which can then be converted to corresponding data types like integers and floating point numbers. The program code below illustrates how to do a simple arithmetic, smallest and largest of three numbers. import javax.swing. JOptionPane ; public class Arithmetic {   public static void main( String args [])   {     String firstNumber;     String secondNumber;     String thirdNumber;     String compare;       int number1; ...

Averaging Score

Image
Suppose you have a class of ten students who took a quiz. The grades (integers in the range 0 to 100) for this quiz are made available to you. so this program tutorial shows us how to determine the class average on the quiz. What we need to understand about the class average is that it is equal to the sum of the grades divided by the number of students. so the algorithm below for solving this problem must input each grade, keep track of the total of all grades input, perform the averaging calculation and print the result. First of all we will need to use the pseudo code to list the actions to execute and specify the order in which these actions should execute. Pseudo code is an artificial and informal language that helps you develop algorithms. It’s useful for developing algorithms that will be converted to structured Java programs. They are not executed on computers; rather, they merely help you “think out” a program before attempting to write it in a programming l...

Calculating Diameter, Circumference, Area and Length of a Circle

Image
In today tutorial on writing codes in Java, we will be writing a program using the Java GUI (Graphics User Interface) framework; that asks a user to input the radius and degree of a circle, the program reads it in and calculates: The radius, Diameter, Circumference, Area and Length of a circle. Before using the Java GUI, we need to import the javax.swing.JOptionPane.  Javax. swing is part of Java Foundation Classes that is used to create window based applications. It provides classes for Java API(Application Program Interface) such as the JButton, JPanel, JTextField and so on. import javax.swing.JOptionPane; public class Circle{   public static void main(String args[])   {     int x;     int y;     int diameter;     double circumference;     double area;     double length;       String xVal;     String yVal;       xVal = JOptionPane.showInputDi...

Comparing Two Integers

Image
We are to Write an application that asks the user to enter two integers, obtains the numbers from the user and displays the larger number followed by its symbol in an information dialog. if the numbers are equal, print the message "these numbers are equal". For us to use the information dialog, we will need to import the java package javax.swing.JOptionPane, which is used to provide some standard confirm and input dialog box.  These dialog boxes will then be used to display information or get input from the user instead of displaying in a command prompt. We will also be making use of our IF statement to compare these two numbers that the user will input to determine which one is larger or smaller. In Java user input is normally in form of strings and not integers, so when the user inputs an integer as a string, we need to convert it to its corresponding integer by calling the Integer.parseInt() method. import javax.swing.JOptionPane;   public class C...

Calculating Product, sum, difference, and quotient of Five Integers

Image
A simulation question is given to write an application using Java language that asks the user to enter five integers, obtains the numbers from the user and prints the product, sum, difference and quotient (division) of the numbers using the Java GUI (Graphics User Interface). In  Java, user input is normally in form of strings and not integers; so when the user inputs an integer as a string, we need to convert it to its corresponding integer by calling the integer.parseInt() method. We will also be importing the javax.swing.JOptionPane, which will be used be used for dialog boxes. in my tutorial on Comparing Two Integers in Java programming , i explained the usefulness of dialog box. import javax.swing.JOptionPane; public class Product{   public static void main (String args[])   {     int r;     int s;     int t;     int u;     int v;     int sum;     int product; ...

Adding two Integers in Java Application

Image
This application reads (or inputs) two integers (whole numbers,) typed by a user at the keyboard, computes their sum and displays it. This program Must keep track of the numbers supplied by the user for the calculation later in the program. Programs remember numbers and other data in the computer’s memory and access That data through program elements called variables . Solution //Addition program that displays the sum of two numbers. //Java packages import javax.swing.JOptionPane; //program uses JOptionPane public class Addition{     //main method begins execution of java application   public static void main (String args[])   {     String firstNumber; //first string entered by user     String secondNumber; //second string entered by user         int number1;   //first number to add     int number2;   //second number to add ...