Posts

Showing posts from 2017

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...

Printing Your First Java Program

Image
Every programmer first code or writing starts with words like "Hello World", "Am a Programmer" etc, that's what makes programming so fun and interesting in a way that the programmer would one day be writing millions of lines of codes. But before you start writing thousands and millions of codes we have to start from somewhere and that is why this post is very essential to beginners new to coding.  We will be demonstrating how to write "Welcome to Java programming" in a Java language. Java language is one of the most widely used high level programming languages for developing complex and high end applications that can be run on all platforms. thus; its platform independent.  To get started with Java, I recommend using DrJava which is a lightweight development environment for writing Java programs. It is designed primarily for students, providing an intuitive interface and the ability to interactively evaluate Java code. It also incl...

Printing Your First C++ Program

Image
Welcome to C++ If you are here, it means you have taken a very big step to a very lucrative journey ahead to become one of those with super powers of coding, and what better way to start than with C++ I won't bore you with much talk cause this blog is all about codes and codes, but before you start coding in C++ you require an IDE (Integrated Device Environment) which will assist you in writing and running your C++ programs. I would recommend   Code::Blocks with gnu gcc compiler (Which supports C programming Language too), which is the best compiler to start  with for beginners and which i like using most.  To make use of the IDE, install and open the code blocks,  Write the  C++  code and save the file with . cpp  extension. To save the file, go to File > Save (Shortcut: Ctrl + S). To run the program, go to Build > Build and Run. Now let's go ahead with what brought you here which is  writing your first C++ code. The code below...

Printing Your First C Program

Image
Welcome to C If you are here, it means you have taken a very big step to a very lucrative journey ahead to become one of those with super powers of coding, and what better way to start than with C To get started with C you need an IDE. Install the Code::Blocks with gnu gcc compiler, which is the best compiler to start  with for beginners. Write the  C  code and save the file with . c  extension. To save the file, go to File > Save (Shortcut: Ctrl + S). To run the program, go to Build > Build and Run. Now let's go ahead with what brought you here which is  writing your first C++ code.  The code below illustrates just how to do that. This application displays a line of text in a Command prompt using an IDE   #include <stdio.h>   int main( void )   { printf( "Welcome to C!\n" );   } see also Printing Your First C++ Program

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...

Temperature Conversion Program

Image
This program uses the switch statement to convert one temperature degree to another and also uses the JOptionPane input/output dialog box from the javax.swing. package to display the information. we also have to note that 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 below illustrates temperature conversion program. import javax.swing.JOptionPane; public class Temperature{   public static void main(String args[])   {     String from;     String to;     String value;       int number1;     int number2;     double temp;       JOptionPane.showMessageDialog(null, "Temperature Conversion");       from = JOptionPane.showInputDialog("Enter no of unit to convert from: 1.Celcius 2. Farenheit 3. Kelvin");     to = JOpti...

Odd and Even

Image
Welcome in C programming, in this tutorial we will be looking at how to w rite a program that asks a user to input an integer and the program determines if the integer is odd or even. An  even number  is a  number  that can be divided into two equal groups. While an  odd number  is a  number  that cannot be divided into two equal groups.  We will be using the IF/ELSE statement to compare the  variable imputed by the user, so if "num" which is the variable name that holds the user input divides two (2) with no reminder, then its an even number, else its an odd number.  The program below, shows the step on how these is achieved. #include<stdio.h> #include<stdlib.h> int main(void) {     int num;      printf("Enter a number:");     scanf("%d", &num);      if(num%2==1){       ...

Simple Interest calculation

Image
In this C programming tutorial, i will be showing you how to write a program in C to calculate simple interest; and we are going to need an illustrated example to enable us get variable to use for the calculation.  So lets assume a person invests $4016.25 in a savings account yielding 9% interest; Assuming that all interest is left on deposit in the account, we are to write a program in C that calculates and prints the amount of money in the account at the end of each year for 5 years. Formula for calculating simple interest amount is:  a= p(1+r) n a= Amount  p= original amount(Principal),  r = Rate ,  n= Number of years. This problem involves a loop that performs the indicated calculation for each of the 5 years the money remains on deposit. We would also be using the  [pow]-Standard Library Function. The function pow(x,y) calculates the values of x raised to the yth power. The header <math.h> should always be included when...

Rolling a Six-Sided Die

Image
Welcome to C programming tutorial, we will be writing a program illustration that Rolls a Six-Sided. A fair  die  means that each of the faces has the same probability of landing facing up;  A standard  six - sided die , for example, can be considered "fair" if each of the faces has a probability of 1/6. The Program will be required to loop 20 times and on each loop the rand() function for number generation will be called to be picking numbers randomly between 1 to 6. #include<stdio.h> #include<stdlib.h> int main( void ) {     int i;     for (i=1; i<=20; i++){         printf("%5d", 1+(rand()%6));         if (i%5==0){             printf("\n");          }     }     return 0; ...

Using Do-While Repetition Statement

Image
A  do while loop  is a control flow  statement  that executes a block of code at least once, and then repeatedly executes the block, or not, depending on a given boolean condition at the end of the block. this tutorial shows us how to use a do while repetition statement to break out loop. Now lets assume you are printing loads of data using this do while loop and you want it to stop at a particular point of mark, that is where the break statements comes in. The break statement are used to alter the flow of control, the break statement when executed in a do-while statement causes an immediate exit from that statement. The program below illustrates how to use the do-while statement. #include<stdio.h> int main(void) {     int x = 1;     do{ printf("%d", x);   if(x==1000){       break; } } while(x <=10000);             ...

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 and Subtracting Integers in C++

Image
Welcome to C++ programming language. if you are new to C++, you have chosen a good platform to becoming a  better programmer. today, we will show you how to use the C++ language to input two integers and compute the sum and difference between the two.  Now ;This program uses the input stream object std::cin  and the stream extraction Operator , >> , to obtain two integers typed by a user at the keyboard, computes the sum and difference of these values and outputs the result using std::cout . #include<iostream> int main () { int number1 ; int number2; int sum;  int difference;   std : : cout << "Enter first integer:" ; std :: cin >> number1; std :: cout << "Enter Second Integer:" ; std :: cin >> number2;  sum = number1 + number2;   difference = number1 - number2;  std :: cout << "Sum is:" << sum << std :: endl ;   std :: cout...