what to do with table?

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 673 Views - Last Post: 14 May 2009 - 04:50 AM Rate Topic: -----

#1 alexandra1_1_1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 03-May 09

what to do with table?

Posted 09 May 2009 - 07:30 AM

I HAVE A TABLE WHICH CONCLUDE NAMES AND NUMBERS....I MAKE THE TABLE STRING
BUT NOW I WANT USE ONLY THE NUMBERS...FOR EXAMBLE ADD THE....WHAT I MUST DOING;
I MAKE CASTING BUT NOTHING....
Is This A Good Question/Topic? 0
  • +

Replies To: what to do with table?

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2733
  • View blog
  • Posts: 11,509
  • Joined: 20-September 08

Re: what to do with table?

Posted 09 May 2009 - 08:00 AM

Please post code (in the correct tags) and PLEASE TAKE OFF YOUR CAPS LOCK
Was This Post Helpful? 0
  • +
  • -

#3 alexandra1_1_1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 03-May 09

Re: what to do with table?

Posted 09 May 2009 - 08:04 AM

View Postalexandra1_1_1, on 9 May, 2009 - 07:03 AM, said:

class Client {
   String   code, age, years,balance, loan;

	Client(String code,String   age,String   years,String  balance, String  loan) {
		this.code = code;
		this.age = age;
		this.years = years;
		this.balance = balance;
		this.loan = loan;
	}

	public static void main(String[] arg) {

		Client[] client = new Client[1000];
		int nbClient = 0;
		String inputDocument = "bank.csv";
		try {
			FileInputStream is = new FileInputStream(inputDocument);
			Reader iD = new InputStreamReader(is);


			BufferedReader buf = new BufferedReader(iD);
			String inputLine;
			while ((inputLine = buf.readLine()) != null) {
				String [] lineParts = inputLine.split(";");
				client[nbClient] = new Client(lineParts[0],lineParts[1],lineParts[2],lineParts[3],lineParts[4]);
				nbClient++;
				if(nbClient == 1000) {
					System.out.printf("Oups... not enough room in Client table");
					break;
				}

			}
		}
		 catch(IOException e) {
					 System.out.println("Problem reading file. Exception " + e);
		}

		System.out.println("The " + nbClient + " code and age are:");
		for(int i = 0; i < nbClient; i++)
		   { double mhniaiadosixwris=dosixwris(client[i].balance);}
	}
	public static double dosixwris(String num1){
		double mhniaiadosi;double k;
		k=(double)(num1);
		mhniaiadosi=k/12;
		return mhniaiadosi;}

}


*Edited to remove duplicated code

This post has been edited by pbl: 09 May 2009 - 08:58 PM

Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2733
  • View blog
  • Posts: 11,509
  • Joined: 20-September 08

Re: what to do with table?

Posted 09 May 2009 - 08:09 AM

That didn't quite work - you probably didn't close the code tag correctly. What's the problem again with your code?

I see you've corrected it. This

Quote

double mhniaiadosixwris=dosixwris(client[i].balance);


should be

double mhniaiadosixwris=Double.parseDouble(dosixwris(client[i].balance));




but it would probably better to use double in the Client class in the first place
Was This Post Helpful? 0
  • +
  • -

#5 alexandra1_1_1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 03-May 09

Re: what to do with table?

Posted 09 May 2009 - 08:21 AM

when you say in the first place
you mean here;
class Client {
   String   code, age, years,balance, loan;

	Client(String code,String   age,String   years,String  balance, String  loan) {
		this.code = code;
		this.age = age;
		this.years = years;
		this.balance = balance;
		this.loan = loan;
	}


Was This Post Helpful? 0
  • +
  • -

#6 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2733
  • View blog
  • Posts: 11,509
  • Joined: 20-September 08

Re: what to do with table?

Posted 09 May 2009 - 08:25 AM

Yes. Probably the only thing that should be of type String there is 'code'
Was This Post Helpful? 0
  • +
  • -

#7 alexandra1_1_1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 03-May 09

Re: what to do with table?

Posted 09 May 2009 - 08:30 AM

ok!thank you...you help me very much!i don't know if i can do this....
because i think all must be same in the table!
Was This Post Helpful? 0
  • +
  • -

#8 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2733
  • View blog
  • Posts: 11,509
  • Joined: 20-September 08

Re: what to do with table?

Posted 09 May 2009 - 08:32 AM

You would still read/write String from/to .csv
Was This Post Helpful? 0
  • +
  • -

#9 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2733
  • View blog
  • Posts: 11,509
  • Joined: 20-September 08

Re: what to do with table?

Posted 09 May 2009 - 08:40 AM

When you change types, you could keep a convenience ctor such as:

    public Client(String code, String age, String years, String balance, String loan) {
        this.code = code;
        this.age = Integer.parseInt(age);
        this.years = Integer.parseInt(years);
        this.balance = Double.parseDouble(balance);
        this.loan = Double.parseDouble(loan);
    }   


Was This Post Helpful? 1
  • +
  • -

#10 alexandra1_1_1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 03-May 09

Re: what to do with table?

Posted 09 May 2009 - 09:00 AM

now code is
import java.io.*;

 public Client(String code, String age, String years, String balance, String loan)
{ this.code = code;
 this.age = Integer.parseInt(age);
 this.years = Integer.parseInt(years);
 this.balance = Double.parseDouble(balance);
 this.loan = Double.parseDouble(loan);	}

	public static void main(String[] arg) {

		Client[] client = new Client[1000];
		int nbClient = 0;
		String inputDocument = "bank.csv";
		try {
			FileInputStream is = new FileInputStream(inputDocument);
			Reader iD = new InputStreamReader(is);


			BufferedReader buf = new BufferedReader(iD);
			String inputLine;
			while ((inputLine = buf.readLine()) != null) {
				String [] lineParts = inputLine.split(";");
				client[nbClient] = new Client(lineParts[0],lineParts[1],lineParts[2],lineParts[3],lineParts[4]);
				nbClient++;
				if(nbClient == 1000) {
					System.out.printf("Oups... not enough room in Client table");
					break;
				}

			}
		}
		 catch(IOException e) {
					 System.out.println("Problem reading file. Exception " + e);
		}

		System.out.println("The " + nbClient + " code and age are:");
		for(int i = 0; i < nbClient; i++)
		   { double mhniaiadosixwris=dosixwris(client[i].balance);}
	}
	public static double dosixwris(Double  num1){
		double mhniaiadosi;
		mhniaiadosi=num1/12;
		return mhniaiadosi;}

}


but compiler finds erros...
Was This Post Helpful? 0
  • +
  • -

#11 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2733
  • View blog
  • Posts: 11,509
  • Joined: 20-September 08

Re: what to do with table?

Posted 09 May 2009 - 09:07 AM

You've not defined the instance variables
Was This Post Helpful? 0
  • +
  • -

#12 alexandra1_1_1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 03-May 09

Re: what to do with table?

Posted 09 May 2009 - 04:22 PM

i have not defined the instance variables?
i don't understand what to do....can you explain me?
Was This Post Helpful? 0
  • +
  • -

#13 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2733
  • View blog
  • Posts: 11,509
  • Joined: 20-September 08

Re: what to do with table?

Posted 10 May 2009 - 04:33 AM

It should begin

public class Client {
    private String code;
    private int age;
    private int years;
    private double balance;
    private double loan;



Was This Post Helpful? 0
  • +
  • -

#14 alexandra1_1_1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 03-May 09

Re: what to do with table?

Posted 12 May 2009 - 05:57 AM

import java.io.*;

 class Client  {  private String code;	private int age;	private int years;	private double balance;	private double loan;
 {this.code = code;
 this.age = Integer.parseInt(age);
 this.years = Integer.parseInt(years);
 this.balance = Double.parseDouble(balance);
 this.loan = Double.parseDouble(loan);}

	public static void main(String[] arg) {

		Client[] client = new Client[1000];
		int nbClient = 0;
		String inputDocument = "bank.csv";
		try {
			FileInputStream is = new FileInputStream(inputDocument);
			Reader iD = new InputStreamReader(is);


			BufferedReader buf = new BufferedReader(iD);
			String inputLine;
			while ((inputLine = buf.readLine()) != null) {
				String [] lineParts = inputLine.split(";");
				client[nbClient] = new Client(lineParts[0],lineParts[1],lineParts[2],lineParts[3],lineParts[4]);
				nbClient++;
				if(nbClient == 1000) {
					System.out.printf("Oups... not enough room in Client table");
					break;
				}

			}
		}
		 catch(IOException e) {
					 System.out.println("Problem reading file. Exception " + e);
		}

 
		for(int i = 0; i < nbClient; i++)
		   { double mhniaiadosixwris=dosixwris(client[i].balance);}
	}
	public static double dosixwris(Double num1){
		double mhniaiadosi;
		mhniaiadosi=num1/12;
		return mhniaiadosi;}

}



i make this but the compiler make errors again which is the error?....i don't find this and i want write and other methods until friday!!!can you help me with this to continue???please
Was This Post Helpful? 0
  • +
  • -

#15 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2733
  • View blog
  • Posts: 11,509
  • Joined: 20-September 08

Re: what to do with table?

Posted 12 May 2009 - 06:51 AM

See below
import java.io.*;


class Client {
    private String code;
    private int age;
    private int years;
    private double balance;
    private double loan;

    public Client(String code, String age, String years, String balance, String loan) {
	this.code = code;
	this.age = Integer.parseInt(age);
	this.years = Integer.parseInt(years);
	this.balance = Double.parseDouble(balance);
	this.loan = Double.parseDouble(loan);
    }

    public static void main(String[] arg) {
	Client[] client = new Client[1000];
	int nbClient = 0;
	String inputDocument = "bank.csv";

	try {
	    FileInputStream is = new FileInputStream(inputDocument);
	    Reader iD = new InputStreamReader(is);

	    BufferedReader buf = new BufferedReader(iD);
	    String inputLine;

	    while ((inputLine = buf.readLine()) != null) {
		String[] lineParts = inputLine.split(";");
		client[nbClient] = new Client(lineParts[0], lineParts[1],
			lineParts[2], lineParts[3], lineParts[4]);
		nbClient++;

		if (nbClient == 1000) {
		    System.out.printf("Oups... not enough room in Client table");

		    break;
		}
	    }
	} catch (IOException e) {
	    System.out.println("Problem reading file. Exception " + e);
	}

	for (int i = 0; i < nbClient; i++) {
	    double mhniaiadosixwris = dosixwris(client[i].balance);
	}
    }

    public static double dosixwris(Double num1) {
	double mhniaiadosi;
	mhniaiadosi = num1 / 12;

	return mhniaiadosi;
    }
}



Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2