Results 1 to 10 of 10
Like Tree1Likes
  • 1 Post By jbarke12

Thread: Main form (?)

  1. #1
    Eskimo is offline Member
    Join Date
    May 2013
    Posts
    4
    Rep Power
    0

    Default Main form (?)

    Error main form when execute .class whit CMD
    Java Code:
    	import java.util.*;
    
    class f extends Object{
    	public static void main(String[] args) {
    
    	class Polinomio extends Object
    	{
    	
    		private double [] Coefficienti;
    
    		public Polinomio () {}
    
    		public Polinomio (int size) {
    			Coefficienti = new double [size];
    		}
    
    		public Polinomio (double [] _Coefficienti) {
    			Coefficienti = _Coefficienti;
    		}
    
    		// Il grado di un polinomio  dato dalla dimensione del polinomio meno 1
    		int grado () { return Coefficienti.length - 1; }
    
    		boolean equals(Polinomio altroPolinomio) {
    			return Arrays.equals(Coefficienti,altroPolinomio.Coefficienti);
    		}
    
    		void somma(Polinomio altroPolinomio) {
    
    			if ( Coefficienti.length >= altroPolinomio.Coefficienti.length ) {
    				for ( int i = 0; i < altroPolinomio.Coefficienti.length; ++i ) {
    					Coefficienti[i] +=
    						altroPolinomio.Coefficienti[i];
    				}
    			} else {
    				double [] nuoviCoefficienti = new double[
    					altroPolinomio.Coefficienti.length
    				];
    				int i = 0;
    				for ( ; i < Coefficienti.length; ++i )
    					nuoviCoefficienti[i] =
    						Coefficienti[i] + altroPolinomio.Coefficienti[i];
    				for ( ; i < altroPolinomio.Coefficienti.length; ++i )
    					nuoviCoefficienti[i] =
    						altroPolinomio.Coefficienti[i];
    				Coefficienti = nuoviCoefficienti;
    			}
    		}
    
    		void trim() {
    			int i = Coefficienti.length;
    			while ( i > 0 && Coefficienti[i-1] == 0 ) i--;
    			if ( i != Coefficienti.length ) {
    
    				double [] nuoviCoefficienti = new double[i];
    				while ( i > 0 ) {
    					--i;
    					nuoviCoefficienti[i] = Coefficienti[i];
    				}
    				Coefficienti = nuoviCoefficienti;
    			}
    		}
    
    		void sottrai(Polinomio altroPolinomio) {
    			if ( Coefficienti.length >= altroPolinomio.Coefficienti.length ) {
    				int i = 0;
    				while ( i < altroPolinomio.Coefficienti.length ) {
    					Coefficienti[i] -=
    						altroPolinomio.Coefficienti[i];
    					++i;
    				}
    				trim();
    
    			} else {
    				double [] nuoviCoefficienti = new double[
    					altroPolinomio.Coefficienti.length
    				];
    				int i = 0;
    				for ( ; i < Coefficienti.length; ++i )
    					nuoviCoefficienti[i] =
    						Coefficienti[i] - altroPolinomio.Coefficienti[i];
    				for ( ; i < altroPolinomio.Coefficienti.length; ++i )
    					nuoviCoefficienti[i] =
    						- altroPolinomio.Coefficienti[i];
    				Coefficienti = nuoviCoefficienti;
    			}
    		}
    
    		void moltiplica(double costante) {
    			for ( int i = 0; i < Coefficienti.length; ++i ) {
    				Coefficienti[i] *= costante;
    			}
    		}
    
    		void moltiplica(Polinomio Moltiplicatore) {
    			// Il grado del polinomio prodotto  dato
    			// dalla somma dei gradi dei polinomi di partenza
    			double [] nuoviCoefficienti = new double[
    				Coefficienti.length  +
    				Moltiplicatore.Coefficienti.length - 1
    			];
    			for ( int c1 = 0; c1 < Coefficienti.length; ++c1 )
    				for ( int c2 = 0; c2 < Moltiplicatore.Coefficienti.length; ++c2 )
    					nuoviCoefficienti[c1+c2] +=
    						(Coefficienti[c1] * Moltiplicatore.Coefficienti[c2]);
    			Coefficienti = nuoviCoefficienti;
    		}
    
    		void dividi(Polinomio Divisore, Polinomio Resto) {
    			// Il grado del polinomio quoziente  dato
    			// dalla differenza dei gradi dei polinomi di partenza
    			if ( Coefficienti.length >= Divisore.Coefficienti.length ) {
    				int new_length =
    					Coefficienti.length - Divisore.Coefficienti.length + 1;
    				double [] nuoviCoefficienti = new double[new_length];
    
    				int new_c = new_length;
    				int c;
    				while ( new_c > 0 ) {
    					--new_c;
    					c = Divisore.Coefficienti.length - 1;
    
    					nuoviCoefficienti[new_c] =
    						Coefficienti[new_c + c] / Divisore.Coefficienti[c];
    					Coefficienti[new_c + c] = 0;
    					while ( c > 0 ) {
    						--c;
    						Coefficienti[new_c + c] +=
    							-(nuoviCoefficienti[new_c] * Divisore.Coefficienti[c]);
    					}
    				}
    				// Resto = new Polinomio (Coefficienti); NO ERRORE
    				Resto.Coefficienti = Coefficienti;
    				Resto.trim();
    				Coefficienti = nuoviCoefficienti;
    				trim();
    
    			} else {
    				Coefficienti = null;
    			}
    		}
    
    		void dividi(double costante) {
    			moltiplica(1/costante);
    		}
    
    		public String toString() {
    			String s = "[";
    			int i = Coefficienti.length;
    			while ( i > 0 )	{
    				--i;
    				s += (new Double(Coefficienti[i])).toString();
    				if ( i != 0 ) s += " ; ";
    			}
    			s += "]";
    			return s;
    		
    		}
    
    	}}
    }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,518
    Blog Entries
    7
    Rep Power
    20

    Default Re: Main form (?)

    It would be nice if you told us what the error was; or do you want us to guess?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Eskimo is offline Member
    Join Date
    May 2013
    Posts
    4
    Rep Power
    0

    Default Re: Main form (?)

    Error: Could not find or load main class C:\Users\...\Desktop\f.class

  4. #4
    jbarke12 is online now Member
    Join Date
    May 2013
    Location
    Charleston, South Carolina USA
    Posts
    82
    Rep Power
    0

    Default Re: Main form (?)

    Right now you have defined an inner class with your main method which can't be done. There are two ways to correct your code:
    1. I would create two separate classes for the code you have up there. In the first class I would define my main method. The second I would create a cut and past your Polonomio class into. I would also take away the extends Object. Classes already extend Object by default.
    2. You can create an inner class with class f, however you need to place the Polonomio class in the right place.

    I would suggest doing my first suggestion.
    Eskimo likes this.

  5. #5
    Eskimo is offline Member
    Join Date
    May 2013
    Posts
    4
    Rep Power
    0

    Default Re: Main form (?)

    Can you give me the project for Eclipse? Please...
    Quote Originally Posted by jbarke12 View Post
    Right now you have defined an inner class with your main method which can't be done. There are two ways to correct your code:
    1. I would create two separate classes for the code you have up there. In the first class I would define my main method. The second I would create a cut and past your Polonomio class into. I would also take away the extends Object. Classes already extend Object by default.
    2. You can create an inner class with class f, however you need to place the Polonomio class in the right place.

    I would suggest doing my first suggestion.

  6. #6
    jbarke12 is online now Member
    Join Date
    May 2013
    Location
    Charleston, South Carolina USA
    Posts
    82
    Rep Power
    0

    Default Re: Main form (?)

    I haven't done your project. I gave you the instructions to fix your error. If you have other issues or questions let me know. This is a learning website. We work through the problem together.

  7. #7
    monkeyjr97 is offline Senior Member
    Join Date
    Nov 2012
    Posts
    258
    Rep Power
    2

    Default Re: Main form (?)

    You dont need to extend Object by the way, everything extends object by default

    in order to do the step 2 suggested above just say:

    in your main:

    Polinomio p = new Polinomio();

    then just call the methods you want in order:

    p.method1();
    p.method2();
    etc etc.

  8. #8
    Eskimo is offline Member
    Join Date
    May 2013
    Posts
    4
    Rep Power
    0

    Default Re: Main form (?)

    Can you paste the code for the first class?
    Quote Originally Posted by jbarke12 View Post
    I haven't done your project. I gave you the instructions to fix your error. If you have other issues or questions let me know. This is a learning website. We work through the problem together.

  9. #9
    monkeyjr97 is offline Senior Member
    Join Date
    Nov 2012
    Posts
    258
    Rep Power
    2

    Default Re: Main form (?)

    you have all the code you need, just take the class out the main method and make it a new Class, then reference that Class in the main method. This is really basic java, if we gave you the answer you would struggle at every other stage in java. The main is where the application begins, it doesn't mean everything has to be in the main.

  10. #10
    jbarke12 is online now Member
    Join Date
    May 2013
    Location
    Charleston, South Carolina USA
    Posts
    82
    Rep Power
    0

Similar Threads

  1. Replies: 0
    Last Post: 01-09-2013, 07:12 PM
  2. Replies: 1
    Last Post: 06-05-2012, 04:31 PM
  3. Replies: 1
    Last Post: 03-22-2010, 09:03 AM
  4. Replies: 0
    Last Post: 10-31-2009, 09:24 AM
  5. Replies: 10
    Last Post: 08-12-2009, 04:02 PM

Posting Permissions

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