Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Creating Methods for Input/Output Files

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Thanked 0 Times in 0 Posts

    Default Creating Methods for Input/Output Files

    Basically, I had to find various properties of a cylinder and make separate methods to do each of these. This is no problem and that runs fine. But every time I try to make a method to do input and output I get several errors and it will not run.
    So right now I just have the input and output files being read inside the main method , but i need separate methods for the input and output files.
    I need help creating these methods for input/output.

    Thank You

    Here's the code I have:

    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    public class Shapes {
        static Scanner input = new Scanner(System.in);
        public static void main(String[] args) throws FileNotFoundException {
    	Scanner inFile = new Scanner (new FileReader("dimensions.txt"));
    	PrintWriter output = new PrintWriter("C:\\Users\\user\\Desktop\\shapes.txt");
        double x = inFile.nextDouble();
    	double y = inFile.nextDouble();
    	double height, radius, base, lateral, surface, volume, outputs;
    	radius = x;
    	height = y;
    	base = baseArea(radius);
    	lateral = lateralArea(radius, height);
    	surface = surfaceArea(lateral, base);
    	volume = cylinderVolume(base, height);
    // this is just to check the calculations without having to open the output evertime
    	output.println(base + "      " + lateral + "      " + surface + "      " + volume);
    // calculates the base area. "a" is the radius and "b" is the value for base area.
    public static double baseArea(double a){
    	double b = Math.PI * a * a;
    	return b;
    public static double lateralArea(double r, double h){
    	double cir = Math.PI * 2 * r;
    	double lat = cir * h;
    	return lat;
    public static double surfaceArea (double la, double ba){
    	double sur = la + ba + ba;
    	return sur;
    public static double cylinderVolume (double base, double h){
    	double vol = base * h;
    	return vol;

  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    United Kingdom
    My Mood
    Thanked 294 Times in 227 Posts
    Blog Entries

    Default Re: Creating Methods for Input/Output Files

    What will be the content of dimensions.txt?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Junior Member
    Join Date
    Nov 2010
    Thanked 0 Times in 0 Posts

    Default Re: Creating Methods for Input/Output Files

    Oh I'm sorry. I just chose two values to test it:

Similar Threads

  1. [SOLVED] T_T [hellllppppp] Input/Output
    By bontet in forum File I/O & Other I/O Streams
    Replies: 9
    Last Post: October 29th, 2010, 11:32 AM
  2. Input/Output file help
    By Plural in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 25th, 2010, 08:34 PM
  3. Input/Output file help
    By Plural in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 23rd, 2010, 06:26 PM
  4. Methods in java class files are not recognized.
    By Girish in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 18th, 2010, 05:44 AM
  5. [SOLVED] java me how to: input - math operation - output
    By Lifer in forum Java ME (Mobile Edition)
    Replies: 3
    Last Post: April 7th, 2010, 05:36 PM