5 Replies - 807 Views - Last Post: 03 April 2009 - 09:53 PM Rate Topic: -----

#1 release16  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-April 09

Make a program that converts a java source code file

Posted 03 April 2009 - 05:00 PM

Hi, guys! I am trying to create a program that converts a java source code file from next-line brace style to an end-of-line brace style source file. I have an outline on step by step instructions on how to do it, but on how to execute each step is what I do not understand and need help on. Any help and guidance would be greatly appreciated! Look forward to hearing from you. Thanks guys! Here is a link to the outline and what I have thus far which isn't much, haha:

http://www.pastie.org/pastes/436444

   

/*****************************************************************************
 * Reformatter.java
 *
 * This program converts a java source code file from next-line brace style
 * to end-of-line brace style source file.
 *
 *****************************************************************************/

// insert import packages below
import java.io.*;

// program class
public class Reformatter
{
  public static void main (String [] args) throws Exception
  {
	// open a Scanner object to read keyboard input
		   userStringEqualityTest()

	// ask the user for a filename
	   System.out.print("Please put in a filename: ");


	// read filename from user
		   System.out.print("Read filename from user: ");

	  // open the file for reading using the filename from the user

[b]Don't know how to open a file and name it:[/b]
	[b]// open a file for writing the newly formatted source code
	// use the same filename with ".backup" extension[/b]


		// create an emtpy string buffer
		StringBuilder buffer = new StringBuilder();

[b]Is this suppose to be a string to make a line? [/b]
	//as long as there are lines in the input file

	{
[b]
Is this suppose to be a string to make a line?[/b]
	   //read a line from the input file

[b]Not sure of the code for this one:[/b]
	   // trim the line

[b]Not sure what to do here:[/b]
	  // if the line read contains only an open brace

	  {

[b]Don't know how to do this one:[/b]
	  // append an open brace and a newline character to the string buffer

	  }

	  else
	  {
		// append the line just read in the string buffer

[b]Am I suppose to put this: StringBuilder buffer = new StringBuilder();?[/b]
		// insert a newline character in the string buffer

	  }

	}

[b]I think I know how to do this:[/b]
	// display the contents of the string buffer on the DOS window

[b]Don't know how to do this:[/b]
	// write the contents of the string buffer to a backup file

[b]Not sure about this either:[/b]
	// close both input and output files

  }

}




I pretty much need help or a quick overview of the whole thing, for all my other options have fallen through. But, I will try to pinpoint the harder parts which is most of it. Sorry for not knowing much, just having a hard time understanding the java life.

-^_^

This post has been edited by release16: 03 April 2009 - 07:18 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Make a program that converts a java source code file

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Make a program that converts a java source code file

Posted 03 April 2009 - 06:58 PM

Welcome!

Please post your code using the code tags:

:code:

Please describe the problem(s) you are having.
Was This Post Helpful? 0
  • +
  • -

#3 release16  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-April 09

Re: Make a program that converts a java source code file

Posted 03 April 2009 - 07:33 PM

View Postn8wxs, on 3 Apr, 2009 - 05:58 PM, said:

Welcome!

Please post your code using the code tags:

:code:

Please describe the problem(s) you are having.




Thanks for your reply, it is good to hear from someone. I hope you can help me in someway, sorry for my inexperience with this and not knowing much. Hope it's not too much. I put in my java code for you and tried to bold what I did not understand which was practically everything. Hope you can understand it. Please let me know. Thanks again!
Was This Post Helpful? 0
  • +
  • -

#4 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Make a program that converts a java source code file

Posted 03 April 2009 - 07:47 PM

See Introduction to Programming Using Java, Fifth Edition

and

The Java Tutorials
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,858
  • Joined: 06-March 08

Re: Make a program that converts a java source code file

Posted 03 April 2009 - 08:08 PM

View Postrelease16, on 3 Apr, 2009 - 06:33 PM, said:

.Hope you can understand it. Please let me know. Thanks again!


We understand that you want us to do your homework.

[rules][/rules]

Anyhow quick one on how to read a file:

Scanner scan = new Scanner(new File("FileToRead.java"));
while(scan.hasNext() {
   String str = scan.nextLine();
   ... your code here
}


Was This Post Helpful? 0
  • +
  • -

#6 release16  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-April 09

Re: Make a program that converts a java source code file

Posted 03 April 2009 - 09:53 PM

View Postpbl, on 3 Apr, 2009 - 07:08 PM, said:

View Postrelease16, on 3 Apr, 2009 - 06:33 PM, said:

.Hope you can understand it. Please let me know. Thanks again!


We understand that you want us to do your homework.

[rules][/rules]

Anyhow quick one on how to read a file:

Scanner scan = new Scanner(new File("FileToRead.java"));
while(scan.hasNext() {
   String str = scan.nextLine();
   ... your code here
}




Thank you for your reply. My intention was not for anyone on this site including you to do my assignment for me which I was hoping no one would get the wrong idea of and if worded that way, unintentional as said before. I just was hoping for a little lesson here and there, some guidance as I said before. When you don't understand, you just don't sometimes understand. But, I am sure that if I look over it more a light bulb will appear over my head. If I need further assistance after knowing more I may come back here. And thanks for the little tidbit on reading a file. Nice site. Chow!

This post has been edited by release16: 03 April 2009 - 09:55 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1