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);
}
}
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);
}
}
@ Tamim: I told do not use Method......
ReplyDeleteExplain the general form of a class.
ReplyDeleteans:- 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.
*** Write a Program to find the volume of a Box (without using methods)***
ReplyDeleteclass 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);
}
}
The general form of a class.
ReplyDeleteA 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
Write a Program to find the volume of a Box :
ReplyDeleteclass 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);
}
}
@Bushra: There are no change found from the previous submission (Tamim). This submission will carry marks. I am observing your practice.
ReplyDeletea) Explain the General Form of a Class.
ReplyDeleteANS :
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();
}
}
b) Write a program to find the volume of a Box. Define only three instance variables: width, height and depth. Do not use Methods.
ReplyDeletepublic 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);
}
}
**********b) Write a program to find the volume of a Box. Define only three instance variables: width, height and depth. Do not use Methods.*******
ReplyDeletepackage 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);
}
}
a) Explain the General Form of a Class.
ReplyDeleteAns:
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
}
}
b)Write a program to find the volume of a Box. Define only three instance variables: width, height and depth. Do not use Methods.
ReplyDeleteAns:
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);
}
}
sir i am ferdous ahmed.,id-201230769.
ReplyDeleteb)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( ));
}
}
/*Write a program to find the volume of a Box. Define only three instance variables: width, height and depth. Do not use Methods.*/
ReplyDeleteimport 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);
}
}
Q:Write a Program to find the volume of a Box
ReplyDeleteMohammad 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);
}
}
noted
Delete...............................
ReplyDeleteDepartment :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);
}
}
noted. use name and picture.
Delete
ReplyDelete//*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);
}
}
noted
Deletepackage project1.day1;
ReplyDeleteclass 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);
}
}
noted
DeleteThis comment has been removed by the author.
ReplyDeleteID-201420406
ReplyDeleteBatch-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);
}
}
noted
Deletepackage volbox;
ReplyDeleteclass 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);
}
}
noted and found correct
DeleteID-201420405
ReplyDeleteBatch-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);
}
}