Results 1 to 3 of 3

Thread: use a class

  1. #1
    artemis01 is offline Member
    Join Date
    Apr 2011
    Posts
    1
    Rep Power
    0

    Default use a class

    Hello
    Im beginner to java.
    I made a simple class with customers and for every customer 3 sums to be seized,
    it puts me an error of incompatible type (line 17) when I try to read to the keyboard, I don't understand why.
    thank you
    Java Code:
    import java.util.Scanner;
    class Compte{
    	String Nom;
    	double Somme[];
    	}
    public class Module2_Exo1{
    	public static void main(String[]args){
    		Scanner sc = new Scanner(System.in); 
    		Compte[]tabCompte=new Compte[5];
    		Compte[]tabSomme=new Compte[3];
    		for (int i=0;i<tabCompte.length;i++){
    			tabCompte[i]=new Compte();
    			System.out.print("saisir nom  Client" +( i+1) + " : ");
    			tabCompte[i].Nom=sc.nextLine();
    		 	for (int j=0;j<tabSomme.length;j++){
    				tabSomme[j]=sc.nextDouble();
    				System.out.print("saisir Somme de " +(j+1) + " : ");
    			sc.nextLine();
    			}
    		}
    
    	}
    }

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Paste the exact error message please.

  3. #3
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default

    Compte[]tabSomme=new Compte[3];
    tabsome is a object of Compte class and there are two variavle.they are Nom and Sommy.
    What are you trying by this?
    tabSomme[j]=sc.nextDouble();
    In which variable this Double value will be assigned?
    Did you got it?

    Create an constructor on the Compte class which will take one Double parameter which will assign the value as you wish.

    Regards
    Ujjal
    Don't Forget to try yourself before asking others help.....
    Press REP, if you find their advices/solutions effective.

Similar Threads

  1. Replies: 0
    Last Post: 03-27-2011, 05:49 AM
  2. Replies: 5
    Last Post: 01-26-2011, 06:38 PM
  3. Replies: 8
    Last Post: 04-14-2010, 05:49 AM
  4. Replies: 7
    Last Post: 05-06-2009, 12:42 PM
  5. Replies: 8
    Last Post: 03-21-2009, 09:34 AM

Posting Permissions

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