Algorithm Chalenges

prabulk

Member
Sep 5, 2010
6
0
0
Hi friends .
This thread is not only for the programmer anyone can join with this challenge.If you're don't know about any programming language you can put pseudo code .Most impotent thin is efficiency of you're algorithm(time complexity).(You can put you're institute or university name with you're algorithms).get ready for the 1st challenge ..

:yes::eek:

If you Have any problem with you're Assignment this is the place ....
 
Last edited:

prabulk

Member
Sep 5, 2010
6
0
0
1st Challenge

You have String array with 20 elements.
String details[] = {"kamal,"Nimal","saman","kamal",...........}
I want to remove duplicates item from this string Array and print others on console.
This challenge is seems to be very easy but please consider about efficiency .It is the most impotent factor.
 

samila224

Banned
Jan 25, 2009
6,954
280
0
Melbourne VIC Australia
Puluwan akkenek mata mea assigmnt aka karala denna!! Plz

A company calculates the bonus scheme for its employees based on the following scheme.
Monthly salary
Service in years
Bonus rate
>= 30,000
> = 5 years
10% of basic salary
>30,000
< 5 years
5% of the basic salary
< =30,000
>=5 years
2% of the basic salary
< 30,000
< 5 years
No bonus

Program must calculate the tax amount to be paid to the department of Inland Revenue and that will be applied to the employees’ whose salary is greater than or equal to Rs. 30,000/=. Tax will be calculated after the bonus. The tax rate 2.5% of the total salary including bonus amount.
The program prompts the employee name and his basic salary. Finally it calculates the bonus and salary, bonus and tax will be displayed together with the name.

You are required;
1. The inputs and outputs.
2. An algorithm for the program
3. A test plan
4. A computer program using java language with appropriate documentation
 

samila224

Banned
Jan 25, 2009
6,954
280
0
Melbourne VIC Australia
Puluwan akkenek mata mea assigmnt aka karala denna!! Plz

4959823303_06870e4273_b.jpg
 
Last edited:

prabulk

Member
Sep 5, 2010
6
0
0
Puluwan akkenek mata mea assigmnt aka karala denna!! Plz

4959823303_06870e4273_b.jpg

Hi this code will be helpful to solve you're problem but i haven't check it bec lack of time .So please check before it use . ;)

Running command
java bonesCalculator name 35000 5


Code:
public class bonesCalculator {

    private final static double TAX_LIMIT = 30000;
    private final static double SALARY_LIMIT = 30000;
    private final static double EXPER_LIMIT = 5;

    public static void main(String[] args) {

        try {
            bonesCalculator sal = new bonesCalculator();

            if (args.length == 3) {

                String name = args[0];
                double salary = Double.parseDouble(args[1]);
                double experience = Double.parseDouble(args[2]);
                sal.salaryCalculator(salary, experience, name);

            } else {
                System.out.println("Please Enter the data .....");
            }

        } catch (NumberFormatException e) {
            e.printStackTrace();
        }

    }

    public void salaryCalculator(double salary, double experience, String name) {

        double basicSalary = 0;
        double bonus = 0;
        double tax = 0;
        bonesCalculator sal = new bonesCalculator();
        try {

            if (salary >= SALARY_LIMIT && experience >= EXPER_LIMIT) {

                bonus = (salary * 10) / 100;
                basicSalary = bonus + salary;
                tax = sal.taxCalculate(basicSalary);

            } else if (salary > SALARY_LIMIT && experience < EXPER_LIMIT) {
                bonus = (salary * 5) / 100;
                basicSalary = bonus + salary;
                tax = sal.taxCalculate(basicSalary);

            } else if (salary <= SALARY_LIMIT && experience >= EXPER_LIMIT) {
                bonus = (salary * 2) / 100;
                basicSalary = bonus + salary;
                tax = sal.taxCalculate(basicSalary);

            } else if (salary < SALARY_LIMIT && experience < EXPER_LIMIT) {
                tax = sal.taxCalculate(salary);
            } else {
                System.out.println("Out of range");
            }

            System.out.println("Name=" + name + " Tax=" + tax + " Bonus ="
                    + bonus);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public double taxCalculate(Double salary) {

        double tax = 0;

        try {
            if (salary >= TAX_LIMIT) {
                tax = (salary * 2.5) / 100;
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return tax;

    }

}
 

samila224

Banned
Jan 25, 2009
6,954
280
0
Melbourne VIC Australia
Hi this code will be helpful to solve you're problem but i haven't check it bec lack of time .So please check before it use . ;)

Running command
java bonesCalculator name 35000 5


Code:
public class bonesCalculator {

    private final static double TAX_LIMIT = 30000;
    private final static double SALARY_LIMIT = 30000;
    private final static double EXPER_LIMIT = 5;

    public static void main(String[] args) {

        try {
            bonesCalculator sal = new bonesCalculator();

            if (args.length == 3) {

                String name = args[0];
                double salary = Double.parseDouble(args[1]);
                double experience = Double.parseDouble(args[2]);
                sal.salaryCalculator(salary, experience, name);

            } else {
                System.out.println("Please Enter the data .....");
            }

        } catch (NumberFormatException e) {
            e.printStackTrace();
        }

    }

    public void salaryCalculator(double salary, double experience, String name) {

        double basicSalary = 0;
        double bonus = 0;
        double tax = 0;
        bonesCalculator sal = new bonesCalculator();
        try {

            if (salary >= SALARY_LIMIT && experience >= EXPER_LIMIT) {

                bonus = (salary * 10) / 100;
                basicSalary = bonus + salary;
                tax = sal.taxCalculate(basicSalary);

            } else if (salary > SALARY_LIMIT && experience < EXPER_LIMIT) {
                bonus = (salary * 5) / 100;
                basicSalary = bonus + salary;
                tax = sal.taxCalculate(basicSalary);

            } else if (salary <= SALARY_LIMIT && experience >= EXPER_LIMIT) {
                bonus = (salary * 2) / 100;
                basicSalary = bonus + salary;
                tax = sal.taxCalculate(basicSalary);

            } else if (salary < SALARY_LIMIT && experience < EXPER_LIMIT) {
                tax = sal.taxCalculate(salary);
            } else {
                System.out.println("Out of range");
            }

            System.out.println("Name=" + name + " Tax=" + tax + " Bonus ="
                    + bonus);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public double taxCalculate(Double salary) {

        double tax = 0;

        try {
            if (salary >= TAX_LIMIT) {
                tax = (salary * 2.5) / 100;
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return tax;

    }

}


Thnxxx bro!! :D:D:D i found a cord... Plz hlp me 2 do d Algorithm & Test Plan for dz cord....



import java.util.*;
public class Assignment1
{
public static void main (String [] args)
{
String employeeName;
double totalSales;



Scanner keyboard = new Scanner(System.in);

System.out.print ("Enter employee's name :");
employeeName = keyboard.nextLine();

System.out.print ("Enter annual total of sales made by the " + employeeName +":");
totalSales = keyboard.nextDouble();

if (totalSales >= 100000)
{
System.out.println ("Empolyee "+ employeeName +"'s annual total of sales amount is "+ totalSales);
System.out.println ("Empolyee "+ employeeName + " will get 20% of bonus");
System.out.println ("And his/her bonus amount is" + " " + totalSales*0.2);
}
else if (totalSales >= 40000)
{
System.out.println ("Empolyee "+ employeeName +"'s annual total of sales amount is "+ totalSales);
System.out.println ("Empolyee "+ employeeName + " will get 10% of bonus");
System.out.println ("And his/her bonus amount is" + " " + totalSales*0.1);
}
else
{
System.out.println ("Empolyee "+ employeeName + " will not get any bonus");

}
}
}
 

prabulk

Member
Sep 5, 2010
6
0
0
Thnxxx bro!! :D:D:D i found a cord... Plz hlp me 2 do d Algorithm & Test Plan for dz cord....



import java.util.*;
public class Assignment1
{
public static void main (String [] args)
{
String employeeName;
double totalSales;



Scanner keyboard = new Scanner(System.in);

System.out.print ("Enter employee's name :");
employeeName = keyboard.nextLine();

System.out.print ("Enter annual total of sales made by the " + employeeName +":");
totalSales = keyboard.nextDouble();

if (totalSales >= 100000)
{
System.out.println ("Empolyee "+ employeeName +"'s annual total of sales amount is "+ totalSales);
System.out.println ("Empolyee "+ employeeName + " will get 20% of bonus");
System.out.println ("And his/her bonus amount is" + " " + totalSales*0.2);
}
else if (totalSales >= 40000)
{
System.out.println ("Empolyee "+ employeeName +"'s annual total of sales amount is "+ totalSales);
System.out.println ("Empolyee "+ employeeName + " will get 10% of bonus");
System.out.println ("And his/her bonus amount is" + " " + totalSales*0.1);
}
else
{
System.out.println ("Empolyee "+ employeeName + " will not get any bonus");

}
}
}





Hi ...


It is not difficult algorithm mean logic.as the example

Code:
if (totalSales >= 100000)
          {   
              System.out.println ("Empolyee "+ employeeName +"'s annual total of sales amount is "+ totalSales);
              System.out.println ("Empolyee "+ employeeName + " will get 20% of bonus");
              System.out.println ("And his/her bonus amount is" + " " + totalSales*0.2);
          }
          else if (totalSales >= 40000)
          {
              System.out.println ("Empolyee "+ employeeName +"'s annual total of sales amount is "+ totalSales);
              System.out.println ("Empolyee "+ employeeName + " will get 10% of bonus");
              System.out.println ("And his/her bonus amount is" + " " + totalSales*0.1);
          }
          else
          {
              System.out.println ("Empolyee "+ employeeName + " will not get any bonus");
              
          }



if totalSales > 100000

he will get 20% of bonus

else

No bonus


Like this ....

Before you try to write code you should think about algorithm and efficiency .


About test plan

Make all possibilities of inputs and calculate outputs.

Ex:-

Input salary 20000 rs.

According to the logic output should be a "will get 20% of bonus".


Then input you're salary to the system and check out put .You're expectation and system out put is same .Test is ok.


So you should make all possibilities of input and expected output .
 

samila224

Banned
Jan 25, 2009
6,954
280
0
Melbourne VIC Australia
Hi ...


It is not difficult algorithm mean logic.as the example

Code:
if (totalSales >= 100000)
          {   
              System.out.println ("Empolyee "+ employeeName +"'s annual total of sales amount is "+ totalSales);
              System.out.println ("Empolyee "+ employeeName + " will get 20% of bonus");
              System.out.println ("And his/her bonus amount is" + " " + totalSales*0.2);
          }
          else if (totalSales >= 40000)
          {
              System.out.println ("Empolyee "+ employeeName +"'s annual total of sales amount is "+ totalSales);
              System.out.println ("Empolyee "+ employeeName + " will get 10% of bonus");
              System.out.println ("And his/her bonus amount is" + " " + totalSales*0.1);
          }
          else
          {
              System.out.println ("Empolyee "+ employeeName + " will not get any bonus");
              
          }

if totalSales > 100000

he will get 20% of bonus

else

No bonus


Like this ....

Before you try to write code you should think about algorithm and efficiency .


About test plan

Make all possibilities of inputs and calculate outputs.

Ex:-

Input salary 20000 rs.

According to the logic output should be a "will get 20% of bonus".


Then input you're salary to the system and check out put .You're expectation and system out put is same .Test is ok.


So you should make all possibilities of input and expected output .


Thnxxxx machan!!
:D:D:D:D
 

Tom Riddle

Member
Aug 31, 2007
1,833
196
0
You have String array with 20 elements.
String details[] = {"kamal,"Nimal","saman","kamal",...........}
I want to remove duplicates item from this string Array and print others on console.
This challenge is seems to be very easy but please consider about efficiency .It is the most impotent factor.

Sort the array first (you can do it in worst case O(n log n) using QuickSort ). Then read the array from the beginning till the end ONCE ( O(n) ), and if you come across a duplicate remove it.

So the total complexity is O(n log n), which is much better than O(n^2) which would result when using the obvious algorithm of taking each word and comparing it with all the other words in the array.

University of Moratuwa.