Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Having Difficulties With a Multi Thread Code... Help?

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Having Difficulties With a Multi Thread Code... Help?

    There is an issue with part of my program, I get two errors.. And I have no idea how to fix it. Here is what I have for the code:

    class Customer{
    private String name;
    private int age;
    public Customer(String n, int a)throws CreateException{
    if(0<a<125){
    Name=n;
    Age=a;
    throw new CreateException(&#8220; Age limit is 0 to 125 &#8221;);
    }
     
    }
     
    public void print(){
    System.out.println(" The Name:" +Name);
    System.out.println(" The Age:" +Age);
    }
    }

    public class CustomerDemo{
    public static void main(String args[]){
    Customer cust[]=new Customer[2];
    for(int i=0;i<2;i++){
    try{
    c[0]=new Customer(&#8220;Ram&#8221;,60);
    c[0].print();
    }catch(CreateException e){
    System.out.println(&#8220; Complete &#8221;);
    System.out.println(e.getMessage());
    }
    }
    }
    }


  2. #2
    Junior Member
    Join Date
    Apr 2011
    Location
    Pune, India
    Posts
    11
    My Mood
    Cool
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Having Difficulties With a Multi Thread Code... Help?

    Hi... I think you have to work hard on your basics..

    1) if(0<a<125) condition is wrong. It could be if((0<a)&&(a<125))
    2) Your declared variables are
    private String name;
    private int age;
    And you are using
    Name=n;
    Age=a;
    This is again basic, declared name of variable are different then assigned one.

    3) In customer demo class
    c[0]=new Customer(“Ram”,60);
    c[0].print();
    Where is the array of c, i think it should be cust.
    ---------------------------------------------------
    package com.java.main;
     
    class Customer {
    	private String name;
    	private int age;
     
    	public Customer(String n, int a) throws Exception {
    		if ((0 < a) && (a < 125)) {
    			name = n;
    			age = a;
    			throw new Exception("Age limit is 0 to 125");
    		}
     
    	}
     
    	public void print() {
    		System.out.println(" The Name:" + name);
    		System.out.println(" The Age:" + age);
    	}
    }
    ----------------------------------------------------
    package com.java.main;
     
    public class CustomerDemo {
    	public static void main(String args[]) {
    		Customer cust[] = new Customer[2];
    		for (int i = 0; i < 2; i++) {
    			try {
    				cust[0] = new Customer("Ram", 60);
    				cust[0].print();
    			} catch (Exception e) {
    				System.out.println("Complete");
    				System.out.println(e.getMessage());
    			}
    		}
    	}
    }
    Hardik Jadhav

Similar Threads

  1. [SOLVED] Assigning Values to Multi Array
    By dredjohn in forum Collections and Generics
    Replies: 3
    Last Post: April 18th, 2011, 07:43 PM
  2. Help on 2D Multi Table Array
    By clevel211 in forum Object Oriented Programming
    Replies: 1
    Last Post: February 1st, 2011, 04:28 AM
  3. Converting Code to Multi Thread
    By cmill_xc in forum Threads
    Replies: 1
    Last Post: December 6th, 2010, 12:39 PM
  4. Multi-dimension ArrayList example
    By adeola in forum Collections and Generics
    Replies: 3
    Last Post: March 26th, 2010, 03:23 AM
  5. Multi-dimension ArrayList example
    By helloworld922 in forum Java Programming Tutorials
    Replies: 1
    Last Post: February 3rd, 2010, 11:01 AM