Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2007
    Posts
    35

    Red face Unanswered: i am a beginner in JAVA please help...

    i'm 100% sure this is easy for you to treat where i'm wrong...but i'm the new beginner really don't know what happen...this code actually want to show a constructor in java...


    this is the code


    public class customer {

    String name;
    String address;
    String discount;




    customer() {}

    customer c = new customer();


    public static void main(String args[]) {



    customer c1 = new customer("wan","ipoh");
    customer c2 = new customer("nadia","kedah");
    customer c3 = new customer("seri","penang");





    System.out.println("name,address,discount");
    }
    }



    don't know where the mistake i've done so many error...please help...
    **akuccputsedut**
    Intelligent is Me!!But a little confusing
    sometimes needs HELP!!

  2. #2
    Join Date
    Jan 2005
    Posts
    362
    Code:
    public class customer {
           	String name;
    	String address;
    	String discount;    
    
           customer() {}
    	 customer(String Name,String Address) {
    name=Name;
    address=Address}          }
    public class myclass
    {public static void main(String args[]) {
    	 customer c = new customer();
                   customer c1 = new customer("wan","ipoh");
                   customer c2 = new customer("nadia","kedah");
    	       customer c3 = new customer("seri","penang");
    		System.out.println("name,address,discount");
           }}
    Try this

  3. #3
    Join Date
    Jun 2007
    Posts
    35

    thank you

    thank's for your help but i still have error on print part..

    system.out.println don't know why..???
    **akuccputsedut**
    Intelligent is Me!!But a little confusing
    sometimes needs HELP!!

  4. #4
    Join Date
    Jun 2008
    Posts
    4
    Try below code.
    U have two constructor one without any arguments and one with two arguments name and surname.
    run and check output

    package com.test;
    public class customer {

    String name;
    String address;
    String discount;




    customer() {
    System.out.print("Inside No argument Constructor");
    }

    public customer(String name, String surname) {
    // TODO Auto-generated constructor stub
    System.out.print("Passed parametrs are Name "+name+" Surname" +surname);
    }




    public static void main(String args[]) {


    customer c = new customer();
    customer c1 = new customer("wan","ipoh");
    customer c2 = new customer("nadia","kedah");
    customer c3 = new customer("seri","penang");





    System.out.println("name,address,discount");
    }
    }

  5. #5
    Join Date
    Jan 2005
    Posts
    362
    Quote Originally Posted by dimis2500
    Code:
    public class customer {
           	String name;
    	String address;
    	String discount;    
    
           customer() {}
    	 customer(String Name,String Address) {
    name=Name;
    address=Address}          }
    public class myclass
    {public static void main(String args[]) {
    	 customer c = new customer();
                   customer c1 = new customer("wan","ipoh");
                   customer c2 = new customer("nadia","kedah");
    	       customer c3 = new customer("seri","penang");
    		System.out.println("name,address,discount");
           }}
    Try this
    ]
    Code:
    public class customer {
           	String name;
    	String address;
    	String discount;    
    public String getname()
    {return name;}
    public String getaddress()
    {return address;}
           customer() {}
    	 customer(String Name,String Address) {
    name=Name;
    address=Address}          }
    public class myclass
    {public static void main(String args[]) {
    	 customer c = new customer();
                   customer c1 = new customer("wan","ipoh");
                   customer c2 = new customer("nadia","kedah");
    	       customer c3 = new customer("seri","penang");
    		System.out.println("name"+c1.getname()+",address"+c1.getaddress());
           }}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •