uNreQuiteD

November 30, 2006

gross net tax

Filed under: basic java — anai lem @ 2:13 am

/* Create a program that will compute the gross and netpay of an employee where rate = 100 and hrs worked = 8. The formula for gross, tax and net is as follows:
gross = rate * hrs worked
tax = 5% of gross
net = gross – tax
*/

class grossNet
{
public static void main(String args[])
{
double gross, net, tax, rate = 100, hrsWorked=8;
gross = rate * hrsWorked;
tax = gross * .05;
net = gross – tax;
System.out.println(“GROSS = ” + gross);
System.out.println(“TAX = ” + tax);
System.out.println(“NET = ” + net);
}
}

output
GROSS = 800.0
TAX = 40.0
NET = 760.0

November 28, 2006

Operators / * – +

Filed under: basic java — anai lem @ 2:16 am

/*
Compute and display the values for x, y and its average.
x = 5a
—- – 4a
10a

y = 2(a^2) + 6a
*/

class compute {
public static void main(String args[]) {
int a = 5;
int x = ((5*a) / (10*a)) – (4*a);
int y = (2*a*a) + (6*a);
int ave = (x + y )/2;
System.out.println(“x = ” + x);
System.out.println(“y = ” + y);
System.out.println(“average = ” + ave);
}
}

Output:
x = -20
y = 80
average = 30

Correct change (operators / and %)

Filed under: basic java — anai lem @ 1:48 am

/*
http://www.javacommerce.com/displaypage.jsp?name=notes/chap10/progexercises10.sql&id=18218
(some part of the program specs are edited from the site written above)

CORRECT CHANGE
When cashiers in a store give you change, they first try to
“fit” dollars (100 cents coins) into the amount you get back,
then try to “fit” quarters (25 cent coins) into what is left
over, they try to “fit” dimes (10 cent coins) into what is
now left over, then try to “fit” nickels (5 cent coins)
into what is left, and finally are left with a few odd
cents. For example, say that your change is 163 cents:

One dollar fits into 163, leaving 63 cents.
Two quarters fit into 63 cents, leaving 13 cents.
One dime fits into 13 cents, leaving 3 cents.
No nickels are needed.
Three cents are left.

Your change is : 1 dollar, 2 quarter, 1 dime, 0 nickel, and 3 cents.

Write a program that compute the change due to a buyer (in cents) and writes out how many dollars, quarters, dimes, nickels, and pennies she is due. All variables and all math in this program will be integers. If you are stuck, it will help to do an example problem with paper and pencil.
*/

class change {
public static void main(String args[]) {

int ch = 163, dollar, quarter, dime, nickel, cents;
dollar = ch / 100;
ch = ch % 100;
quarter = ch / 25;
ch = ch % 25;
dime = ch / 10;
ch = ch % 10;
nickel = ch / 5;
ch = ch % 5;
cents = ch;

System.out.print(“Your change is : “);
System.out.print(dollar + ” dollar, ” + quarter + ” quarter, “);
System.out.print(dime + ” dime, ” + nickel + ” nickel, and “);
System.out.print(cents + ” cents”);
}
}

November 24, 2006

Filed under: object oriented progg — anai lem @ 2:05 am

//SUPERCLASS
class methodHere
{
 int factor (int x)
 {
  int f=1;                                
  if(x>0)
    f = x * factor(x-1);
  return f;
 }
}

//SUBCLASS FACTORIAL EXTENDING SUPERCLASS METHODHERE
class factorial extends methodHere
{
 public static void main(String args[])
 {
   factorial fl = new factorial();
   int y = fl.factor(5);
   System.out.println(“Factorial of 5: ” + y);
 }
}

output
                    Factorial of 5: 120

employee inheritance

Filed under: object oriented progg — anai lem @ 1:59 am

 //superclass person

class person
{
  void info(String name, int age)
  {
    System.out.println(“Name :” + name);
    System.out.println(“Age  :” + age);
  }

  int gross(int rate, int hrs)
  {
    int gr = rate * hrs;
    System.out.println(“Gross : ” + gr);
    return gr;
  }
}

 //subclass employee

class employee extends person
{
  void net(int gross)
  {
     double netIncome = gross – (gross * .10);
     System.out.println(“Net income : ” + netIncome);
  }

  public static void main(String args[])
  {
     employee e = new employee();
     e.info(“IANA MEL”, 20);
     int g = e.gross(200,8);
     e.net(g);
  }
}

output:

 Name :IANA MEL
Age :20
Gross : 1600
Net income : 1440.0

November 23, 2006

fibonacci – method

Filed under: object oriented progg — anai lem @ 8:02 am

class fibonacci
{
  void fibo()
  {
   int x=1, y=1, temp=x+y;;
   System.out.print(x + ” ” + y + ” ” + temp +” “);
   while(temp<13)
   {
     y=x;
     x=temp;
     temp = x + y;
     System.out.print(temp + ” “);
   }
  }

  public static void main(String args[])
  {
     fibonacci f = new fibonacci();
     f.fibo();
  }
}

//e3371@yahoo.com 

lab exer1: 1-di array

Filed under: data structure — anai lem @ 5:54 am

class array13579
{
public static void main(String args[])
{
int A[] = new int[5];
for (int i=0; i<5; i++)
{
A[i] = i*2 + 1;
System.out.print(A[i] + ” “);
}
}
}

//******************************************

class array10203040
{
public static void main(String args[])
{
int A[] = new int[4];
for (int i=0; i<4; i++)
{
A[i] = (i + 1) * 10;
System.out.print(A[i] + ” “);
}
}
}

Blog at WordPress.com.