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

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));
}

}



Share