Results 1 to 4 of 4
  1. #1
    zlloyd1 is offline Member
    Join Date
    Nov 2012
    Posts
    57
    Rep Power
    0

    Question FileOutputStream constructor issue

    The following program is complaining about my use of FileOutputStream, and I cannot understand why:
    Java Code:
    import java.io.*;
     import java.awt.*;
     import java.awt.event.*;
     import java.text.*;
     import javax.swing.*;
     import java.util.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    	 
                      	    public class MortgagePaymentCalc extends JFrame 
                                implements ActionListener {
    	         
    	        private FileOutputStream output;
    	 
    	        DecimalFormat calcPattern = new DecimalFormat("0.00");  //Makes it a little bit   
                       //      easier just in case a Deciaml is Entered
    	 
    	        JLabel loanAmountLabel = new JLabel("Loan Amount (Without $):");
    	        JTextField loanAmountText = new JTextField(10);
    	        JButton calculateButton = new JButton("Calculate Payment");
    	        JTextField paymentText = new JTextField(10);
    	        JLabel monthlyPaymentLabel = new JLabel("");
    	        JButton chooseButton = new JButton("Choose Term");
    	        JButton clearButton = new JButton("Clear");
    	        JButton quitButton = new JButton("Quit");
    	         
    	        // Creates a text box to display all the info
    	         
    	        JTextArea textArea = new JTextArea(30, 25);
    	        JScrollPane scrollPane = new JScrollPane(textArea,                                                    
                              JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,                                                       
                              JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    	 
    	        // Variable setting for interest rate and the length of loan
    	         
    	         
    	        String loanLength, interestRate, terms;
    	 
    	        public MortgagePaymentCalc() {
    	             
    	            super("McBride Financial Services Mortgage Calculator");
    	            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	 
    	            JPanel pane = new JPanel();
    	            FlowLayout fl = new FlowLayout(FlowLayout.LEFT);
    	            pane.setLayout(fl);
    	            pane.add(loanAmountLabel);
    	            pane.add(loanAmountText);
    	 
    	            //Should anyone be like me, this allows the Calculate button to be pushed by         
                                 //hitting "Enter"...
    	             
    	            getRootPane().setDefaultButton(calculateButton);
    	            pane.add(scrollPane);
    	            pane.add(calculateButton);
    	            pane.add(monthlyPaymentLabel);
    	            pane.add(paymentText);
    	            pane.add(clearButton);
    	            pane.add(quitButton);
    	            setContentPane(pane);
    	 
    	            //Gives Functionality to the buttons...
    	             
    	            calculateButton.addActionListener(this);
    	            clearButton.addActionListener(this);
    	            quitButton.addActionListener(this);
    	            loanAmountText.addActionListener(this);
    	            chooseButton.addActionListener(this);
    	        }
    	 
    	        public static void main(String args[]) {
    	 
    	            //Sets the Variables for the Frame (Size, Resizable, and what not)...
    	             
    	            JFrame aFrame = new MortgagePaymentCalc();
    	            aFrame.setTitle("McBride Financial Services Mortgage Calculator");
    	            aFrame.setSize(310,650);
    	            aFrame.setResizable(true);
    	            aFrame.setVisible(true);
    	        }
    	 
    	        public void actionPerformed(ActionEvent e) {
    	 
    	            //Identifies the "what to do" when the "Button" is Clicked...
    	             
    	            Object clickSource = e.getSource();
    	 
    	            // set variables when specific mortgage terms are selected (e.g. "7yr; 5.35pt",     
                                  //"15yr; 5.5pt", "30yr; 5.75pt")
    	             
    	            if (clickSource == chooseButton) {
                                           
                                // Gathers the Data from the Sequential File
                                             
                                output = new FileOutputStream(new FileOutputStream(terms)); //ERROR IS HERE????
                           
                        
    	 
    	                // Forces a choice
    	                 
    	                if (!terms.startsWith("Select")) {
    	 
    	                    // Gathers the loan length in years
    	                     
    	                    int yearIndex = terms.indexOf("years");
    	                    loanLength = terms.substring(0,yearIndex);
    	 
    	                    // Gathers the  interest rate
    	                     
    	                    int startPercentageIndex = terms.indexOf("; ");
    	                    int endPercentageIndex = terms.indexOf("%");
    	                    interestRate = terms.substring(startPercentageIndex + 2,                                
                                           endPercentageIndex);
    	                }
    	            }          
    	             
    	            //This runs the Calculation on the Formulae when asked to...
    	             
    	            if (clickSource == calculateButton) {
    	                 
    	                //clear the text area before each calculation
    	                textArea.setText("");
    	 
    	                //Reads what was Written
    	                 
    	                String loanAmount = loanAmountText.getText();
    	                String interestrate = interestRate;
    	                String years = loanLength;
    	 
    	                //The Formulae
    	                 
    	                double total = Double.parseDouble(loanAmount) * (((((Double.parseDouble       
                                (interestrate)) / 100) / 12) * (Math.pow(1 + (((Double.parseDouble                              
                                 (interestrate)) / 100) / 12), Integer.parseInt(years) * 12))) / ((Math.pow(1 +             
                               (((Double.parseDouble(interestrate)) / 100) / 12), Integer.parseInt(years) *              
                           12)) - 1));
    	 
    	                //Display for the Monthly Payment
    	                 
    	                paymentText.setText("$" + calcPattern.format(total));
    	                 
    	                //Calculates the monthly interest
    	                 
    	                  double monthlyInterest = Double.parseDouble(loanAmount) / (12 * 100);        
           
    	                double currentMonthlyInterest = Double.parseDouble(loanAmount) *                
                                       (Double.parseDouble(interestrate) / (12 * 100));
    	                double monthlyPayment = total - currentMonthlyInterest;
    	                double newBalance = Double.parseDouble(loanAmount) - monthlyPayment;
    	                int monthNumber = 1;
    	                textArea.append("Month" + "\tBalance" + "\tInterest\n");
    	 
    	                // Keeps looping until the formulae is at a 0 balance
    	                 
    	                while (newBalance > 0) {
    	 
    	                    // Displays the Month
    	                     
    	                    textArea.append(monthNumber + "\t" + calcPattern.format(newBalance) +   
                                         "\t" + calcPattern.format(currentMonthlyInterest) + "\n");
    	 
    	                    currentMonthlyInterest = newBalance * (Double.parseDouble(interestrate) 
                                           / (12 * 100));
    	                    monthlyPayment = total - currentMonthlyInterest;
    	                    newBalance = newBalance - monthlyPayment;
    	                    monthNumber++;
    	             
    	                    }
    	                 
    	            }
    	 
    	            //This gives the User the Choice to either Re-Enter the Variables or "Clear" it   
                                    //all out altogether.
    	             
    	            if (clickSource == clearButton) {
    	                loanAmountText.setText("");
    	                paymentText.setText("");
    	                loanAmountText.requestFocus();
    	    }
    	 
    	            //If you can't stand the Heat, get out of the Kithcen...That means you can Quit
    	             
    	            if (clickSource == quitButton) {
    	                System.exit(0);
    	  }
    	 }
    	}
    It is giving the following error:
    no suitable constructor found for FileOutputStream(FileOutputStream)
    constructor FileOutputStream.FileOutputStream(FileDescriptor) is not applicable
    (actual argument FileOutputStream cannot be converted to FileDescriptor by method invocation conversion)
    constructor FileOutputStream.FileOutputStream(File,boolean) is not applicable
    (actual and formal argument lists differ in length)
    constructor FileOutputStream.FileOutputStream(File) is not applicable
    (actual argument FileOutputStream cannot be converted to File by method invocation conversion)
    constructor FileOutputStream.FileOutputStream(String,boolean) is not applicable
    (actual and formal argument lists differ in length)
    constructor FileOutputStream.FileOutputStream(String) is not applicab...

    Can anyone tell me why PLEASE??

  2. #2
    kuriozal is offline Member
    Join Date
    Aug 2012
    Posts
    9
    Rep Power
    0

    Default Re: FileOutputStream constructor issue

    Java Code:
    output = new FileOutputStream(new FileOutputStream(terms)); //ERROR IS HERE????
    what do you think this code is doing? because I can't figure it out ;> You are making FileOutputStream from FileOutputStream from String, wtf? Is this String a filepath or something? If it is you can use just: new FileOutputStream(terms); I hope that you know it's a stream for WRITING to file, not for READING?

  3. #3
    zlloyd1 is offline Member
    Join Date
    Nov 2012
    Posts
    57
    Rep Power
    0

    Default Re: FileOutputStream constructor issue

    Quote Originally Posted by kuriozal View Post
    Java Code:
    output = new FileOutputStream(new FileOutputStream(terms)); //ERROR IS HERE????
    what do you think this code is doing? because I can't figure it out ;> You are making FileOutputStream from FileOutputStream from String, wtf? Is this String a filepath or something? If it is you can use just: new FileOutputStream(terms); I hope that you know it's a stream for WRITING to file, not for READING?
    Yes , it is supposed to write sequentially to a file. I just cannot figure out why it is saying no suitable constructor found for FileOutputStream??

  4. #4
    Estrella is offline Member
    Join Date
    Jan 2013
    Location
    Texas
    Posts
    16
    Rep Power
    0

    Default Re: FileOutputStream constructor issue

    Check the Java API to see what type of parameters FileOutputStream's constructor takes in. The line your referring to attempts to create a FileOutputStream object by taking in a FileOutputStream object, which doesn't really make sense.
    Last edited by Estrella; 02-01-2013 at 06:48 AM. Reason: typo

Similar Threads

  1. Replies: 7
    Last Post: 11-26-2011, 12:03 PM
  2. FileOutputStream to GIF
    By dewitrydan in forum New To Java
    Replies: 12
    Last Post: 10-11-2010, 08:12 AM
  3. Replies: 16
    Last Post: 07-08-2010, 10:13 PM
  4. FileOutputStream > int > FileInputStream
    By dudejonne in forum New To Java
    Replies: 11
    Last Post: 11-11-2009, 05:03 PM
  5. constructor issue
    By kuaimun in forum Advanced Java
    Replies: 2
    Last Post: 01-22-2009, 09:09 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •