Structure Query Language, C programming, Java, Servlet, Jsp, Unix

Sunday 15 July 2012

Define a class called Product, each product has a name, a product code and manufacturer name. Define variables, methods and constructors, for the Product class. Write a class called Test Product, with the main method to test the methods and constructors of the Product class.


[ test_product.java ]
import java.io.*;
class product
{
String p_name,m_name;
int p_code;
product()
{
System.out.println("CONSTRUCTOR CALLED....\n");
p_code=0;
}
//inisialization block
{
System.out.println("INISIALIZATION BLOCK CALLED....\n");
}
static
{
System.out.println("STATIC BLOCK CALLED....\n");
}
public void get_data() throws IOException
{
System.out.println(".....GETTING DATA FROM USER.....\n\n");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("\tEnter Product Code : ");
p_code=Integer.parseInt(br.readLine());
System.out.print("\tEnter Product Name : ");
p_name=br.readLine();
System.out.print("\tEnter Manufacturar Name : ");
m_name=br.readLine();
}
public void display_data()
{
System.out.println("\n\n.....Displaying data....\n\n");
System.out.println("\tProduct Code : " + p_code);
System.out.println("\tProduct Name : " + p_name);
System.out.println("\tManufacturar Name : " + m_name);
}
}
class test_product
{
public static void main(String args[]) throws IOException
{
product obj;
obj=new product();
obj.get_data();
obj.display_data();
}
}

2 comments:

  1. GoTo Command Prompt(Win + R)

    HOW TO COMPILE
    javac c:\yourdir\test_product.java

    HOW TO EXECUTE
    java c:\yourdir\test_product

    ReplyDelete