Results 1 to 5 of 5
Thread: VeryLong Integer.. help
- 12-14-2007, 03:06 AM #1
Member
- Join Date
- Dec 2007
- Posts
- 21
- Rep Power
- 0
VeryLong Integer.. help
Hi guys,
please, help me))) :confused:
I am trying to create a VEreyLong Integer class.. I am using ArrayList..
but I have some questions..
this is my code (just the beginning)
so, in readln method, I am trying to read a string from console, then write each char (which is digit) to ArrayList, then I have to claim that that created ArrayList is my class VeryLong integer, right? But in this case, ArrayList functions will not be available for me.. So do I need to make my class VeryLong smth likeJava Code:package VeryLong; import java.util.*; public class VeryLong{ public VeryLong(ArrayList<Integer> a){ ArrayList<Integer> verylong = new ArrayList<Integer>(); System.out.println("number is created"); }; public ArrayList<Integer> Readln(){ int i=0, tempint=0; ArrayList<Integer> verylong = new ArrayList<Integer>(); Scanner in = new Scanner(System.in); String str; str=in.next(); while (Character.isDigit(str.charAt(i))) { tempint = Integer.parseInt( Character.toString( str.charAt(i) ) ); verylong.add(tempint); i++; }; return verylong; } }
VeryLong extends ArrayList???? But in this case, how do I block other ArrayList methods, which I don't need..
I know, that it sounds really confusing.. but please, help me!!!))) :confused: :confused: :confused:
- 12-14-2007, 03:16 PM #2
I think what you want to do is make the ArrayList a field in your class.
this way the array just lives in the class. It is private so other classes cannot call ArrayList methods on it directly. If you need use of any of the ArrayLists just set up a public method in your class that calls them.Java Code:package VeryLong; import java.util.*; public class VeryLong{ private ArrayList<Integer> longInt; public VeryLong(ArrayList<Integer> a){ this.longInt = a; System.out.println("number is created"); }; public ArrayList<Integer> Readln(){ int i=0, tempint=0; Scanner in = new Scanner(System.in); String str; str=in.next(); while (Character.isDigit(str.charAt(i))) { tempint = Integer.parseInt( Character.toString( str.charAt(i) ) ); this.longInt.add(tempint); i++; }; return this.longInt; } }
- 12-14-2007, 03:30 PM #3
Member
- Join Date
- Dec 2007
- Posts
- 21
- Rep Power
- 0
em.. So, in that way, longInt will be my very long integer itself.. right? Thank you so much.! I still don't understand it completely, but I think I am on the right way.)))
- 12-14-2007, 09:28 PM #4
Member
- Join Date
- Dec 2007
- Posts
- 21
- Rep Power
- 0
I am sorry for the stupid questions, but how can I test it?
This is what I have:
:mad: :mad: :mad: but I cannot do this, because Readln is non-static, but I also cannot call constructor,because I need to read inforamtion from the console first.. any ideas?Java Code:import VeryLong.VeryLong; import java.util.*; class main{ public static void main(String[] args){ VeryLong.Readln(); } }
Thanks a lot!!!
- 12-14-2007, 09:48 PM #5
You need to create a VeryLong object.
You'll probably want to add another constructor to the very long class that looks like this.Java Code:VeryLong vl = new VeryLong(**Some array list here**);
This will create an empty VeryLong instead of copying a passed ArrayList. To use this constructor:Java Code:pucbli VeryLong(){ this.longInt = new ArrayList<Integer>(); }
After the object is created, you can call it methods.Java Code:VeryLong vl = new VeryLong();
Java Code:vl.Readln() //by the way, it is a good idea to start your method names with lower case letters
Similar Threads
-
Breaking down an integer
By Emily in forum New To JavaReplies: 1Last Post: 03-06-2008, 06:39 PM -
Create a VeryLong class that will store an integer of arbitrary length.
By hey in forum New To JavaReplies: 2Last Post: 12-12-2007, 05:01 PM -
Short/Integer
By mew in forum New To JavaReplies: 3Last Post: 12-06-2007, 09:28 PM -
Integer vs int
By bugger in forum New To JavaReplies: 1Last Post: 11-14-2007, 09:13 PM -
Help with Integer in java
By susan in forum New To JavaReplies: 1Last Post: 07-14-2007, 05:25 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks