Friday, December 6, 2013

Class in JAVA : Day 1


  Explain the General Form of a Class.   --------------------------------------------------------------------------------------------------------------------------
Write a program to find the volume of a Box. Define only three instance variables: width, height and depth. Do not use Methods.
-----------------------------------------------------------------------------------------------------------------------------
package volbox;
class Bigbox
{
   double width;
   double depth;
   double height;
}
public class Volbox
{
  public static void main(String[] args)
  {
    Bigbox lbox=new Bigbox();
    lbox.width=15;
    lbox.depth=8;
    lbox.height=20;
    double vol=lbox.width * lbox.depth * lbox.height;
    System.out.println("Volume of box is:" +vol);
  }
}

27 comments:

  1. @ Tamim: I told do not use Method......

    ReplyDelete
  2. Explain the general form of a class.

    ans:- A class is declared by use of the class keyword.the general form a class definition is shown here

    class classname
    {
    type instance-variable1;
    type instance-variable2;

    type methodname1(parameter list)
    {
    //Body Of Method
    }
    type methodname2(parameter list)
    {
    //Body Of Method
    }

    }

    the data or variables, defined within a class are called instance variables. the code is contained within methods. collectively the methods and variables defined within a class are called members of the class. All methods have the same general form as main().java classes do not need to have a main() method.

    ReplyDelete
  3. *** Write a Program to find the volume of a Box (without using methods)***

    class box
    {
    double width;
    double height;
    double depth;
    }
    // This class declares an object of type Box //
    class BoxDemo
    {
    public static void main()
    {
    Box mybox = new Box();
    double vol;
    // assign values to mybox`s instance variable //
    mybox.width=10;
    mybox.height=15;
    mybox.depth=5;
    // compute volume of box //
    vol=mybox.width*mybox.height*mybox.depth;
    System.out.println(vol);
    }
    }

    ReplyDelete
  4. The general form of a class.

    A class is declared by use of the class keyword.the general form a class definition is shown here

    class classname
    {
    type instance-variable1;
    type instance-variable2;

    type methodname1(parameter list)
    {
    //Body Of Method
    }
    type methodname2(parameter list)
    {
    //Body Of Method
    }

    }

    the data or variables, defined within a class are called instance variables. the code is contained within methods. collectively the methods and variables defined within a class are called members of the class

    ReplyDelete
  5. Write a Program to find the volume of a Box :

    class box
    {
    double width;
    double height;
    double depth;
    }
    // This class declares an object of type Box //
    class BoxDemo
    {
    public static void main()
    {
    Box mybox = new Box();
    double vol;
    // assign values to mybox`s instance variable //
    mybox.width=10;
    mybox.height=15;
    mybox.depth=5;
    // compute volume of box //
    vol=mybox.width*mybox.height*mybox.depth;
    System.out.println(vol);
    }
    }

    ReplyDelete
  6. @Bushra: There are no change found from the previous submission (Tamim). This submission will carry marks. I am observing your practice.

    ReplyDelete
  7. a) Explain the General Form of a Class.
    ANS :

    public class AnotherClass {

    type instance-variable_1;
    type instance-variable_2;
    .
    .
    .
    .
    type instance-variable_N;


    type methodename_1(parameter-list)
    {
    // body of methode;
    }


    type methodename_2(parameter-list)
    {
    // body of methode;
    }
    .
    .
    .
    .
    .

    type methodename_N(parameter-list)
    {
    // body of methode;
    }


    }



    public class Classname {

    public static void main(String[] args) {

    AnotherClass an = new AnotherClass();
    an. methodename_1();
    an. methodename_2();
    .
    .
    .
    .
    .
    .
    .
    an. methodename_N();
    }

    }

    ReplyDelete
  8. b) Write a program to find the volume of a Box. Define only three instance variables: width, height and depth. Do not use Methods.



    public class Mybox {

    double width;
    double height;
    double depth;

    public static void main(String[] args) {

    Mybox mb = new Mybox();
    double vol;

    mb.width = 10;
    mb.height = 20;
    mb.depth = 15;

    vol = mb.width*mb.height*mb.depth;

    System.out.println("The Volume is : " +vol);

    }

    }

    ReplyDelete
  9. **********b) Write a program to find the volume of a Box. Define only three instance variables: width, height and depth. Do not use Methods.*******

    package box;
    public class Box
    {
    double width;
    double height;
    double depth;
    }
    class BoxDemo
    {
    public static void main(String[] args)
    {
    Box mbox = new Box();
    double vol;
    mbox.width = 25;
    mbox.height = 15;
    mbox.depth = 10;
    vol = mbox.width*mbox.height*mbox.depth;
    System.out.println("Volume is " + vol);
    }
    }

    ReplyDelete
  10. a) Explain the General Form of a Class.

    Ans:

    class classname{
    type instance-variable1;
    type instance-variable2;
    //--
    type instance-variableN;
    type mathodname1(parameter-list){
    //body of method
    }
    type mathodnamme2(parameter-list){
    //body of method
    }
    //---
    type mathodnameN(parameter-list){
    //body of method
    }
    }

    ReplyDelete
  11. b)Write a program to find the volume of a Box. Define only three instance variables: width, height and depth. Do not use Methods.

    Ans:


    class Box{
    double width;
    double height;
    double depth;
    }
    class Boxdemo{
    public static void main(String args[]){
    Box mybox=new Box();
    double vol;
    mybox.width=5;
    mybox.height=10;
    mybox.depth=7;
    vol=mybox.width*mybox.height*mybox.depth;
    System.outprintln(volume is"+vol);
    }
    }

    ReplyDelete
  12. sir i am ferdous ahmed.,id-201230769.
    b)Write a program to find the volume of a Box. Define only three instance variables: width, height and depth. Do not use Methods.
    class Box
    {
    int l,b,h;
    int volume( )
    {
    return(l*b*h);
    }
    }
    class Abc
    {
    public static void main(String args[ ])
    {
    Box b1= new Box( );
    b1.l=4;
    b1.b=6;
    b1.h=10;
    System.out.println(“Length of box is = 4″);
    System.out.println(“Breadth of box is = 6″);
    System.out.println(“Height of box is = 10″);
    System.out.println(“Volume of box is =”+b1.volume( ));
    }
    }

    ReplyDelete
  13. /*Write a program to find the volume of a Box. Define only three instance variables: width, height and depth. Do not use Methods.*/

    import java.util.Scanner;
    public class box {
    public static void main(String[] args) {
    Scanner scr=new Scanner(System.in);
    System.out.println("Enter height:");
    double height=scr.nextDouble();
    System.out.println("Enter weight:");
    double weight=scr.nextDouble();
    System.out.println("Enter depth:");
    double depth=scr.nextDouble();
    double vol=0;
    vol=height*weight*depth;
    System.out.println("The volume is:"+vol);
    }
    }

    ReplyDelete
  14. Q:Write a Program to find the volume of a Box
    Mohammad Ashraful Hasan Sobuj
    My Department :CSE


    package box;
    public class Box
    {
    double width;
    double height;
    double depth;
    }
    // class declares an object of type Box
    class Boxstyle
    {
    public static void main(String[] args)
    {
    Box tbox = new Box();
    double vol;
    // tbox`s instance variable
    tbox.width = 300;
    tbox.height = 200;
    tbox.depth = 100;
    vol = tbox.width*tbox.height*tbox.depth;
    System.out.println("Volume is " + vol);
    }
    }

    ReplyDelete
  15. ...............................
    Department :CSE

    ID : 201421068
    ...............................



    package day1;

    class Box{

    double w;
    double h;
    double d;
    }

    public class Day1 {

    public static void main(String[] args) {

    Box mybox = new Box();

    double cal;
    mybox.d = 10;
    mybox.h = 20;
    mybox.w = 30;

    cal = mybox.d*mybox.h*mybox.w;
    System.out.println("Your findout result :" + cal);


    }
    }

    ReplyDelete

  16. //*Write a program to find the volume of a Box.
    //Define only three instance variables: width, height and depth.
    //Do not use Methods.*/
    //Md.Hasmot Hossen
    //Batch = 46th
    //ID No = 201421066

    package personal;
    class box
    {
    int w,h,d;
    }


    public class Personal {

    public static void main(String[] args) {
    // TODO code application logic here

    box mybox = new box();
    int cal;


    mybox.d=20;
    mybox.h=30;
    mybox.w=50;

    cal= mybox.d* mybox.h* mybox.w;
    System.out.println("Your findout result : " + cal);
    }

    }

    ReplyDelete
  17. package project1.day1;
    class box
    {
    int A,B,C;
    }


    public class Project1Day1 {

    public static void main(String[] args) {
    box mybox = new box();
    int cal;

    mybox.A=75;
    mybox.B=25;
    mybox.C=55;

    cal= mybox.A* mybox.B* mybox.C;
    System.out.println("MD:Rashed Prodhania");
    System.out.println("ID:201420763");
    System.out.println("Batch: 46th");
    System.out.println("Display Your Expected Output : " + cal);
    }

    }

    ReplyDelete
  18. This comment has been removed by the author.

    ReplyDelete
  19. ID-201420406
    Batch-46th

    package day1;
    class box
    {
    int X,Y,Z;
    }
    public class Day1
    {
    public static void main(String[]args)
    {
    box mybox = new box();
    int cal;
    mybox.X=55;
    mybox.Y=63;
    mybox.Z=20;

    cal= mybox.X* mybox.Y* mybox.Z;
    System.out.println("Asian University Of Bangladesh");
    System.out.println("Dipertment: BSC In CSE");
    System.out.println("Name:Priyo Nath Chakma");
    System.out.println("ID:201420406");
    System.out.println("Batch: 46th");
    System.out.println("Output Result : " + cal);

    }

    }

    ReplyDelete
  20. package volbox;
    class Bigbox
    {
    double width;
    double depth;
    double height;
    }
    public class Volbox
    {
    public static void main(String[] args)
    {
    Bigbox lbox=new Bigbox();
    lbox.width=15;
    lbox.depth=8;
    lbox.height=20;
    double vol=lbox.width * lbox.depth * lbox.height;
    System.out.println("Volume of box is:" +vol);
    }

    }

    ReplyDelete
  21. ID-201420405
    Batch-46th

    package personal;
    class box
    {
    int w,h,d;
    }


    public class Personal {

    public static void main(String[] args) {
    // TODO code application logic here

    box mybox = new box();
    int cal;


    mybox.d=20;
    mybox.h=30;
    mybox.w=50;

    cal= mybox.d* mybox.h* mybox.w;
    System.out.println("Your findout result : " + cal);
    }

    }

    ReplyDelete