Search This Blog

UI/UX Design | Web Development | Mobile Application Development

Whether you need UI/ UX design, web development services, or mobile app development services, Qaabil Digitals will be more than happy to help you. We work with top software developers, designers, and project managers. We tailor our services to suit your exact needs. We closely look at your company, listen to your story, and bring about the best ideas and solutions that can help you drive solid results. We don’t just produce work that works. We produce work that matters. Get a quote now Or Talk to us

Wednesday, 16 January 2013

Suppose that electricity costs 4.75 cents per kilowatt hour, and that a surcharge of 10% is added to the bill. A city utility tax is 3% is also levied;however no tax is charged on the surcharge, and no surcharge is added for the tax. A penalty for a late payment is 4% of the total bill. Write the java program that computes an electric bill (by Maria sh)

import java.util.Date;
import java.util.Scanner;

public class ElectricityBill 
{
/*
* 4.75 cents per KiloWatt per hour 
* Surcharge 10%
* City utility tex 3%
* 4% of total bill charged on late payment 
*/
public static void main(String[] args) 
{
int totalUnits;
double billCharged;
Scanner in = new Scanner(System.in);
Scanner ins = new Scanner(System.in);
Date date = new Date();
System.out.print("Enter total units consumed (in KiloWatt) = ");
totalUnits = in.nextInt();
billCharged = totalUnits*4.75;
System.out.println("Day of month = "+date.getDate());
if (date.getDate()> 10)
{
billCharged += billCharged * (0.10+0.04);
}
billCharged += billCharged *(0.03);
System.out.println("Your total bill = "+billCharged);
}

}

Note that 10th of each month is assumed to be the due date of bill payment. If any customer pays bill after due date, 10% surcharge and 4% of total bill on late payment will be charged.

Thursday, 12 April 2012

How to use If else in switch statement in java to perform different arithmatic operations BY (Shifa Anjum)

import java.util.Scanner;


public class ConditionalSwitch {
   
    public static void main(String[] args) {
       
        Scanner in = new Scanner (System.in);
        int a,b,c=1;
       
        System.out.println("First number must be 1 to 5 and second from 1 to 100");
       
        System.out.print("Enter first number = ");
        a=in.nextInt();
        System.out.print("Enter second number = ");
        b=in.nextInt();
       
        switch(a)
        {
        case 1:
            if (b<100 && b>1)
            {
                c = a * b;
                System.out.println("Product of both numbers = "+c);
            }
            else
                System.out.println("Second number must be from 1 to 100");
            break;
        case 2:
            if (b<100 && b>1)
            {
                c = a + b;
                System.out.println("Sum of both numbers = "+c);
            }
            else
                System.out.println("Second number must be from 1 to 100");
            break;
        case 3:
            if (b<100 && b>1)
            {
                c = a - b;
                System.out.println(""+a+" - "+b+" = "+c);
            }
            else
                System.out.println("Second number must be from 1 to 100");
            break;
        case 4:
            if (b<100 && b>1)
            {
                c = a / b;
                System.out.println(""+a+" / "+b+" = "+c);
            }
            else
                System.out.println("Second number must be from 1 to 100");
            break;
        case 5:
            if (b<100 && b>1)
            {
                c = b % a;
                System.out.println("Remainder of "+b+" / "+a+" = "+c);
            }
            else
                System.out.println("Second number must be from 1 to 100");
            break;
        default:
                System.out.println("First number must be from 1 to 5");
        }
    }

}

Monday, 14 November 2011

Java program that calculates table of any given number and displays in ascending or descending order (by Sara)

import java.util.*;

class table
{
public static void main (String argsp[])
{
Scanner in = new Scanner (System.in);

int a,b,c,d=0;
System.out.print ("\n\t Enter the number to print table = ");
a=in.nextInt();
System.out.print ("\n\t Enter 1 for ascending and 2 for descending order = ");
c=in.nextInt();

if (c==1)
{
System.out.println ("\n\t Table of "+a+" in ascending order ");
b=1;
while (b<=10)
{
d=b*a;
System.out.println ("\n\t "+a+" * "+b+" = "+d);
++b;
}
}
else if (c==2)
{
System.out.println ("\n\t Table of "+a+" in ascending order ");
b=10;
while (b>0)
{
d=b*a;
System.out.println ("\n\t "+a+" * "+b+" = "+d);
--b;
}
}
else
System.out.println ("\n\t Invalid number ");

}
}

Saturday, 5 November 2011

Develop a java program to generate the Electricity bill. The program have three member functions, Getdata(): to accept the block number, flat name, name and number of units, Calc(): calculate the total cost, Display(): display the bill in proper format ( name, units , total charges). If the total is greater than RM 150 then additional surcharge 15% is added (by Fikri Fieda)


import java.util.*;
class ebill
{
public static void main (String args[])
{
customerdata ob = new customerdata();
ob.Getdata();
ob.Calc();
ob.Display();

}
}

class customerdata
{
Scanner in = new Scanner (System.in);
Scanner ins = new Scanner (System.in);
String cname,fname;
int bn;
double units,tbill;

void Getdata()
{
System.out.print ("\n\t Enter block number = ");
bn = in.nextInt();
System.out.print ("\n\t Enter flate name = ");
fname = ins.nextLine();
System.out.print ("\n\t Enter customer name = ");
cname = ins.nextLine();
System.out.print ("\n\t Enter total consumed units = ");
units = in.nextDouble();
}

void Calc()
{
if (units<100)
tbill=0.40*units;
else if (units>100 && units<300)
tbill=0.50*units;
else
tbill=0.60*units;
if (tbill>150)
tbill+=tbill*0.15;
}

void Display()
{
System.out.println ("\n\t Customer name = "+cname);
System.out.println ("\n\t Total units = "+units);
System.out.println ("\n\t Total bill = RM "+tbill);
}
}

Write a class name employee. This class should hold the employee's details such as employee id,name,gender,salary and position. Write a member function to input all these details and displaying the information on the screen. Supply another member function to calculate the net salary for an employee (by Syuhadah razak)


import java.util.*;
class employee
{
public static void main (String args[])
{
employeeinfo ob = new employeeinfo();
ob.get();
ob.totalsalary();
ob.display();

}
}

class employeeinfo
{
Scanner in = new Scanner (System.in);
Scanner ins = new Scanner (System.in);
String name,gender,position;
int id,salary,ma,hr,bn;

void get()
{
System.out.print ("\n\t Enter employee ID = ");
id = in.nextInt();
System.out.print ("\n\t Enter emplyee name = ");
name = ins.nextLine();
System.out.print ("\n\t Enter employee gender = ");
gender = ins.nextLine();
System.out.print ("\n\t Enter employee salary = ");
salary = in.nextInt();
System.out.print ("\n\t Enter employee position = ");
position = ins.nextLine();
}

void totalsalary()
{
System.out.print ("\n\t Enter medical allowance = ");
ma = in.nextInt();
System.out.print ("\n\t Enter house rent = ");
hr = in.nextInt();
System.out.print ("\n\t Enter bounus = ");
bn = in.nextInt();
}

void display()
{
System.out.println ("\n\t Employee ID = "+id);
System.out.println ("\n\t Employee name = "+name);
System.out.println ("\n\t Employee gender = "+gender);
System.out.println ("\n\t Employee basic salary = "+salary);
System.out.println ("\n\t Employee position/post = "+position);
System.out.println ("\n\t Total salary = "+(ma+hr+bn+salary));
}

}



Write a program that store (a, e, i, o and u) in string data type. Then ask the user to enter a string of characters. then the program should count the number of vowels in that string (by Tieqa)


import java.util.*;
class charvowels
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
char vowels[] = new char[10];
String str;
char c1,c2;
int t=0;

vowels[0] = 'A';
vowels[1] = 'a';
vowels[2] = 'E';
vowels[3] = 'e';
vowels[4] = 'I';
vowels[5] = 'i';
vowels[6] = 'O';
vowels[7] = 'o';
vowels[8] = 'U';
vowels[9] = 'u';

System.out.print ("\n\t Enter the string = ");
str=in.nextLine();

System.out.print ("\n\n\t Vowels in the string = ");
for (int i=0;i<str.length();++i)
{
c1=str.charAt(i);
for (int j=0;j<10;++j)
{
if (c1==vowels[j])
{
System.out.print (" "+c1);
++t;
break;
}
}
}

System.out.println ("\n\t Total number of vowels = "+t);
}
}

Java program to create an ARRAY of 5 STRINGS. The program finds and displays the total number of vowels (both uppercase and lowercase) in all five strings by (Adler Lawn Service, LLC)


import java.util.*;
class vowels
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
String n="",n1,n2,n3,n4,n5;
char c;
int r=1;

System.out.print ("\n\t Enter first name of first person = ");
n1 = in.nextLine();
System.out.print ("\n\t Enter first name of second person = ");
n2 = in.nextLine();
System.out.print ("\n\t Enter first name of third person = ");
n3 = in.nextLine();
System.out.print ("\n\t Enter first name of fourth person = ");
n4 = in.nextLine();
System.out.print ("\n\t Enter first name of fifth person = ");
n5 = in.nextLine();

while (r<6)
{
if (r==1)
{
n=n1;
System.out.print ("\n\n\t Vowels in first person's name = ");
}
else if (r==2)
{
n=n2;
System.out.print ("\n\n\t Vowels in second person's name = ");
}
else if (r==3)
{
n=n3;
System.out.print ("\n\n\t Vowels in third person's name = ");
}
else if (r==4)
{
n=n4;
System.out.print ("\n\n\t Vowels in fourth person's name = ");
}
else if (r==5)
{
n=n5;
System.out.print ("\n\n\t Vowels in fifth person's name = ");
}
else
System.out.println ();

for (int i=0;i<n.length();++i)
{
c=n.charAt(i);
switch (c)
{
case 'A':
case 'a':
System.out.print (" "+c);
break;
case 'E':
case 'e':
System.out.print (" "+c);
break;
case 'I':
case 'i':
System.out.print (" "+c);
break;
case 'O':
case 'o':
System.out.print (" "+c);
break;
case 'U':
case 'u':
System.out.print (" "+c);
break;
default:
System.out.print ("");
}
}

++r;
}

}
}

Wednesday, 26 October 2011

A video rental shop maintains the inventory of videotapes that are being sold in the shop. Whenever a customer wants to rent a videotape, the sales person can check through the list to find out the availability of that particular videotape. If it is not available, then certain message will be displayed. If it is available, then the system displays the details. If the customer confirms his/her choice, the system displays the price and the due date for returning the videotape by (noor diana fauzi)

import java.util.*;
class moviesforrent
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
String mname;
System.out.print ("\n\t Enter the movie name = ");
mname=in.nextLine();
movies ob = new movies();
ob.pricendetail(mname);
}
}

class movies
{
String ma[] = new String [4];
String mc[] = new String [4];
//price per week=RM10.
movies()
{
ma[0]="fast&furious";
ma[1]="pearl harbor";
ma[2]="death note";
ma[3]="ratatouille";

mc[0]="Josh Hartnett";
mc[1]="Ben Affleck";
mc[2]="Michael Bays";
mc[3]="Jerry Bruckheimer";
}

void pricendetail(String mname)
{
int i=0,j=0;
while (i<4)
{
if (mname.equals(ma[i]))
{
System.out.println ("\n\t Movie: "+mname+" \n\t Main character: "+mc[i]+"\n\t Price per week = RM 10.00");
j=1;
break;
}
++i;
}
if (j==0)
System.out.println ("\n\t "+mname+" is not available.");
}

}

Tuesday, 25 October 2011

Java program that joins 3 strings to show the quote, the person who said that and dates he/she lived by(Adler Lawn Service, LLC)

import java.util.*;

class joinstring
{
public static void main (String args[])
{
Scanner in= new Scanner (System.in);
String quote,name,date;

System.out.print ("\n\t Enter the quote = ");
quote=in.nextLine();
System.out.print ("\n\t Enter name of the person who said this = ");
name=in.nextLine();
System.out.print ("\n\t Enter the dates that person lived \n\t (i.e. 14 September 1925 - 25 January 1995 ) = ");
date=in.nextLine();

System.out.println ("\n\n\n\t ''"+quote+"''\n\t "+name+"\n\t ("+date+")");

}
}

Wednesday, 19 October 2011

Java program to find sum, average and modulus by 3, of three numbers by(aol.com)

import java.util.*;
class average
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
double a,b,c,sum=0;
double mod,avg;
System.out.print ("\n\t Enter first number = ");
a=in.nextDouble();
System.out.print ("\n\t Enter second number = ");
b=in.nextDouble();
System.out.print ("\n\t Enter third number = ");
c=in.nextDouble();
sum=a+b+c;
avg=sum/3;
mod=sum%3;




System.out.println ("\n\t Sum of the numbers = "+sum);
System.out.println ("\n\t Average of the numbers = "+avg);
System.out.println ("\n\t Modulus of the sum of numbers by 3 = "+mod);
}
}

Java program which calculates next number by adding all previous numbers using exception handling (by Adler Lawn Service, LLC)

import java.util.*;

class EverySum
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
int a,b=0;
System.out.println ("\n\t The number must be 50 or less");
System.out.print ("\n\t Enter the nth number = ");
a=in.nextInt();
try
{
if (a>50)
check.test();
else
{
for (int i=1;i<a;++i)
{
b+=i;
System.out.print ("\t "+b);
}
}

}
catch (IndexOutOfBoundsException e)
{
System.out.println ("\n\t Invalid number: "+e);
}


}
}

class check
{
static void test() throws IndexOutOfBoundsException
{
throw new IndexOutOfBoundsException (">50");
}
}

Java program to display ifno of different cars using abstract class (by noor diana fauzi)

import java.util.*;
class CarPrice
{
public static void main (String args[])
{
Ford fr = new Ford();
fr.getcarmaker();
fr.setPrice();
Chevy ch = new Chevy();
ch.getcarmaker();
ch.setPrice();
fr.displyinfo();
ch.displyinfo();
}
}

abstract class Auto
{
abstract void getcarmaker();
abstract void setPrice();
}

class Ford extends Auto
{
Scanner in = new Scanner (System.in);
double price;
String maker;
void getcarmaker()
{
System.out.print ("\n\t Enter the name of car maker = ");
maker=in.nextLine();
}

void setPrice()
{
System.out.print ("\n\t Enter price of "+maker+" car = $");
price=in.nextDouble();
}

void displayinfo()
{
System.out.println ("\n\t Car maker = "+maker);
System.out.println ("\n\t Car Price = $"+price);
}
}

class Chevy extends Auto
{
Scanner in = new Scanner (System.in);
double price;
String maker;
void getcarmaker()
{
System.out.print ("\n\t Enter the name of car maker = ");
maker=in.nextLine();
}

void setPrice()
{
System.out.print ("\n\t Enter price of "+maker+" car = $");
price=in.nextDouble();
}

void displayinfo()
{
System.out.println ("\n\t Car maker = "+maker);
System.out.println ("\n\t Car Price = $"+price);
}
}

Java program to find area of a square and rectangle using abstract class (by noor diana fauzi)

import java.util.*;
class area
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
double base,height;
System.out.print ("\n\t Enter base of the Rectangle = ");
base=in.nextDouble();
System.out.print ("\n\t Enter height of the Rectangle = ");
height=in.nextDouble();

double side1,side2;
System.out.print ("\n\t Enter length of side1 of the Square = ");
side1=in.nextDouble();
System.out.print ("\n\t Enter length of side2 of the Square = ");
side2=in.nextDouble();

Rectangle ob1 = new Rectangle (base,height);
Square ob2 = new Square (side1,side2);
ob1.area();
ob2.area();
}
}


abstract class Shape
{
abstract void area();
}

class Rectangle extends Shape
{
double base,height,a;
Rectangle(double b, double l)
{
base=b;
height=l;
}
void area()
{
a=base*height;
System.out.println ("\n\t Area of Rectangle = "+a);
}
}

class Square extends Shape
{
double side1,side2,a;
Square (double s1, double s2)
{
side1=s1;
side2=s2;
}
void area()
{
a=side1*side2;
System.out.println ("\n\t Area of Square = "+a);
}
}

Sunday, 2 October 2011

Java program to calculate commission on sales using methods (by Adler Lawn Service,LLC)

 import java.util.*;
class commission2
{
public static void main (String args[])
{
Scanner in =new Scanner (System.in);
double sales_figure,commission_rate_d;
int commission_rate_i;
System.out.print ("\n\t Enter sales figure = ");
sales_figure=in.nextDouble();
System.out.print ("\n\t Enter first commission rate = ");
commission_rate_d=in.nextDouble();
System.out.print ("\n\t Enter second commission rate = ");
commission_rate_i=in.nextInt();
comm2 ob2 = new comm2();
totalcomm ob = new totalcomm();
ob.computeCommission(sales_figure,commission_rate_d);
ob.computecommission(sales_figure,commission_rate_i);
ob2.computeCommission(sales_figure);
}
}

class comm2 extends totalcomm
{
void computeCommission (double sales)
{
double cr;
cr=(7.5/100)*sales;
System.out.println ("\n\t Commission at 7.5% = "+cr);
}
}

class totalcomm
{
double sales_fig,comm_rate;
int com_rate;
void computeCommission(double p1, double p2)
{
sales_fig=p1;
comm_rate=p2;
System.out.println ("\n\t Sales commission = "+(sales_fig*comm_rate));
}
void computecommission(double p1, int p2)
{
sales_fig=p1;
com_rate=p2/100;
System.out.println ("\n\t Commission = "+(sales_fig*com_rate));
}
}

Monday, 26 September 2011

Java program to find even and odd numbers from 20 numbers (by noor diana)

import java.util.*;
class evenodd
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
int a[]= new int[20];
System.out.println ("\n\t You must enter 20 numbers");
for (int i=0;i<20;++i)
{
System.out.print ("\n\t Enter the number = ");
a[i]=in.nextInt();
}

System.out.println ("\n\t Even numbers : ");
for (int i=0;i<20;++i)
{
if (a[i]%2==0)
System.out.println ("\t"+a[i]);
}

System.out.println ("\n\t Odd numbers : ");
for (int i=0;i<20;++i)
{
if (a[i]%2!=0)
System.out.println ("\t"+a[i]);
}

}
}

Thursday, 22 September 2011

Java program to calculate total cost of an item using methods (OOP)

import java.util.*;
class invoice
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
String name;
itemdata ob = new itemdata();
ob.get();
System.out.print ("\n\t Enter item name = ");
name=in.nextLine();
ob.cost();
ob.displyLine(name);

}
}


class itemdata
{
Scanner in = new Scanner (System.in);
int number;
double quantity,price,tcost=0;
void get()
{
System.out.print ("\n\t Enter item number = ");
number=in.nextInt();
}

void cost()
{
System.out.print ("\n\t Enter item quantity = ");
quantity=in.nextDouble();
System.out.print ("\n\t Enter item price per unit = ");
price=in.nextDouble();
tcost=quantity*price;
}

void displyLine(String name)
{
System.out.println ("\n\t Item number = "+number);
System.out.println ("\n\t Item nume = "+name);
System.out.println ("\n\t Item quantity = "+quantity);
System.out.println ("\n\t Item price per unit = "+price);
System.out.println ("\n\t Total cost = "+tcost);
}

}

Wednesday, 21 September 2011

Java program to calculate salary of an employe using methods

import java.util.*;
class salary
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
double hpr,rh,oh;
System.out.print ("\n\t Enter hourly pay rate = ");
hpr=in.nextDouble();
System.out.print ("\n\t Enter regular hours = ");
rh=in.nextDouble();
System.out.print ("\n\t Enter overtime hours = ");
oh=in.nextDouble();

double rhp=0,otp,tp=0;
rhp = hpr*rh;                            //calculating regular hours pay: rhp

calculate ob = new calculate();            //creating object of class calculate
otp=ob.overtimepay(hpr,oh);                   //calling the method overtimepay
tp=rhp+otp;                                //calculating total pay

System.out.println ("\n\t Regular hours pay = "+rhp);
System.out.println ("\n\t Overtime pay = "+otp);
System.out.println ("\n\t Total pay = "+tp);
}
}


class calculate
{
double otp;
double overtimepay (double hpr, double oh)        //recieving hourly pay rate and overtime hours hpr, oh respectively
{
otp=(hpr*0.5)*oh;                                //calculating overtime pay
return otp;
}
}

Thursday, 1 September 2011

Java program to find average and add two numbers taken from user

Finding addition and average of two numbers is also very simple in java. As you will see it is little bit different from another program which finds sum and product of two numbers. There is its code:

import java.util.*;
class sumavg
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
int a,b,s,avg;
System.out.print ("\n\t Enter first number = ");
a=in.nextInt();
System.out.print ("\n\t Enter second number = ");
b=in.nextInt();
s=a+b;
avg=s/2;
System.out.print ("\n\t sum = "+s);
System.out.print ("\n\t avg = "+avg);
}
}

Note:
          Look at this "avg=s/2" statement. We have sum of the numbers in s and that's why we are dividing s by 2 to calculate average of these numbers. You can also do that in a different way like:
avg=(a+b)/2;

Java program to find sum and product of two numbers

It is very easy to find sum and product of two numbers in java. First of all we must take two numbers from user and then we will add and multiply these numbers. Lets see how, it is

import java.util.*;
class sumproduct
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
int a,b,s,p;
System.out.print ("\n\t Enter first number = ");
a=in.nextInt();
System.out.print ("\n\t Enter second number = ");
b=in.nextInt();
s=a+b;
p=a*b;
System.out.print ("\n\t sum = "+s);
System.out.print ("\n\t product = "+p);
}
}

Note:
          After we have the numbers, take two variables for sum and product. As we have s and p in this program.

Tuesday, 9 August 2011

The for loop

For loop:
                For loop is a powerful and versatile construct. Its general form is:
for (initialization;condition;iteration)
{
//body
}
If you have only one statement to repeat then you can do this without curly braces. The for loop operates as follows:
  • When the loop starts first time, the initialization portion of the loop is executed. Generally, this is an expression that sets the value of the loop control variable, which acts as a counter that controls the loop. It is important to understand that the initialization expression is only executed once.
  • Next, condition is evaluated. This must be a Boolean expression. If this expression is true then the body of the loop is executed. If it is false the loop terminates.
  • Next, the iteration portion of the loop is executed. This is usually an expression that increments or decrements the loop control variables.
This process will continue till condition is true. See a simple java program explaining all this.

Share