Wednesday, 28 August 2013

Create an Applet that displays the a House. If the mouse is rolled over roof, the message “Mouse is over roof” should be displayed on the status bar. If the mouse is rolled over door, the message “Mouse is over door” should be displayed on the status bar. Like wise for windows and walls

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

/**
 *
 * @author Administrator
 */
public class House extends Applet {

    Rectangle r[] = new Rectangle[4];
    Polygon p = null;
    int a[] = {500, 700, 600};
    int b[] = {200, 200, 100};
    int x = 0, y = 0;
    String msg = null;

    /**
     * Initialization method that will be called after the applet is loaded
     * into the browser.
     */
    public void init() {

        r[0] = new Rectangle(500, 200, 200, 200);
        r[1] = new Rectangle(550, 300, 100, 100);
        r[2] = new Rectangle(525, 225, 50, 50);
        r[3] = new Rectangle(625, 225, 50, 50);
        p = new Polygon(a, b, 3);
        addMouseMotionListener(new A());
    }

    public class A extends MouseMotionAdapter {

        @Override
        public void mouseMoved(MouseEvent m) {

            x = m.getX();
            y = m.getY();
            int z = getShape(x, y);
            if (z == 1) {
                msg = "Mouse is over door";
            } else if (z == 2 || z == 3) {
                msg = "Mouse is over Window ";
            } else if (z == 4) {
                msg = "Mouse is over roof";
            } else {
                msg = "Mouse is over walls";
            }

            repaint();
        }

        public int getShape(int x, int y) {

            if (r[1].contains(x, y)) {
                return 1;
            } else if (r[2].contains(x, y)) {
                return 2;
            } else if (r[3].contains(x, y)) {
                return 3;
            } else if (p.contains(x, y)) {
                return 4;
            } else {
                return -1;
            }
        }
    }

    public void paint(Graphics g) {
        g.setColor(Color.PINK);
        g.fillRect(500, 200, 200, 200);
        g.setColor(Color.red);
        g.fillRect(550, 300, 100, 100);
        g.setColor(Color.GRAY);
        g.fillRect(525, 225, 50, 50);
        g.fillRect(625, 225, 50, 50);
        g.setColor(Color.RED);
        g.fillPolygon(a, b, 3);
        showStatus(msg);
    }
    // TODO overwrite start(), stop() and destroy() methods
}

Pass the following parameters to Applet: a. Shapes (Rectangle or Oval) b. Style (Hollow or Solid) c. BgColor (R,G,B value) d. FrColor (R,G,B value) e. X f. Y g. Width h. Height

import java.awt.*;
import java.applet.*;

public class PeraComputer extends Applet {

    int xs[] = {100, 220, 160};
    int ys[] = {270, 270, 220};
    String CPUBgColor = new String();
    String CPUFrColor = new String();
    String MouseBgColor = new String();
    String MouseFrColor = new String();
    String KeyBgColor = new String();
    String KeyFrColor = new String();
    String ScreenImage = new String();
    String ScreenFrColor=new String();
    Image img=null;
    int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7;
  
    public void init() {
        CPUBgColor = getParameter("CPUBgColor");
        CPUFrColor = getParameter("CPUFrColor");
        MouseBgColor = getParameter("MouseBgColor");
        MouseFrColor = getParameter("MouseFrColor");
        KeyBgColor = getParameter("KeyBgColor");
        KeyFrColor = getParameter("KeyFrColor");
        ScreenImage = getParameter("ScreenImage");
        ScreenFrColor=getParameter("ScreenFrColor");
        x1 = CPUBgColor.indexOf(",");
        y1 = CPUBgColor.lastIndexOf(",");
        x2 = CPUFrColor.indexOf(",");
        y2 = CPUFrColor.lastIndexOf(",");
        x3 = MouseBgColor.indexOf(",");
        y3 = MouseBgColor.lastIndexOf(",");
        x4 = MouseFrColor.indexOf(",");
        y4 = MouseFrColor.lastIndexOf(",");
        x5 = KeyBgColor.indexOf(",");
        y5 = KeyBgColor.lastIndexOf(",");
        x6 = KeyFrColor.indexOf(",");
        y6 = KeyFrColor.lastIndexOf(",");
        x7 = ScreenFrColor.indexOf(",");
        y7= ScreenFrColor.lastIndexOf(",");

    }

    public void paint(Graphics g) {
       
        img=getImage(getCodeBase(),ScreenImage);
        g.drawImage(img, 100, 100, this);
        //Monitor
        g.setColor(new Color(Integer.parseInt(ScreenFrColor.substring(0, x7)), Integer.parseInt(ScreenFrColor.substring(x7 + 1, y7)), Integer.parseInt(ScreenFrColor.substring(y7 + 1))));
        g.drawRect(100, 100, 120, 120);
        g.fillPolygon(xs, ys, 3);
        //CPU
        g.setColor(new Color(Integer.parseInt(CPUBgColor.substring(0, x1)), Integer.parseInt(CPUBgColor.substring(x1 + 1, y1)), Integer.parseInt(CPUBgColor.substring(y1 + 1))));
        g.fillRect(270, 100, 70, 170);
        g.setColor(new Color(Integer.parseInt(CPUFrColor.substring(0, x2)), Integer.parseInt(CPUFrColor.substring(x2 + 1, y2)), Integer.parseInt(CPUFrColor.substring(y2 + 1))));
        g.drawRect(270, 100, 70, 170);
        g.fillRect(305,110,30,10);
        g.fillOval(325,125,8,8);
        g.fillOval(287,142,35,35);
        g.fillOval(290,187,30,30);
        g.fillOval(293,227,25,25);
        //KeyBoard
        g.setColor(new Color(Integer.parseInt(KeyBgColor.substring(0, x5)), Integer.parseInt(KeyBgColor.substring(x5 + 1, y5)), Integer.parseInt(KeyBgColor.substring(y5 + 1))));
        g.fillRect(100, 320, 120, 50);
         g.setColor(new Color(Integer.parseInt(KeyFrColor.substring(0, x6)), Integer.parseInt(KeyFrColor.substring(x6 + 1, y6)), Integer.parseInt(KeyFrColor.substring(y6 + 1))));
        g.drawRect(100, 320, 120, 50);
        g.fillOval(110,325,10,10);
        g.fillOval(125,325,10,10);
        g.fillOval(140,325,10,10);
        g.fillOval(155,325,10,10);
        g.fillOval(170,325,10,10);
        g.fillOval(185,325,10,10);
        g.fillOval(200,325,10,10);
        g.fillRect(105,340,10,10);
        g.fillRect(120,340,10,10);
        g.fillRect(135,340,10,10);
        g.fillRect(150,340,10,10);
        g.fillRect(165,340,10,10);
        g.fillRect(180,340,10,10);
        g.fillRect(195,340,10,10);
        g.fillRect(210,340,5,10);
        g.fillRect(105,355,10,10);
        g.fillRect(120,355,10,10);
        g.fillRect(135,355,10,10);
        g.fillRect(150,355,10,10);
        g.fillRect(165,355,10,10);
        g.fillRect(180,355,10,10);
        g.fillRect(195,355,10,10);
        g.fillRect(210,355,5,10);
        //Mouse
        g.setColor(new Color(Integer.parseInt(MouseBgColor.substring(0, x3)), Integer.parseInt(MouseBgColor.substring(x3 + 1, y3)), Integer.parseInt(MouseBgColor.substring(y3 + 1))));
        g.fillRect(245, 335, 30, 25);
        g.fillArc(245, 320, 30, 30, 0, 180);
        g.setColor(new Color(Integer.parseInt(MouseFrColor.substring(0, x4)), Integer.parseInt(MouseFrColor.substring(x4 + 1, y4)), Integer.parseInt(MouseFrColor.substring(y4 + 1))));
        g.drawArc(245, 320, 30, 30, 0, 180);
        g.drawRect(245, 335, 30, 25);
        g.drawRect(258,320,4,15);

    }
}

Applet that displays the following shapes a. Fido Dido b. House c. Mobile d. Computer

FIDO DIDO

import java.awt.*;
import java.applet.Applet;
public class Fido_Dido extends Applet {
 public void paint(Graphics g)
   {
     g.setColor(Color.GREEN);
     g.fillArc(160,150,150,240,180,180);
     g.setColor(Color.BLACK);
     g.fillOval(190,300,30,30);
     g.fillOval(250,300,30,30);
     g.drawLine(235,310,235,350);
     g.drawArc(160,229,10,40,-90,180);
     g.drawArc(180,229,10,40,-90,180);
     g.drawArc(200,229,10,40,-90,180);
     g.drawArc(220,229,10,40,-90,180);
     g.drawArc(240,229,10,40,-90,180);
     g.drawArc(260,229,10,40,-90,180);
     g.drawArc(280,229,10,40,-90,180);
     g.drawArc(300,229,10,40,-90,180);
     g.drawArc(161,188,10,40,90,180);
     g.drawArc(181,188,10,40,90,180);
     g.drawArc(201,188,10,40,90,180);
     g.drawArc(221,188,10,40,90,180);
     g.drawArc(241,188,10,40,90,180);
     g.drawArc(261,188,10,40,90,180);
     g.drawArc(281,188,10,40,90,180);
     g.drawArc(301,188,10,40,90,180);
     g.setColor(Color.RED);
     g.drawArc(210,340,50,30,0,-180);
   }
}


HOUSE

import java.awt.*;
import java.applet.Applet;

public class House extends Applet{
    int xs[]={550,700,625};
    int ys[]={190,190,90};
    public void paint(Graphics g)
    {

        g.setColor(Color.red);
        g.fillRect(550, 190, 150, 150);
        g.setColor(Color.green);
        g.fillPolygon(xs, ys, 3);
        g.drawLine(625, 100, 550, 190);
        g.drawLine(625, 100, 700, 190);
        g.drawLine(550,190,495,250);
        g.drawLine(700,190,750,250);
        g.setColor(Color.gray);
        g.fillRect(570,210,25,40);
        g.fillRect(600,265,50,70);
        g.setColor(Color.black);
        g.fillRect(623,265,4,70);

    }

}




















MOBILE

import java.awt.*;
import java.applet.Applet;
public class mobile extends Applet {
public void paint(Graphics g)
    {
       g.setColor(Color.BLACK);
       g.drawRoundRect(40,60,100,200,20,20);
       g.fillRoundRect(40,60,100,200,20,20);
       g.setColor(Color.GRAY);
       g.drawRoundRect(55,61,70,99,20,20);
       g.fillRoundRect(55,61,70,99,20,20);
       g.setColor(Color.darkGray);
       g.fillRect(55,162,20,28);
       g.fillRect(80,162,20,28);
       g.fillRect(105,162,20,28);
       g.fillRect(55,192,20,15);
       g.fillRect(80,192,20,15);
       g.fillRect(105,192,20,15);
       g.fillRect(55,210,20,15);
       g.fillRect(80,210,20,15);
       g.fillRect(105,210,20,15);
       g.fillRect(55,227,20,15);
       g.fillRect(80,227,20,15);
       g.fillRect(105,227,20,15);


      
    }
}











COMPUTER

 import java.awt.*;
import java.applet.*;

public class Computer extends Applet {

    int xs[] = {100, 220, 160};
    int ys[] = {270, 270, 220};
     public void paint(Graphics g) {
        //Monitor
        g.setColor(Color.red);
        g.drawRect(100, 100, 120, 120);
        g.fillPolygon(xs, ys, 3);
        //CPU
        g.setColor(Color.black);
        g.fillRect(270, 100, 70, 170);
        g.setColor(Color.red);
        g.drawRect(270, 100, 70, 170);
        g.fillRect(305,110,30,10);
        g.fillOval(325,125,8,8);
        g.fillOval(287,142,35,35);
        g.fillOval(290,187,30,30);
        g.fillOval(293,227,25,25);
        //KeyBoard
        g.setColor(Color.black);
        g.fillRect(100, 320, 120, 50);
        g.setColor(Color.red);
        g.drawRect(100, 320, 120, 50);
        g.fillOval(110,325,10,10);
        g.fillOval(125,325,10,10);
        g.fillOval(140,325,10,10);
        g.fillOval(155,325,10,10);
        g.fillOval(170,325,10,10);
        g.fillOval(185,325,10,10);
        g.fillOval(200,325,10,10);
        g.fillRect(105,340,10,10);
        g.fillRect(120,340,10,10);
        g.fillRect(135,340,10,10);
        g.fillRect(150,340,10,10);
        g.fillRect(165,340,10,10);
        g.fillRect(180,340,10,10);
        g.fillRect(195,340,10,10);
        g.fillRect(210,340,5,10);
        g.fillRect(105,355,10,10);
        g.fillRect(120,355,10,10);
        g.fillRect(135,355,10,10);
        g.fillRect(150,355,10,10);
        g.fillRect(165,355,10,10);
        g.fillRect(180,355,10,10);
        g.fillRect(195,355,10,10);
        g.fillRect(210,355,5,10);
        //Mouse
        g.setColor(Color.black);
        g.fillRect(245, 335, 30, 25);
        g.fillArc(245, 320, 30, 30, 0, 180);
        g.setColor(Color.red);
        g.drawArc(245, 320, 30, 30, 0, 180);
        g.drawRect(245, 335, 30, 25);
        g.drawRect(258,320,4,15);
        }
 }
 /*
 <applet code="Computer.java" width=500 height=500>
 </applet>
 */

Applet that displays your name 10 times using different colors and Font.

import java.awt.*;
import java.applet.Applet;
public class Name extends Applet {
    public void paint(Graphics g)
    {
        setBackground(Color.magenta);
        setForeground(Color.BLACK);
        g.setFont(new Font("Bodoni MT Black",Font.ITALIC,30));
        g.drawString("Hemant", 100, 100);

        g.setColor(Color.YELLOW);
        Font f1=new Font("Arial",Font.BOLD+Font.ITALIC,30);
        g.setFont(f1);
        g.drawString("Hemant", 100,150);

        g.setColor(Color.BLUE);
        Font f2=new Font("Times new roman",Font.BOLD,30);
        g.setFont(f2);
        g.drawString("Hemant", 100,200);

        g.setColor(Color.GREEN);
        Font f3=new Font("Helvetica",Font.BOLD+Font.ITALIC,30);
        g.setFont(f3);
        g.drawString("Hemant", 100,250);

        g.setColor(Color.RED);
        Font f4=new Font("Ms scan",Font.BOLD+Font.ITALIC,30);
        g.setFont(f4);
        g.drawString("Hemant", 100,300);

        g.setColor(Color.WHITE);
        Font f5=new Font("Algerian",Font.BOLD+Font.ITALIC,40);
        g.setFont(f5);
        g.drawString("Hemant", 100,350);

        g.setColor(Color.cyan);
        Font f6=new Font("comic",Font.BOLD+Font.ITALIC,30);
        g.setFont(f6);
        g.drawString("Hemant", 100,400);

        g.setColor(Color.gray);
        Font f7=new Font("caliographic",Font.BOLD+Font.ITALIC,30);
        g.setFont(f7);
        g.drawString("Hemant", 100,450);

        g.setColor(Color.ORANGE);
        Font f8=new Font("Viner Hand ITC",Font.BOLD+Font.ITALIC,30);
        g.setFont(f8);
        g.drawString("Hemant", 100,500);

        g.setColor(Color.PINK);
        Font f9=new Font("Papyrus",Font.BOLD+Font.ITALIC,30);
        g.setFont(f9);
        g.setColor(Color.yellow);
        g.drawString("Hemant", 100,50);
       
    }
}

Tuesday, 27 August 2013

Create a matrix that contains sales of 4 products for 4 regions and perform the following operations a. Total sales of products for region-wise b. Total sales of products product-wise c. Highest and lowest selling products d. Total sales made by the company

import java.util.Scanner;

class Product {

    public static void main(String[] args) {
        int sum = 0, tsum = 0, i, j;
        Scanner in = new Scanner(System.in);
        int arr[][] = new int[4][4];
        System.out.println("Enter product");
        for (i = 0; i <= 3; i++) {
            for (j = 0; j <= 3; j++) {
                arr[i][j] = in.nextInt();
            }
        }
        int h = arr[0][0], l = arr[0][0];
        System.out.println("Matrix form of entered product is:");
        for (i = 0; i <= 3; i++) {
            for (j = 0; j <= 3; j++) {
                System.out.print("\t" + arr[i][j]);
            }
            System.out.println();
        }
        for (i = 0; i <= 3; i++) {
            System.out.println("Total sales of product for region " + i + "is:");
            for (j = 0; j <= 3; j++) {
                sum = sum + arr[j][i];
                tsum = tsum + arr[i][j];
            }
            System.out.println(sum);
            sum = 0;
        }
        for (i = 0; i <= 3; i++) {
            System.out.println("Total sales of product for product" + i + "is");
            for (j = 0; j <= 3; j++) {
                sum = sum + arr[i][j];
            }
            System.out.println(sum);
            sum = 0;
        }
        for (i = 0; i <= 3; i++) {
            for (j = 0; j <= 3; j++) {
                if (h < arr[i][j]) {
                    h = arr[i][j];
                }
            }
        }
        for (i = 0; i <= 3; i++) {
            for (j = 0; j <= 3; j++) {
                if (l > arr[i][j]) {
                    l = arr[i][j];
                }
            }
        }
        System.out.println("Highhest selling product is: " + h);
        System.out.println("Lowest selling product is: " + l);
        System.out.println("Total sales made by company is: " + tsum);
    }
}

Program that accepts a number as command line argument and display its square. If argument contains more than 1 number proper error message should be displayed.

public class Square {

    public static void main(String[] args) {
        if (args.length != 1)
        {
            System.out.println("Invalid argument");
            System.exit(0);

        }
        int num=Integer.parseInt(args[0]);
        System.out.println("Square of number is: "+num*num);



    }
}

Program that accepts a 2D array of 4 by 5 by numbers and display the sum of all the rows, columns and the entire matrix ?

import java.util.Scanner;

public class TwoD {

    public static void main(String[] args) {
        float sum = 0, isum = 0;
        int a[][] = new int[4][5];
        Scanner in = new Scanner(System.in);
        for (int i = 0; i <= 3; i++) {
            for (int j = 0; j <= 4; j++) {
                System.out.println("Enter element no. " + i + j);
                a[i][j] = in.nextInt();
            }
        }
        System.out.println("Entered matrix is:");
        for (int i = 0; i <= 3; i++) {
            for (int j = 0; j <= 4; j++) {
                System.out.print(a[i][j] + "    ");
            }
            System.out.println();
        }
        for (int i = 0; i <= 3; i++) {
            for (int j = 0; j <= 4; j++) {
                sum = sum + a[i][j];
            }
            isum = isum + sum;
            System.out.println("Sum of " + (i + 1) + " row is:" + sum);
            sum = 0;
        }

        for (int i = 0; i <= 4; i++) {
            for (int j = 0; j <= 3; j++) {
                sum = sum + a[j][i];
            }
            System.out.println("Sum of " + (i + 1) + " coloum is:" + sum);
            sum=0;

        }
        System.out.println("Sum of intire matrix is: " + isum);

    }
}

Program that accepts an array by 10 numbers and display them in ascending order

import java.util.Scanner;

public class Ascending {

    public static void main(String[] args) {
        int temp;
        Scanner in = new Scanner(System.in);
        int a[] = new int[10];
        for (int i = 0; i <= 9; i++) {
            System.out.println("Enter element no. " + (i + 1));
            a[i] = in.nextInt();
        }
        for (int i = 0; i <= 9; i++) {
            for (int j = i + 1; j <= 9; j++) {
                if (a[i] > a[j]) {
                    temp = a[i];
                    a[i] = a[j];
                    a[j] = temp;
                }
            }
        }
        for (int i = 0; i <= 9; i++) {
            System.out.print(a[i] + " ");
        }
    }
}

Saturday, 11 August 2012

TempEmp CLASS QUESTION

TEMPEMP CLASS QUESTION

import java.util.Scanner;


public class TempEmp extends Employee {
protected String grade;
    protected int days;
public TempEmp() {
    }
public TempEmp(int x, String y, String grade, int days) {
super(x, y);
this.grade = grade;
this.days = days;
    }
public TempEmp(String grade) {
super(20, "Nirmal");
this.grade = grade;
days = 10;
    }
public TempEmp(int days) {
super(20, "Vinod");
this.days = days;
grade = "A";

}public int getDays() {
        return days;
    }


public String getGrade() {
        return grade;
    }

    @Override
    public void getData() {
        super.getData();
Scanner in = new Scanner(System.in);
System.out.println("Enter grade:");
grade = in.nextLine();
System.out.println("Enter work of days:");
days = in.nextInt();
    }

    @Override
    public void showData() {

super.showData();
System.out.println("Grade is:" + grade);

System.out.println("days of working is:" + days);
    }
public static void main(String[] args) {
TempEmp t = new TempEmp(1234, "Manoj", "B", 60);
t.showData();
        TempEmp t1 = new TempEmp("A");
t1.showData();
        TempEmp t2 = new TempEmp(60);

t2.showData();
        TempEmp t3 = new TempEmp();
t3.getData();
        t3.showData();
}

}

POINT CLASS FOR RECTANGLE

POINT CLASS FOR RECTANGLE




import java.util.Scanner;


public class Point {
protected int x_co;
    protected int y_co;

    public Point() {
    }


public Point(int x, int y) {
        x_co = x;
        y_co = y;
    }
public int getX_co() {
        return x_co;
    }
public void setX_co(int x_co) {
        this.x_co = x_co;
    }


public int getY_co() {
        return y_co;
    }
public void setY_co(int y_co) {
this.y_co = y_co;
    }


public void getData() {
Scanner in = new Scanner(System.in);
System.out.println("Enter X_CO:");
        x_co = in.nextInt();
        System.out.println("Enter Y_CO:");
        y_co = in.nextInt();
    }
public void showData() {
System.out.println("X_CO=" + x_co);
        System.out.println("Y_CO=" + y_co);
    }
public static void main(String[] args) {

Point p = new Point();

Point p1 = new Point();
p1.getData();
p.showData();
p1.showData();
}

}

Create a class called Student that stores its name, class, section, and marks in four subjects. Write functions to accept, display and get/set of the data.

Create a class called Student that stores its name, class, section, and marks in four subjects. Write
functions to accept, display and get/set of the data.




import java.util.Scanner;


public class Student {


protected String name;

protected int Class;

protected char section;

protected int s1;

protected int s2;

protected int s3;

protected int s4;


public Student() {

}


public Student(String name, int Class, char section, int s1, int s2, int s3, int s4) {

this.name = name;

this.Class = Class;

this.section = section;

this.s1 = s1;

this.s2 = s2;

this.s3 = s3;

this.s4 = s4;
    }


public String getName() {

return name;
    }


public void setName(String name) {

this.name = name;
    }


public int get_Class() {

return Class;
    }


public void setClass(int Class) {

this.Class = Class;
    }


public char getSection() {

return section;
    }


public void setSection(char section) {

this.section = section;
    }


public int getS1() {

return s1;
    }


public void setS1(int s1) {

this.s1 = s1;
    }


public int getS2() {

return s2;
    }


public void setS2(int s2) {

this.s2 = s2;
    }


public int getS3() {

return s3;
    }


public void setS3(int s3) {

this.s3 = s3;
    }


public int getS4() {

return s4;
    }


public void setS4(int s4) {

this.s4 = s4;
    }


public void getData() {

Scanner in = new Scanner(System.in);

System.out.println("Enter name:");

name = in.nextLine();

System.out.println("Enter class:");

Class = in.nextInt();

System.out.println("Enter Section:");

section = in.next().charAt(0);

System.out.println("Enter marks in 4 subjects:");

s1 = in.nextInt();
        s2 = in.nextInt();
        s3 = in.nextInt();
        s4 = in.nextInt();


    }


public void showData() {

System.out.println("Name is: " + name + "\nClass is: " + Class + "\nSection is: " + section + "\nMarks in 4 subjects are: " + s1 + " " + s2 + " " + s3 + " " + s4);

}


public int getTotal() {

return (s1 + s2 + s3 + s4);

}


public float getPercentage() {

return (float) (getTotal() / 4);

}


public static void main(String[] args) {
Student s1 = new Student("Gourav", 12, 'A', 89, 95, 75, 81);

 s1.showData();

System.out.println("Total is: " + s1.getTotal());
System.out.println("Percentage is: " + s1.getPercentage());
Student s2 = new Student();

s2.getData();
s2.showData();
System.out.println("Total is: " + s2.getTotal());

System.out.println("Percentage is: " + s2.getPercentage());

   
}

}

Create a class called Employee that stores its code and name. Create two derive classes from Employee named TempEmp and PerEmp.

Create a class called Employee that stores its code and name. Create two derive classes from
Employee named TempEmp and PerEmp.




import java.util.Scanner;


public class Employee {
protected int code;
protected String name;
public Employee() {
    }
public Employee(int code) {
        this.code = code;
    }


public Employee(String name) {
        this.name = name;
    }
public Employee(int code, String name) {
        this.code = code;
        this.name = name;
    }
public int getCode() {
        return code;
    }
public void setCode(int code) {
        this.code = code;
    }


public String getName() {
        return name;
    }
public void setName(String name) {
        this.name = name;
    }

public void getData() {
        Scanner in = new Scanner(System.in);
System.out.println("Enter name");
        name = in.nextLine();
System.out.println("Enter code");
        code = in.nextInt();
    }
public void showData() {
        System.out.println("Code is:" + code);
System.out.println("Name is:" + name);
}
public static void main(String[] args) {

Employee e = new Employee(1234, "hemant");
e.showData();

}

}
 

Create a class called Employee that stores its name, department, designation and basic salary.

Create a class called Employee that stores its name, department, designation and basic salary. Write
functions to accept, display and get/set of the data.
The incentives includes HRA, DA , CA.
import java.util.Scanner;


public class Employe {

    protected String name;
    protected String department;
    protected String designation;
    protected float bs;

    public Employe() {

}
public Employe(String name, String department, String designation, float bs) {

this.name = name;
        this.department = department;
        this.designation = designation;
        this.bs = bs;

}

    public String getName() {

return name;
}

    public void setName(String name) {

this.name = name;
}
public String getDepartment() {
return department;

}


public void setDepartment(String department) {
this.department = department;
}
public String getDesignation() {
return designation;
}

    public void setDesignation(String designation) {
this.designation = designation;
}

    public void getData() {
Scanner in = new Scanner(System.in);
System.out.println("Enter name:");
name = in.nextLine();
System.out.println("Enter department:");
department = in.nextLine();
System.out.println("Enter designation:");
designation = in.nextLine();
System.out.println("Enter Basic salary:");
    bs = in.nextInt();
}
public void showData() {
System.out.println("Name is:" + name);

System.out.println("Department is:" + department);
        System.out.println("Designation is:" + designation);
System.out.println("Basic salary is:" + bs);
}


public float getBs() {

return bs;
}


public void setBs(float bs) {
this.bs = bs;

}
public float getHRA() {
        return bs * 20 / 100;
    }


public float getDA() {

return bs * 10 / 100;

}
public float getCA() {
        return bs * 10 / 100;
    }

    public static void main(String[] args) {

        Employe e = new Employe("Vikas", "management", "ceo", 60000);
        e.showData();
        System.out.println("HRA is:" + e.getHRA());
        System.out.println("DA is:" + e.getDA());
System.out.println("CA is:" + e.getCA());
        Employe e1 = new Employe();
        e1.getData();
       e1.showData();
System.out.println("HRA is:" + e1.getHRA());
System.out.println("DA is:" + e1.getDA());
System.out.println("CA is:" + e1.getCA());

}
}

Create a derive class from this class called DerivedA with an integer as its member data

Create a derive class from this class called DerivedA with an integer as its member data. Write suitable constructors and method.



import java.util.Scanner;


class DerivedA extends AbstractA {


protected int a;

    public DerivedA(){
}


public DerivedA(int a) {
this.a = a;

}


public int getA() {
return a;

}
public void setA(int a) {
this.a = a;
}


public void getData() {
Scanner in = new Scanner(System.in);
System.out.println("Enter A:");
a = in.nextInt();

}


public void showData() {

System.out.println("A is:" + a);
}
public static void main(String[] args) {
AbstractA x = new DerivedA(10);
        DerivedA y = new DerivedA(20);
        x.showData();
        y.showData();
    }
}

Create a class called Circle derived from Point. Apart from Point this class should store the radius

Create a class called Circle derived from Point. Apart from Point this class should store the radius.  declare a static final called PI in this class that can
be used in area and circumference methods.



import java.util.Scanner;
class Circle1 {
protected float radius;
public Circle1() {

radius = 10;

}


public Circle1(float radius){

this.radius = radius;

}


public float getRadius() {
return radius;

}


public void setRadius(float radius) {

this.radius = radius;

}


public void getData() {

Scanner in = new Scanner(System.in);

System.out.println("Enter Radius");
radius = in.nextFloat();

}


public void showData() {

System.out.println("Radius:" + radius);

}


public float getArea() {

return (float) (Math.PI * Math.pow(radius, 2));

}


public float getCircumfrence() {
return (float) (2 * Math.PI * radius);
}


public static void main(String[] args) {

Circle1 c1 = new Circle1(10);

c1.showData();

System.out.println("Area is:" + c1.getArea());

System.out.println("Circumfrence is:" + c1.getCircumfrence());

Circle1 c2 = new Circle1();

c2.getData();

c2.showData();

System.out.println("Area is:" + c2.getArea());

System.out.println("Circumfrence is:" + c2.getCircumfrence());

}
}

Create a class called Circle that stores radius

Create a class called Circle that stores radius.methods to get/set, displays and accept the data.
All write methods that return its area and circumference.

import java.util.Scanner;

class Circle extends Point {

    protected float radius;
    protected static final float PI = 3.14f;

    public Circle(int x, int y) {
        super(x, y);
        radius = 10;

    }

    public Circle(float r) {
        super(10, 10);
        radius = r;
    }

    public Circle(int x, int y, float radius) {
        super(x, y);
        this.radius = radius;
    }

    public Circle(Point p) {
        super(p.getX_co(), p.getY_co());
        radius = 10f;

    }

    public Circle(Point p, float r) {
        super(p.getX_co(), p.getY_co());
        radius = r;
    }

    public void setRadius(float radius) {
        this.radius = radius;
    }

    @Override
    public void getData() {
        super.getData();
        Scanner in = new Scanner(System.in);
        System.out.println("enter radius");
        radius = in.nextFloat();
    }

    @Override
    public void showData() {
        super.showData();
        System.out.println("Radius:" + radius);
    }

    public float getArea() {
        return (float) (PI * Math.pow(radius, 2));
    }

    public float getPerimeter() {
        return (float) (2 * PI * radius);
    }

    public Point getCenter() {
        Point p1 = new Point(getX_co(), getY_co());
        return p1;
    }

    public static void main(String[] args) {
        Circle c1 = new Circle(10, 10);
        c1.showData();
        Point p1 = new Point(1, 2);
        Circle c2 = new Circle(p1, 3f);
        c2.showData();
        c2.getCenter().showData();
    }
}

Create a class called Rectangle derived from Point class.

Create a class called Rectangle derived from Point class.  Write suitable method that accepts, displays and reads/writes the data. Write appropriate constructors and method that returns its area



 import java.util.Scanner;


class Rectangle extends Point {
protected float width;
protected float height;
public Rectangle1() {
    }
public Rectangle1(float width, float height) {
        super(10, 20);
        this.width = width;
        this.height = height;
    }
public Rectangle1(int x, int y, float width, float height) {
        super(x, y);
        this.width = width;
        this.height = height;
    }
public Rectangle1(Point p) {
        super(p.getX_co(), p.getY_co());
        width = 20.5f;
        height = 15.10f;
    }
public float getWidth() {
        return width;
    }
public void setWidth(float width) {
        this.width = width;
    }
public float getHeight() {
        return height;

    }
public void setHeight(float height) {
        this.height = height;
    }

    @Override
    public void getData() {

super.getData();
Scanner in = new Scanner(System.in);
System.out.println("Enter Width:");
width = in.nextFloat();
System.out.println("Enter Height:");
height = in.nextFloat();
    }

    @Override
    public void showData() {
super.showData();
System.out.println("Width is:" + width);
System.out.println("Height is:" + height);

}
public float getArea() {
        return height * width;
    }
public static void main(String args[]) {

Rectangle1 r = new Rectangle1(15, 25);
r.showData();
System.out.println("Area is:" + r.getArea());
Rectangle1 r2 = new Rectangle1(15, 25, 45, 55);
r2.showData();
System.out.println("Area is:" + r2.getArea());
Point p = new Point(12, 15);
Rectangle1 r3 = new Rectangle1(p);
r3.showData();
Rectangle1 r1 = new Rectangle1();
        r1.getData();
        r1.showData();
        System.out.println("Area is:" + r1.getArea());
}

}


    (PLEASE CHANGE CLASS NAME)

Create a class called Rectangle that stores width and height. display and get/set of the data

Create a class called Rectangle that stores width and height. display and
get/set of the data. its area. Test the code by creating an
implementation program


 import java.util.Scanner;


class Rectangle {
protected int width;
protected int height;
public Rectangle() {
    }
public Rectangle(int x, int y) {
        width = x;
        height = y;
    }
public Rectangle(int x) {
        width = x;
        height = 20;
    }


public int getWidth() {
        return width;
    }
public int getHeight() {
        return height;
    }
public void setWidth(int width) {
        this.width = width;
    }
public void setHeight(int height) {
        this.height = height;
    }


public void getData() {
        Scanner in = new Scanner(System.in);
System.out.println("Enter Width:");
        width = in.nextInt();
System.out.println("Enter Height:");
        height = in.nextInt();
    }
public void showData() {
System.out.println("Width is:" + width + "\nHeight is:" + height);
    }
public float getArea() {
        return (float) (height * width);
    }
public static void main(String args[]) {

Rectangle r = new Rectangle(20, 10);
        r.showData();
        System.out.println("Area is:" + r.getArea());
Rectangle r1 = new Rectangle();
r1.getData();
        r1.showData();
System.out.println("Area is:" + r1.getArea());
}

}


JAVA program which displays the following pyramid where num=5

        1
      212
    32123
  4321234
543212345
  4321234
    32123
      212
        1


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

int p = 5;
for (int i = 1; i <= 5; i++) {
for (int l = 4; l >= i; l--) {
System.out.print(" ");
}

for (int j = i; j >= 1; j--) {

System.out.print("" + j);
}
for (int k = 2; k <= i; k++){
System.out.print("" + k);
}

System.out.print("\n");
}

for (int i = 1, k = 4; i <= 4; i++, k--) {

for (int l = 1; l <= i; l++) {

System.out.print(" ");

}

for (int j = k; j >= 1; j--) {
System.out.print("" + j);
}

p--;
for (int m = 2; m <= p; m++) {
System.out.print("" + m);
}


System.out.print("\n");
}


}

}

JAVA Program accepts an integer and display whether it is a single digit, two digit, three digits or more three digits.



import java.util.Scanner;


public class Q{


public static void main(String[] args){

int d, f, c = 0;
Scanner a = new Scanner(System.in);
     
System.out.println("Enter any no.:");
int n = a.nextInt();

while (n > 0) {

d = n % 10;
n = n / 10;
c++;
}

System.out.println("the digit of no is:" + c);

}

}