qpMONKEYMIKEqp's Profile User Rating: -----

Reputation: -1 Dishonored
Group:
Members
Active Posts:
25 (0.04 per day)
Joined:
16-October 12
Profile Views:
215
Last Active:
User is offline Oct 09 2013 11:01 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   qpMONKEYMIKEqp has not set their status

Posts I've Made

  1. In Topic: C++ Operator<< Override inheritance

    Posted 9 Oct 2013

    I have figured it out now! With your help!

    I moved the operator<< into public and then my compiler was giving me some error about constants. So I took const out of the operator<< and changed it all from info.Variable to info.getVariable. This let me compile with no errors and get the product i was looking for.

    Once again thank you all for the help. I love that the people here give me hits to the correct answers instead of just taking my code fixing it and pasting it into the chat!

    My changed code is:

    Circle.h

    
    #ifndef Ch2HW_MichaelRauch_Circle_h
    #define Ch2HW_MichaelRauch_Circle_h
    
    #include <iostream>
    #include "Point.h"
    
    using namespace std;
    
    class Circle: public Point
    {
    public:
        
        friend ostream& operator<< (ostream&, const Circle&);
        friend ostream& operator<< (ostream&, const Point&);
        //Construtor
        Circle(double x, double y, double rad)
        {
            radius = rad; //Store the radius of the circle
            setX(x); //Stores the xCoordinate
            setY(y); //Stores the yCoordinate
        }
        
        double getRadius()
        {
            return radius;
        }
        
    private:
        double radius; //Variable to define radius
    };
    
    ostream& operator<<(ostream& osObject, Circle& info)
    {
        osObject << "(";                        
        osObject << info.getX();
        osObject << ",";                        
        osObject << info.getY();
        osObject << ",";                        
        osObject << info.getRadius();
        osObject << ")";                        
        
        return osObject;    //return osObject which contains "(x,y)"
    }
    
    
    #endif
    
    
    


    Point.h

    
    #ifndef Ch2HW_MichaelRauch_Point_h
    #define Ch2HW_MichaelRauch_Point_h
    
    #include <iostream>
    
    using namespace std;
    
    class Point
    {
    public:
        //Overload << operator
        friend ostream& operator<< (ostream&, const Point&);
        
            //Construtor
        Point(double x = 0, double y = 0)
        {
            xCoordinate = x; //Store the X value of the coordinate
            yCoordinate = y; //Store the Y value of the coordinate
        }
            
            //Function to set the y coordinate
        void setY(double y = 0)
        {
            yCoordinate = y; //Store new y value of the coordinate
        }
        
            //Function to set the x coordinate
        void setX(double x = 0)
        {
            xCoordinate = x; //Store new x value of the coordinate
        }
        
            //Function to get the y coordinate
        double getY()
        {
            return yCoordinate; //return the y value of the coordinate
        }
        
            //Function to get the x coordinate
        double getX()
        {
            return xCoordinate; //return the x value of the coordinate
        }
        
    private:
        double xCoordinate; //Variable to define x coordinate
        double yCoordinate; //Variable to define y coordinate
    };
    
        //Make << output "(x,y)"
    ostream& operator<<(ostream& osObject, const Point& coordinate)
    {
        osObject << "(";                        //Current output "("
        osObject << coordinate.xCoordinate;     //Current output "(x"
        osObject << ",";                        //Current output "(x,"
        osObject << coordinate.yCoordinate;     //Current output "(x,y"
        osObject << ")";                        //Current output "(x,y)"
        
        return osObject;    //return osObject which contains "(x,y)"
    }
    
    #endif
    
    
    
  2. In Topic: C++ Operator<< Override inheritance

    Posted 9 Oct 2013

    Where should i look or what can i try to get the output i want? I tried just creating another operator<< override in circle.h but if i do that i can not the the x and yCoordinate from the Point.h?

    I can get the radius from the class Circle. but i can not get the x and yCoordinates form the Point class. But the Circle class can get x and y from Point class....

    i tried using << Point:xCoordinate and << getX(). Nothing seems to be going my way.
  3. In Topic: Lottery winner

    Posted 15 Dec 2012

    Here is what i think you are trying to do.

    What i changed was inside your for loop you made it to where it chose if the number was right or wrong. The first number is going to be right or wrong. So then it pushes it out of the loop

    so what i did was only ask if its right inside the for loop. but outside ask if the value 'win' has been changed. If it was not changed in the for loop then you did not win.

    int main(void)
    {
        int playerNumbers [10] = { 77777, 13579, 62483, 26792, 93121,
            79422, 85647, 26791, 33445, 55555};
        int i = 0;
        int win = 0;
        int results = 0;
        int lott = 0;
        printf("Enter the winning number: ");
        fflush(stdout);
        scanf("%d", &lott);
        if (lott > 0 || lott < 99999)
        {
            for(i=0;i<10;i++)
            {
                if(lott==playerNumbers[i])
                {
                    printf(" is a winner!!! :");
                    fflush(stdout);
                    win = 1;
                }
            }
            if (win == 0)
            {
                printf("Sorry you did not win");
                fflush(stdout);
            }
        }//end if
        else
        {
            printf("You have entered a wrong number  ");
            fflush(stdout);
            return 0;
        }
        return 0;
    }//end main
    
    
  4. In Topic: JAVA - GUI metric and temp conversion program - help with output!

    Posted 15 Dec 2012

    It is complete

    This is the criteria that i was working off of. Does it look like i implemented everything that was needed so far i think i did but a second pair of eyes always helps?

    1. Start with the Conversion class. Task 1 is to extend this class using inheritance and create a subclass called 'TempConversion'. The new class needs methods for converting Fahrenheit to Celsius and Celsius to Fahrenheit. You will use the parent class' roundoff() method to insure the results returned are two decimal places.

    2. Task 2 is to create a GUI. The first textbox is Fahrenheit and the second is Celsius. When input is entered into the first box, the F to C formula is used and the results placed in the second textbox. If the input value is in the second textbox, the C to F formula is used and the result is placed in the first textbox. Your GUI will include functioning menus and a HELP menu that displays a dialog box that lists the name of the program and the programmers name.

    3. Finally for Task 3, You will use Exception Handling to insure the input is correct before attempting to convert the input.

    Here is my final code

    TestConverter.java
    
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.border.*;
    
    public class TestConverter extends JFrame implements ActionListener 
    {//TestConverter
        private JLabel title = new JLabel("Temperature Converter" ); //label for title
        private JPanel titlePanel = new JPanel( ); //panel for title
        private JLabel fLabel = new JLabel( "Fahrenheit: " ); //label for fahrenheit input
        private JTextField fField = new JTextField( 10 ); //textbox for fahrenheit input
        private JPanel fPanel = new JPanel( ); //panel for fahrenheit label+textbox
        private JPanel cPanel = new JPanel( ); //panel for celsius label+textbox
        private JTextField cField = new JTextField( 10 ); //textbox for celsius input
        private JLabel cLabel = new JLabel( "Celsius: " ); //label for celsius input
        private JPanel converterPanel = new JPanel( ); //panel for fpanel+cpanel
        private JButton convertBtn = new JButton("Convert"); //button to execute conversion
        private JButton clearBtn = new JButton("Clear"); //button to clear all textboxs
        private JPanel buttonPanel = new JPanel(); //panel for convertBtn+clearBtn
        private JMenuBar menuBar = new JMenuBar();
    
        public TestConverter( ) { //constructor
        	super("Temperature Converter"); //text above menuBar
            createTitlePanel(); //constructor for createTitlePanel
            getContentPane().add(titlePanel, BorderLayout.NORTH); //organize titlePanel to the top
            createConverterPanel( ); //constructor for createConverterPanel
            getContentPane().add(converterPanel, BorderLayout.WEST); //organize converterPanel to the left
            createButtonPanel(); //constructor for createButtonPanel
            getContentPane().add(buttonPanel, BorderLayout.EAST); //organize buttonPanel to the right
            createMenuBar(); //constructor for createMenuBar
        }//end of constructor
        
        private void createTitlePanel( ) 
        {//createTitlePanel
            titlePanel.add( title ); //add title to titlePanel
        }//end of createTitlePanel
        
        private void createfPanel( ) 
        {//createfPanel
        	fPanel.setLayout(new GridLayout(1,2)); //create layout for fPanel
            fPanel.add( fLabel  ); //add fLabel to fPanel
            fPanel.add( fField ); //add fField to fPanel
        }//end of createfPanel
    
        private void createcPanel( ) 
        {//createcPanel
        	cPanel.setLayout(new GridLayout(1,2)); //create layout for cPanel
            cPanel.add( cLabel ); //add cLabel to cPanel
            cPanel.add( cField ); //add cField to cPanel
        }//end of createcPanel
    
        private void createConverterPanel( ) 
        {//createConverterPnel
        	converterPanel.setLayout(new GridLayout(2,1)); //create layout for converterPanel
            createfPanel( ); //constructor for createfPanel
            converterPanel.add( fPanel ); //add fPanel to converterPanel
            createcPanel( ); //constructor for createcPanel
            converterPanel.add(cPanel); //add cPanel to converterPanel
       }//end of createConverterPanel
        
        private void createButtonPanel( )
        {//createButtonPanel
            buttonPanel.setLayout(new GridLayout(2,1)); //create layout for buttonPanel
            buttonPanel.add(convertBtn); //add convertBtn to buttonPanel
            buttonPanel.add(clearBtn); //add clearBtn to buttonPanel
            convertBtn.addActionListener(this); //add actionListener to converterBtn
            clearBtn.addActionListener(this); //add actionListener to clearBtn
        }//end of createButtonPanel
        
        private void createMenuBar( )
        {//createMenuBar
        	class exitAction implements ActionListener
            {//exitAction
           	 	public void actionPerformed (ActionEvent ae)
           	 	{//actionPerformed
           	 		System.exit(0); //exit app
           	 	}//end of actionPerformed
            }//end of exitAction
        	
        	class aboutAction implements ActionListener
        	{//aboutAction
        		public void actionPerformed (ActionEvent ae)
        		{//actionPerformed
        			JOptionPane.showMessageDialog(null, //popup dialog box with app information
        					"Author: Michael Rauch\nTitle: Temperature\nLast Edit: 12/14/12", //message contents
        					"About", //title
        					JOptionPane.INFORMATION_MESSAGE); //type of message icon
        		}//end of actionPerformed
        	}//end of aboutAction
        	
             setJMenuBar(menuBar); // create menuBar
             JMenu file = new JMenu("File"); //create file menu
             menuBar.add(file); //add file
             JMenuItem exit = new JMenuItem("Exit"); //create exit menuItem
             file.add(exit); //add exit
             exit.addActionListener(new exitAction()); //add actionListener to exit
             
             JMenu help = new JMenu("Help"); //create help menu
             menuBar.add(help); //add help
             JMenuItem about = new JMenuItem("About"); //create about menuItem
             help.add(about); //add about
             about.addActionListener(new aboutAction()); //add actionListener to about
        }//end of createMenuBar
     
        public void actionPerformed(ActionEvent ae) 
        {//actionPerformed
    		if ( ae.getSource( ) == convertBtn ) 
    		{ //if convertBtn is pressed
    			double d = 0.0; //create double d
    			int error = 0; //create int error
    			if ( cField.getText().isEmpty() && fField.getText().isEmpty() )
    	    	{//if cField & fField are empty
        			JOptionPane.showMessageDialog(null, //popup dialog box with error
        					"Both fields are empty, try again.", //contents
        					"Input Error", //title
        					JOptionPane.ERROR_MESSAGE); //icon type
    	    	}//end if
    	    	else if ( cField.getText().isEmpty() != true && fField.getText().isEmpty() != true )
    	    	{//else if cField & fField are NOT empty
    	    		JOptionPane.showMessageDialog(null, //popup dialog box with error
    	    				"Both fields are full, try again.", //contents
    	    				"Input Error", //title
    	    				JOptionPane.ERROR_MESSAGE); //icon type
    	    		fField.setText(""); //clear fField
    		        cField.setText(""); //clear fField
    	    	}//end else if
    	    	else if( cField.getText().isEmpty() && fField.getText().isEmpty() != true )
    		   	{//else if cField is empty & fField is NOT empty
    		   		try
    		   		{//begin try
    		   			d = Double.parseDouble( fField.getText( )); //converts fFields text to a double and sets it = to d
    		   		}//end of try
    		   		catch (Exception e)
    		   		{//catch if error
    		   			d = 0; //set d = to 0
    		    		JOptionPane.showMessageDialog(null, //popup dialog box with error
    		    				"Fahrenheit input is not a number, try again.", //contents
    		    				"Input Error", //title
    		    				JOptionPane.ERROR_MESSAGE); //icon type
    		    		error = 1; //set error = to 1 (to show an error has happened)
    		    		fField.setText(""); //clear fField
    		    	}//end catch
    		    	if (error == 0)
    		    	{// if there were no errors
    			   		d = TempConversion.f2c( d ); //send the value of d to TempConversion.f2c, then set d to its return value
    			   		cField.setText( Double.toString( d ) ); //set the cField to the text value of d
    		   		}//end if
    		   		error = 0; //reset error counter
    		   	}//end else if
    		   	else if( cField.getText().isEmpty() != true && fField.getText().isEmpty() )
    		   	{ //else if cField is NOT empty & fField is empty
    		   		try
    		   		{//begin try
    		    		d = Double.parseDouble( cField.getText( )); //convert cFields text to double and set it = to d
    		    	}//end of try
    		    	catch (Exception e)
    		    	{//catch if error
    		   			d = 0; //set d = to 0
    		   			JOptionPane.showMessageDialog(null, //popup dialog box with error
    		   					"Celsius input is not a number, try again.", //contents
    		   					"Input Error", //title
    		   					JOptionPane.ERROR_MESSAGE); //icon type
    		   			error = 1; //set error = to 1 (to show an error has happened)
    	    			cField.setText(""); //clear cField
    	    		}//end catch
    	    		if (error == 0)
    	    		{//if there were no errors
    		    		d = TempConversion.c2f( d ); //send the value of d to TempConversion.c2f, then set d to its return value
    		    		fField.setText( Double.toString( d ) ); //set the cField to the text value of d
    	    		}//end if
    	    		error = 0; //reset error counter
    	    	}//end else if
    	    }//end if
    	    else if ( ae.getSource( ) == clearBtn )
    	    {//if clearBtn is pressed
    	        fField.setText(""); //clear fField
    	        cField.setText(""); //clear cField
    	    }// end if
        } //end actionPerformed method
    
    
        public static void main( String[ ] args ) 
        {//main
            final int FRAMEWIDTH = 400; //set FRAMEWIDTH
            final int FRAMEHEIGHT = 130; //set FRAMEHEIGHT
            TestConverter tc = new TestConverter( ); //create new TestConverter
            tc.setSize( FRAMEWIDTH, FRAMEHEIGHT ); //set size of tc
            tc.pack(); //compress tc to remove white space
            tc.setVisible( true ); //set tc to be visible
        }//end of main method
    }//end of class
    
    
    
    
    


    TempConversion
    
    public class TempConversion extends Conversion 
    {//TempConversion
    	public static double f2c( double f ) 
    	{//f2c
            return roundOff((f - 32.) * 5./9.); //convert f to c then send to roundOff then return the value
        } //end f2c method
    
        public static double c2f( double c )
        {//c2f
            return roundOff(c * 9./5. + 32.); //convert c to f then send to roundOff then return the value
        } //end c2f method
    }//end of TempConversion
    
    
    


    Conversion.java
    public class Conversion 
    {//conversion
        public static double m2k( double m ) 
        {//m2k
            return roundOff( m*1.6 ); //convert m to k then send the value to roundOff then return the value
        } //end m2k method
    
        public static double k2m( double k ) 
        {//k2m
            return roundOff( k*0.62 ); //convert k to m then send the value to roundOff then return the value
        } //end k2m method
    
        protected static double roundOff( double d ) 
        {//roundOff
            d = d * 100; //multiply by 100
        	d = Math.round( d ); //round to 0.00
            d = d / 100; //divide by 100
            return d; //return rounded off value
        } // end of roundOff method
    } //end of class
    
    
    
  5. In Topic: JAVA - GUI metric and temp conversion program - help with output!

    Posted 15 Dec 2012

    I now have a menu bar and i changed the GUI around. I removed the radio buttons and now it works without them.

    Next i will be creating exception handlers so that when any errors occur like if both text fields are full or both are empty or if its not a number then it will throw a pop up to the user stating what the error was.

    current code (Only changes from here on out are to the metricConverter)


    metricConverter.java
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.border.*;
    
    public class MetricConverter extends JFrame implements ActionListener {
    	
        private JLabel title = new JLabel("Temperature Converter" );
        private JPanel titlePanel = new JPanel( );
        private JLabel fLabel = new JLabel( "Fahrenheit: " );
        private JTextField fField = new JTextField( 10 );
        private JPanel fPanel = new JPanel( );
        private JPanel cPanel = new JPanel( );
        private JTextField cField = new JTextField( 10 );
        private JLabel cLabel = new JLabel( "Celsius: " );
        private JPanel converterPanel = new JPanel( );
        private JButton convertBtn = new JButton("Convert");
        private JButton clearBtn = new JButton("Clear");
        private JPanel buttonPanel = new JPanel();
    
        public MetricConverter( ) {
        	super("Metric Converter");
            createTitlePanel(title);
            getContentPane().add(titlePanel, BorderLayout.NORTH);
            createConverterPanel( );
            getContentPane().add(converterPanel, BorderLayout.CENTER);
            createButtonPanel();
            getContentPane().add(buttonPanel, BorderLayout.EAST);
            createMenuBar();
        }//end of constructor
        
        private void createTitlePanel( JLabel t ) {
            titlePanel.add( t );
        }
        
        private void createInputPanel( ) {
        	fPanel.setLayout(new GridLayout(1,2));
            fPanel.add( fLabel  );
            fPanel.add( fField );
        }
    
        private void createResultPanel( ) {
        	cPanel.setLayout(new GridLayout(1,2));
            cPanel.add( cLabel );
            cPanel.add( cField );
        }
    
        private void createConverterPanel( ) {
        	converterPanel.setLayout(new GridLayout(2,1));
            createInputPanel( );
            converterPanel.add( fPanel );
            createResultPanel( );
            converterPanel.add(cPanel);
       }
        
        private void createButtonPanel( ){
            buttonPanel.setLayout(new GridLayout(2,1));
            buttonPanel.add(convertBtn);
            buttonPanel.add(clearBtn);
            convertBtn.addActionListener(this);
            clearBtn.addActionListener(this);
        }
        
        private void createMenuBar( )
        {
        	class exitAction implements ActionListener
            {
           	 	public void actionPerformed (ActionEvent ae)
           	 	{
           	 		System.exit(0);
           	 	}
            }
        	
        	class aboutAction implements ActionListener
        	{
        		public void actionPerformed (ActionEvent ae)
        		{
        			JOptionPane.showMessageDialog(null,"Author: Michael Rauch\nTitle: Temperature\nLast Edit: 12/14/12","About",JOptionPane.PLAIN_MESSAGE);
        		}
        	}
        	
        	JMenuBar menuBar = new JMenuBar();
             setJMenuBar(menuBar);
             JMenu file = new JMenu("File");
             menuBar.add(file);
             JMenuItem exit = new JMenuItem("Exit");
             file.add(exit);
             exit.addActionListener(new exitAction());
             
             JMenu help = new JMenu("Help");
             menuBar.add(help);
             JMenuItem about = new JMenuItem("About");
             help.add(about);
             about.addActionListener(new aboutAction());
        }
     
        public void actionPerformed(ActionEvent ae) {
    		if ( ae.getSource( ) == convertBtn )  {
    			System.out.println(fField.getText() + "\n" + cField.getText());
    			double d = 0.0;
    	    	//f = Double.parseDouble( fField.getText( ) );
    	    	//c = Double.parseDouble( cField.getText( ) );
    	    	if ( cField.getText().isEmpty() && fField.getText().isEmpty() )
    	    	{
    	    		System.out.println("Error: emply fields");
    	    		fField.setText("");
    		        cField.setText("");
    	    	}
    	    	if( cField.getText().isEmpty() && fField.getText().isEmpty() != true )
    	    	{
    	    		d = Double.parseDouble( fField.getText( ));
    	    		d = TempConversion.f2c( d );
    	    		cField.setText( Double.toString( d ) );
    	    	}
    	    	else if( cField.getText().isEmpty() != true && fField.getText().isEmpty() )
    	    	{
    	    		d = Double.parseDouble( cField.getText( ));
    	    		d = TempConversion.c2f( d );
    	    		fField.setText( Double.toString( d ) );
    	    	}
    	    	else if ( cField.getText().isEmpty() != true && fField.getText().isEmpty() != true )
    	    	{
    	    		System.out.println("Error: full fields");
    	    		fField.setText("");
    		        cField.setText("");
    	    	}
    	    }
    	    else if ( ae.getSource( ) == clearBtn ){
    	        fField.setText("");
    	        cField.setText("");
    	   }
        } //end actionPerformed method
    
    
        public static void main( String[ ] args ) {
            final int FRAMEWIDTH = 400;  
            final int FRAMEHEIGHT = 130;
            MetricConverter mc = new MetricConverter( ); 
            mc.setSize( FRAMEWIDTH, FRAMEHEIGHT );
            //mc.pack();
            mc.setVisible( true );
        }//end of main method
    }//end of class
    
    
    
    

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

qpMONKEYMIKEqp hasn't added any friends yet.

Comments

qpMONKEYMIKEqp has no profile comments yet. Why not say hello?