Posts

Showing posts from January, 2017

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

Body Mass Index Calculator In C

Image
C programming Project From Deitel C how to program (Making a difference) Create a BMI calculator application that reads the user’s weight in pounds and height in inches (or, if you prefer, the user’s weight in kilograms and height in meters), then calculates and displays the user’s body mass index.  Also, the application should display the following information from the Department of Health and Human Services/National Institutes of Health so the user can evaluate his/her BMI: BMI VALUES Underweight: less than 18.5 Normal: between 18.5 and 24.9 Overweight: between 25 and 29.9 Obese: 30 or greater One thing we generally need to know is that Bmi is universally expressed in Kg/M 2  and heights in Meters  and the formula given by; BMI weightInKilog rams --------------------------------------------- heightInMeters  ×  heightInMeters It can also be expressed in Pounds and Inches with the formula given as; ...

A Simple Questionier Program

Image
Write a program that asks a user to input his name, age, and marital status and displays the result. /* A simple  questioner  program*/ #include<stdio.h> #include<stdlib.h> /*function main begins program execution */ int main ( void ) { /*Initialization phase */     char name [ 100 ];     char mari [50];     char yes;     int age; /*Processing phase */     printf("\t This Program helps catalog all your personal data.\n\n \tPlease complete the following question \n" );     printf ( "Whats your name:" );      scanf ( "%s" , name);     printf ( "How old are you:" );     scanf ( "%d" , & age);     printf ( "Are you Married:" );     scanf ( "%s" , mari);   /*Terminating phase */     printf ( "Tha...

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