473,581 Members | 2,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help! empty output file

1 New Member
Hello, I have source code that builds correctly, however, after the program terminates the output file produced is empty.

Here is my source code:

import java.io.*;
import java.util.Scann er;
public class project
{
public static void main( String args[] )
{
try {
FileInputStream fis = new FileInputStream ("Foobar.java") ;
DataInputStream dis = new DataInputStream (fis);
BufferedReader br = new BufferedReader( new InputStreamRead er(dis));


String line = "";
String se = "";
String var="";
String t="";
Scanner in = new Scanner( System.in );
int input;


// Create a new file output stream
// connected to "myfile.txt "
PrintWriter pw = new PrintWriter ( new BufferedWriter( new FileWriter("Foo bar.java")));

// declare a file output object
// declare a print stre p = new PrintStream( out );

// Connect print stream to the output stream

System.out.prin tln( "Choose the correct option to create appropriate method(s) for each variable found\\n");
System.out.prin tln("****Menu** **");
System.out.prin tln( "(1) Set");
System.out.prin tln( "(2) Get");
System.out.prin tln( "(3) Both");
System.out.prin tln( "(4) Skip");

input = in.nextInt();
// Here BufferedInputSt ream is added for fast reading.
// dis.available() returns 0 if the file does not have more lines.
while ((line = br.readLine()) != null) {

// this statement reads the line from the file and print it to
// the console.
line = br.readLine();
line.trim();
pw.write( line );
if( line.indexOf("p rivate") != -1 )
{
String [] newLine = line.split(" ");


t = newLine[7];

var = newLine[8];
t = t.replace( ';', ' ' );
var = var.replace( ';', ' ' );
switch( input )
{

case 1:

se+=prepareSet( t, var );
se+="\n";

break;

case 2:
se+=prepareGet( t, var );
se+="\n";

break;

case 3:
se+=prepareSet( t, var );
se+=prepareGet( t, var );
se+="\n";

break;
case 4:


break;
default:
break;

}
}

}//end of while
if( input == 1 )
System.out.prin tln("Set Methods Prepared....... Thank you!");
if( input == 2 )
System.out.prin tln("Get Methods Prepared....... Thank you!");
if( input == 3 )
System.out.prin tln("Both Set and Get Methods Prepared....... Thank you!");
if( input == 4 )
System.out.prin tln("Nothing was Changed......Th ank you!");
pw.println(se);

fis.close();
br.close();
dis.close();
pw.close();
// dispose all the resources after using them.
}//END OF TRY

catch (FileNotFoundEx ception e) {
e.printStackTra ce();
} catch (IOException e) {
e.printStackTra ce();
}
}
public static String prepareSet( String ti, String v )
{
String s = "public "+ ti+" set"+v + "(" + ti + " " + v + ")\n" +
"{\n\tthis. " +v+ "=" +v+";\n}\n";

return s;

}
public static String prepareGet(Stri ng ti, String v )
{
String s = "Public void get"+v + "()\n" +
"{\nreturn this." +v + ";\n}\n";
return s;
}
}


HERE IS THE ASSIGNMENT (KIND OF LONG)

Due Date: 12/05/07 5:00PM (-10% per day late)



Objective:

Create a program to insert public accesors (setXX and getXX methods) into a java class.



Your program will accept a .java source file as a command line argument, and the output should be inserted into the file. The output should be written to the same file and file name as the input file.



Sample Input: (Foobar.java)



public class Foobar

{

private int _counter;

private String _firstName;

private Date birthDate;

public static void main(String[] args)

{

System.out.prin tln("Hello World!" + FirstName);

}

}



Processing:



You program should:

1. Open the input file
2. Locate the private class variables
3. Determine the variable types and names
4. Prompt the user to create Set/Get/Both/Skip methods for each variable found
5. Insert all the generated methods and write the output file.



* You solution should recognize all valid variable declarations. Example:

private int _someVar;

private MyDate $gradYear;

* Assume that the input file is syntactically correct and compiles properly

* Assume 1 variable declaration per line of code. (no declarations like “private int a,b,c;” will be given)

* Properly handle errors and exceptions. For example, missing input file, invalid user input, etc.





Corresponding Output (Foobar.java)



public class Foobar

{

private int _counter;

private String _firstName;

private Date birthDate;



/* Public Accessors */

public void setCounter(int val) {

_counter = val;

}

public int getCounter() {

return _counter;

}

public void setBirthDate(Da te val) {

birthDate = val;

}

public Date getBirthDate() {

return birthDate;

}



public static void main(String[] args)

{

System.out.prin tln("Hello World!" + FirstName);

}

}





Sample Run:



C:\oop\project> javac AccesGen.java

C:\oop\project> java AccesGen Foobar.java



Loading Foobar.java.



Found private int _counter.

Generate Set, Get, Both, None [S/G/B/N] ? B



Found private int _firstName.

Generate Set, Get, Both, None [S/G/B/N] ? N



Found private int birthDate.

Generate Set, Get, Both, None [S/G/B/N] ? B



Changes written to Foobar.java

Done

C:\oop\project>
Dec 2 '07 #1
0 1799

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2193
by: python-help-bounces | last post by:
Your message for python-help@python.org, the Python programming language assistance line, has been received and is being delivered. This automated response is sent to those of you new to python-help, to point out a few resources that can help with answering your own questions, or improve the chances of getting a useful answer from the...
4
3338
by: Sarir Khamsi | last post by:
Is there a way to get help the way you get it from the Python interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the module cmd.Cmd? I know how to add commands and help text to cmd.Cmd but I would also like to get the man-page-like help for classes and functions. Does anyone know how to do that? Thanks. Sarir
6
3002
by: d.warnermurray | last post by:
I am doing a project for school that involves creating help files for a html authoring tool. If you could help me with answers to some questions it would really help. 1. What tasks do you expect an html authoring tool to help you accomplish? 2. What do you expect from online help for a html authoring tool? 3. What audience do you think...
5
2981
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig <<<<<<<<<<<<<<CODE>>>>>>>>>>>>>>>> <html>
0
568
by: tbatwork828 | last post by:
If you were like me trying to figure out how to launch context sensitive help topic by the context id, here is the link: http://weblogs.asp.net/kencox/archive/2004/09/12/228349.aspx and if link doesn't work, basically here is the article: An Exploration Into Launching Context-Sensitive HTML Help with Topic IDs in VB.NET I spent this...
2
2539
by: John Baker | last post by:
I find it highly annoying that MS Access tries to go online when I want to look at the help files. Is there a way to configure it so it just looks at my local helpfiles when I hit F1?
9
2240
by: JJ | last post by:
Do you all use HTML help workshop to create your help system. I am finding it quite clumsy to use. Mayeb because I am not used to using it. Do any of you use any other techniques to create help for your progs? Whats the current popular approach to creating help? I am only wanting a straight help file accessible from a menu - no context...
8
3213
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both including search the internet for help, but the help is worthless. Any ideas?
10
3347
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably the worst I ever seen. I almost cannot find anything I need, including things I
1
6120
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve default property of object Label. Click for more:...
0
7792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8149
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8175
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6553
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5674
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3827
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1403
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1138
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.