Machine Problem in Java
Create a class named Box that includes integer data fields for length, width, and height. Create three Constructors that requires one, two, and three parameters, respectively.
When one argument is passed to the constructor, assign it to length, assign zeros to height
and width, and display "Line Created". When two arguments are used, assign them to length and width, assign zero to height, and display "Rectangle created".
When three arguments are used, assign them to the three variables and display "Box created".
Save this file as Box.java. Create an application named Text Box that demonstrates each method works correctly. Save the application as TestBox.java
I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details. If you want to advertise on my website kindly contact me also in my email address also. Thank you.
My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
Program Listing
Box.java
package test;
/*
* Box.java
*
* Jake Rodriguez Pomperada, MAED-IT, MIT
* www.jakerpomperada.com and www.jakerpomperada.blogspot.com
* jakerpomperada@gmail.com
* Bacolod City, Negros Occidental Philippines
*
* Machine Problem
*
* Create a class named Box that includes integer data fields for length,
width, and height. Create three Constructors that requires one, two,
and three parameters, respectively. When one argument is passed to
the constructor, assign it to length, assign zeros to height
and width, and display "Line Created".
When two arguments are used, assign them to length and width,
assign zero to height, and
display "Rectangle created".
When three arguments are used,
assign them to the three variables and display "Box created".
Save this file as Box.java. Create an application named Text Box that
demonstrates each method works correctly.
Save the application as TestBox.java
*
*/
class Box {
int length;
int width;
int height;
Box(int length)
{
this.length = length;
this.height = 0;
this.width = 0;
System.out.println();
System.out.print("\tLine Created");
}
Box(int length, int width)
{
this.length = length;
this.width = width;
this.height = 0;
System.out.println();
System.out.print("\tRectangle created");
}
Box(int length, int width, int height)
{
this.length = length;
this.width = width;
this.height = height;
System.out.println();
System.out.print("\tBox created");
}
public int getLenght() {
return length;
}
public int getLenght_getWidth() {
return(length * width);
}
public int getLenght_getWidth_getHeight()
{
return(length * width * height);
}
}
Textbox.java
package test;
/*
* TextBox.java
*
* Jake Rodriguez Pomperada, MAED-IT, MIT
* www.jakerpomperada.com and www.jakerpomperada.blogspot.com
* jakerpomperada@gmail.com
* Bacolod City, Negros Occidental Philippines
*
* Machine Problem
*
* Create a class named Box that includes integer data fields for length,
width, and height. Create three Constructors that requires one, two,
and three parameters, respectively. When one argument is passed to
the constructor, assign it to length, assign zeros to height
and width, and display "Line Created".
When two arguments are used, assign them to length and width,
assign zero to height, and
display "Rectangle created".
When three arguments are used,
assign them to the three variables and display "Box created".
Save this file as Box.java. Create an application named Text Box that
demonstrates each method works correctly.
Save the application as TestBox.java
*
*/
public class TestBox {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println();
System.out.println("\tBox Constructors in Java");
/* create boxes using the various constructors */
Box mybox1 = new Box(12);
Box mybox2 = new Box(4,2);
Box mybox3 = new Box(5,6,8);
mybox1.getLenght();
mybox2.getLenght_getWidth();
mybox3.getLenght_getWidth_getHeight();
System.out.println("\n");
System.out.print("\tEnd of Program \n");
System.out.println();
}
}
No comments:
Post a Comment