Guest_imported
New member
- Jan 1, 1970
- 0
Dear Helpers,
I am using IBM Visual Age for JAVA and my teacher gave me a project and these are the tasks:
(WORD PROCESSING)
1) ASk the user for line length, center on SCreen
2) Justify Text
3) Search/Replace
4) Dictionary
1 I am done, 2 I am trapped, 3 How to to??, 4 I need to find a least 100 words to put it in the program. I know that I have to use a data file to check the spellings.
Also I am using HOLT SOFTWARE
so here is my program so far.
/**
* This type was created in VisualAge.
*/
import hsa.*;
import java.awt.*;
import java.io.*;
class Final_Project
{
static Console c;
}
public static void main(String args[])
{
c=new Console();
String word;
int num=num();
word=text();
int length=length(num,word);
String formatted_string =justifyString(num,word);
c.println(formatted_string);
}
public static int num()
{
int num;
c.println("Enter number of characters you want on each line"
num=c.readInt();
return num;
}
public static String text()
{
String word;
//c.println("Enter text"
word=("This is JAVA program from IBM's Visual Age, I hate doing this but I have to, it's so confusing. I have to do this justify today and get search done too. Then I can move to the dictionart tomorrow"
//word= c.readLine();
return word;
}
public static int length(int num,String word)
{
int count=4;
int flag=0;
int count2=0;
int start=0;
int length;
String blank=" ";
c.clear();
int c1=1;
length= word.length();
while (flag=ɢ
{
c.setCursor(c1,(80-num)/2);
if (length>(num+start))
{
while (blank.indexOf(word.charAt(num+start-count2))==-1)
{
count2+=1;
}
}
else if (length<(num+start))
{
count2=(num+start)-length;
flag=1;
}
for (int x=0;x<num-count2;x++)
{
c.print(word.substring(x+start,x+1+start));
}
c.println (""
start+=num-count2+1;
count2=0;
c1++;
}
return length;
}
public static String justifyString (int num,String text)
{
StringBuffer newword = new StringBuffer(text);
int lastspace = -1;
int linestart = 0;
int i = 0;
while (i < newword.length())
{
if ( newword.charAt(i) == ' ' )
lastspace = i;
if ( newword.charAt(i) == '\n')
{
lastspace = -1;
linestart = i+1;
c.print(" "
}
if (i > linestart + num - 1 )
{
if (lastspace != -1)
{
newword.setCharAt(lastspace,'\n');
linestart = lastspace+1;
lastspace = -1;
c.print(" "
}
else
{
newword.insert(i,'\n');
linestart = i+1;
}
}
i++;
}
return newword.toString();
}
Can anyone help to see what I did wrong;
also can anyone give me a sample solution too (Code or just Hints)
I also need advice and examples on REPLACE/Search words in the paragraph.
Lastly I need a hint on DICTIONARY part too.
Also, she gave me 4 tasks but if I do more I can have extra Marks
I think on these to be added in my program.
1) Menu
2) Color, image
3) Some animation
4) Align=center,left,right,justify
What else???
Thank you even if you read this far.
Once again Thank you.
Thx
Eric
I am using IBM Visual Age for JAVA and my teacher gave me a project and these are the tasks:
(WORD PROCESSING)
1) ASk the user for line length, center on SCreen
2) Justify Text
3) Search/Replace
4) Dictionary
1 I am done, 2 I am trapped, 3 How to to??, 4 I need to find a least 100 words to put it in the program. I know that I have to use a data file to check the spellings.
Also I am using HOLT SOFTWARE
so here is my program so far.
/**
* This type was created in VisualAge.
*/
import hsa.*;
import java.awt.*;
import java.io.*;
class Final_Project
{
static Console c;
}
public static void main(String args[])
{
c=new Console();
String word;
int num=num();
word=text();
int length=length(num,word);
String formatted_string =justifyString(num,word);
c.println(formatted_string);
}
public static int num()
{
int num;
c.println("Enter number of characters you want on each line"
num=c.readInt();
return num;
}
public static String text()
{
String word;
//c.println("Enter text"
word=("This is JAVA program from IBM's Visual Age, I hate doing this but I have to, it's so confusing. I have to do this justify today and get search done too. Then I can move to the dictionart tomorrow"
//word= c.readLine();
return word;
}
public static int length(int num,String word)
{
int count=4;
int flag=0;
int count2=0;
int start=0;
int length;
String blank=" ";
c.clear();
int c1=1;
length= word.length();
while (flag=ɢ
{
c.setCursor(c1,(80-num)/2);
if (length>(num+start))
{
while (blank.indexOf(word.charAt(num+start-count2))==-1)
{
count2+=1;
}
}
else if (length<(num+start))
{
count2=(num+start)-length;
flag=1;
}
for (int x=0;x<num-count2;x++)
{
c.print(word.substring(x+start,x+1+start));
}
c.println (""
start+=num-count2+1;
count2=0;
c1++;
}
return length;
}
public static String justifyString (int num,String text)
{
StringBuffer newword = new StringBuffer(text);
int lastspace = -1;
int linestart = 0;
int i = 0;
while (i < newword.length())
{
if ( newword.charAt(i) == ' ' )
lastspace = i;
if ( newword.charAt(i) == '\n')
{
lastspace = -1;
linestart = i+1;
c.print(" "
}
if (i > linestart + num - 1 )
{
if (lastspace != -1)
{
newword.setCharAt(lastspace,'\n');
linestart = lastspace+1;
lastspace = -1;
c.print(" "
}
else
{
newword.insert(i,'\n');
linestart = i+1;
}
}
i++;
}
return newword.toString();
}
Can anyone help to see what I did wrong;
also can anyone give me a sample solution too (Code or just Hints)
I also need advice and examples on REPLACE/Search words in the paragraph.
Lastly I need a hint on DICTIONARY part too.
Also, she gave me 4 tasks but if I do more I can have extra Marks
I think on these to be added in my program.
1) Menu
2) Color, image
3) Some animation
4) Align=center,left,right,justify
What else???
Thank you even if you read this far.
Once again Thank you.
Thx
Eric