User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 455,962 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,602 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1365 | Replies: 5 | Solved
Reply
Join Date: Nov 2007
Posts: 9
Reputation: chetah is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
chetah chetah is offline Offline
Newbie Poster

LinkList- Java

  #1  
Nov 16th, 2007
Home Work Problem.
I understand what the program is suppose to do, but I do not understand how to implement it using Link List.

Please help me to understand the problem.

Write a program to perform ariththmetic with integers of unlimited size. You must read data from the input file, input.txt and send output to the file, output.txt.

Each data line has the following format:

number1 operator number 2, where the operator can be one of +, - or *. The operator is preceeded and followed by one or more spaces.

For + and -, Number1 and Number 2 are to be treated as large integers and each must be stored in a link list. Output the given expression and on the next line print the answer. For example,
22222233333333 + 4444455555 =

For *, Number1 is a large integer to be stored in a linked list. Number2 is a small integer whcih can be stored in an int variable. Output the given expression ans on the next line, print the answer for example,
23222222222222 * 7 =
223232323223333
the last line of data contains a zero.

Please help me to under the algorithm in solving this problem
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 19
Solved Threads: 200
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: LinkList- Java

  #2  
Nov 17th, 2007
well, it says right there what you need to do. Couldn't be much clearer than what your teacher already told you.
If you don't understand it, tell your teacher and ask him to help you.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote  
Join Date: Feb 2006
Posts: 1,508
Reputation: masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light 
Rep Power: 10
Solved Threads: 136
masijade's Avatar
masijade masijade is offline Offline
Posting Virtuoso

Re: LinkList- Java

  #3  
Nov 17th, 2007
Although all you really need to do is look at his moniker to find out what he wants here.

"chetah" when sounded out is the current "slang" sound for cheater. The "street" sound for "er" is, now, almost always "ah".
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: Nov 2007
Posts: 9
Reputation: chetah is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
chetah chetah is offline Offline
Newbie Poster

Re: LinkList- Java

  #4  
Nov 17th, 2007
I am don't think you are quite correct, but good luck all the same.
Peace!
Reply With Quote  
Join Date: Nov 2007
Posts: 9
Reputation: chetah is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
chetah chetah is offline Offline
Newbie Poster

Re: LinkList- Java

  #5  
Nov 18th, 2007
Here is the code I have been working on, help with corrections
Class Node {
Int num;
Node next;
}

Public Class Number {
Public static void main (String [] args) {
Scanner in = new Scanner (new File Reader (“input.txt”)
PrinterWriter out = new PrintWriter (new FileWriter (“output.txt”)

Node top, last, np = null;
top = null;

// Load the input file into the link list

int n = in.nextInt()
While (n! =0) {
np = new node (num)

if (top = = null) {
top = np;
else {
last.next = np;
num = in.nextInt ()
}
}

Curr = top
While (curr !=Null)
String sign = in.next()
If (sign. equals (‘+’) {
Int sum = prev.next +curr.next
Curr = curr.next
//write to output file
Elseif{
If (sign. equals (‘-’) {
Int difference = prer.next -curr.next
Curr = curr.next
//write to output file

}
Else{

If (sign. equals (‘*’) {
Int product = curr.num *curr.next
Curr = curr.next
//write to output file

}
Reply With Quote  
Join Date: Nov 2007
Posts: 9
Reputation: chetah is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
chetah chetah is offline Offline
Newbie Poster

Re: LinkList- Java

  #6  
Nov 24th, 2007
Did not help much. When I try to read from the input.txt, the in.next() returns only the first number, it does not read the '+" for the number following it.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 9:00 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC