printwriter - I keep only getting these compiling answers in 3 methods. JAVA -


please ignore sloppy coding. i'm pretty new java , trying project school. can't find causing error

decrossdiscipline.java:455: error: unreported exception filenotfoundexception; must caught or declared thrown          printwriter outputfile = new printwriter(filename);                                   ^ decrossdiscipline.java:533: error: unreported exception filenotfoundexception; must caught or declared thrown          printwriter outputfile = new printwriter(filename);                                   ^ decrossdiscipline.java:623: error: unreported exception filenotfoundexception; must caught or declared thrown          printwriter outputfile = new printwriter(filename);                                   ^ 3 errors 

this program getting errors in. please help. feel need pair of eyes spot problem me. import java.util.scanner; import java.io.*;

public class decrossdiscipline {       public static void main(string[] args) throws ioexception       {       scanner keyboard = new scanner(system.in);        int deselection;       int method;       int method2;       int method3;       blanklines();        system.out.println("\tdifferential equation cross discipline project");        system.out.println();        demenu();       deselection = keyboard.nextint();        if (deselection<1)          {             system.out.println();             system.out.println("that not choice. please try again.\n");             demenu();             deselection = keyboard.nextint();            }        if (deselection>3)          {             system.out.println();             system.out.println("that not choice. please try again.\n");             demenu();             deselection = keyboard.nextint();            }         if (deselection==1)          {menu1();           method=keyboard.nextint();           if (method<1)           {              system.out.println();             system.out.println("not valid choice!");             menu1();             method=keyboard.nextint();            }            if (method>2)           {              system.out.println();             system.out.println("not valid choice!");             menu1();             method=keyboard.nextint();            }             if (method==1)            {rungekutta1();            }            if (method==2)            {euler1();            }           }       if (deselection==2)          {menu2();           method2=keyboard.nextint();            if (method2<1)           {              system.out.println();             system.out.println("not valid choice!");             menu2();             method2=keyboard.nextint();            }            if (method2>2)           {              system.out.println();             system.out.println("not valid choice!");             menu2();             method2=keyboard.nextint();            }            if (method2==1)            {rungekutta2();            }            if (method2==2)            {euler2();            }            }        if (deselection==3)          {menu3();           method3=keyboard.nextint();           if (method3<1)           {              system.out.println();             system.out.println("not valid choice!");             menu3();             method3=keyboard.nextint();            }            if (method3>2)           {              system.out.println();             system.out.println("not valid choice!");             menu3();             method3=keyboard.nextint();            }             if (method3==1)            {rungekutta3();            }            if (method3==2)            {euler3();            }            }             }        public static void blanklines()       {          (int l=0; l<11; l++)          {             system.out.println();            }        }        public static void demenu()       {          system.out.println("1. y'=(x+1)^2\n" +                            "2. y'=3(x^2)*(y-4)^2\n" +                           "3. y'=3(x^2)*(y-2)^2");          system.out.print("please enter number of \ndifferential equation want use:  ");         }        public static void menu1()       {           system.out.print("\n1. runge kutta\n" +                            "2. euler\n");          system.out.print("please enter number of \nmethod want use:  ");                          }        public static void menu2()       {          system.out.print("\n1. runge kutta\n" +                            "2. euler\n");          system.out.print("please enter number of \nmethod want use:  ");                          }           public static void menu3()       {          system.out.print("\n1. runge kutta\n" +                            "2. euler\n");          system.out.print("please enter number of \nmethod want use:  ");                          }         public static void rungekutta1() throws ioexception       {          scanner keyboard = new scanner(system.in);           double y;          double h;          double x;          double i;            system.out.print("\nplease enter initial y value:  ");          y = keyboard.nextdouble();           system.out.print("please enter initial x value:  ");          x = keyboard.nextdouble();           system.out.print("please enter h value:  ");          h = keyboard.nextdouble();          if (h<=0)             {                system.out.println("\nenter valid h value");                system.out.print("please enter h value:  ");          h = keyboard.nextdouble();          }           system.out.print("please enter amount of results want:  ");          = keyboard.nextint();          if (i<1)             {                system.out.println("\nplease enter amount of 1 or greater");                system.out.print("please enter amount of results want:  ");          = keyboard.nextint();             }           system.out.println();           system.out.print("your results printed\n"                              + "to file. please enter name\n"                              + "for file:   ");          string filename = keyboard.next();           system.out.println();           system.out.println("x values\t" + "y values");          system.out.println("___________________________");           double k1, k2, k3, k4, k5, k6, k7, k8, k9, k10;           file file = new file(filename);           printwriter outputfile = new printwriter(filename);           (int number=1; number<=i; number++)             {             system.out.printf("when x = %.2f\t", x);             system.out.printf("y = %.4f\n", y);             outputfile.printf("when x = %.2f\t" + "y = %.4f", x,y);                outputfile.println();                k1 = math.pow(x+1, 2);                k2 = x+h/2;                k3 = y+(h/2)*k1;                k4 = math.pow(k2+1, 2);                k5 = y+(h/2)*k2;                k6 = math.pow(k2+1, 2);                k7 = x+h;                k8 = y+h*k6;                k9 = math.pow(k7+1, 2);                k10 = y+h/6*(k1+2*(k4+k6)+k9);                 x = x+h;                 y = k10;                 }                outputfile.close();               }           public static void euler1()throws ioexception        {          scanner keyboard = new scanner(system.in);           double y;          double h;          double x;          double i;           system.out.print("\nplease enter initial y value:  ");          y = keyboard.nextdouble();           system.out.print("please enter initial x value:  ");          x = keyboard.nextdouble();           system.out.print("please enter h value:  ");          h = keyboard.nextdouble();          if (h<=0)             {                system.out.println("\nenter valid h value");                system.out.print("please enter h value:  ");          h = keyboard.nextdouble();          }            system.out.print("please enter amount of results want:  ");          = keyboard.nextint();          if (i<1)             {                system.out.println("\nplease enter amount of 1 or greater");                system.out.print("please enter amount of results want:  ");          = keyboard.nextint();             }           system.out.println();           system.out.print("your results printed\n"                              + "to file. please enter name\n"                              + "for file:   ");          string filename = keyboard.next();           system.out.println();           system.out.println("x values\t" + "y values");          system.out.println("___________________________");           double e1, e2, e3, e4, e5;            file file = new file(filename);           printwriter outputfile = new printwriter(filename);           (int number=1; number<=i; number++)         {                system.out.printf("while x = %.2f\t", x);              system.out.printf("y = %.4f\n", y);             outputfile.printf("when x = %.2f\t" + "y = %.4f", x,y);                outputfile.println();              e1 = math.pow(x+1, 2);              e2 = x+h;              e3 = y+(h*e1);              e4 = math.pow(e2+1, 2);              e5 = y+h/2*(e1+e4);              x = x+h;              y = e5;            }           outputfile.close();           }              public static void rungekutta2() throws ioexception           {             scanner keyboard = new scanner(system.in);           double y;          double h;          double x;          int i;           system.out.print("\nplease enter initial y value:  ");          y = keyboard.nextdouble();           system.out.print("please enter initial x value:  ");          x = keyboard.nextdouble();           system.out.print("please enter h value:  ");          h = keyboard.nextdouble();          if (h<=0)             {                system.out.println("\nenter valid h value");                system.out.print("please enter h value:  ");          h = keyboard.nextdouble();          }            system.out.print("please enter amount of results want:  ");          = keyboard.nextint();          if (i<1)             {                system.out.println("\nplease enter amount of 1 or greater");                system.out.print("please enter amount of results want:  ");          = keyboard.nextint();             }           system.out.println();           system.out.print("your results printed\n"                              + "to file. please enter name\n"                              + "for file:   ");          string filename = keyboard.next();           system.out.println();           system.out.println("x values\t" + "y values");          system.out.println("___________________________");           double r1, r2, r3, r4, r5, r6, r7, r8, r9, r10;           file file = new file(filename);           printwriter outputfile = new printwriter(filename);           (int number=1; number<=i; number++)             {                system.out.printf("while x = %.2f\t", x);              system.out.printf("y = %.4f\n", y);             outputfile.printf("when x = %.2f\t" + "y = %.4f", x,y);                outputfile.println();                 r1 = 3*(x*x)*math.pow((y-4), 2);                 r2 = x+h/2;                 r3 = y+(h/2)*r1;                 r4 = (3*(r2*r2))*math.pow(r3-4, 2);                 r5 = y+(h/2)*r4;                 r6 = (3*(r2*r2))*math.pow(r5-4, 2);                 r7 = x+h;                 r8 = y+h*r6;                 r9 = (3*(r7*r7))*math.pow(r8-4, 2);                 r10 = y+h/6*(r1+2*(r4+r6)+r9);                  x = x+h;                 y = r10;                }                outputfile.close();             }              public static void euler2()           {             int i;             double y;             double h;             double x;           scanner keyboard = new scanner(system.in);           system.out.print("\nplease enter initial y value:  ");          y = keyboard.nextdouble();           system.out.print("please enter initial x value:  ");          x = keyboard.nextdouble();           system.out.print("please enter h value:  ");          h = keyboard.nextdouble();          if (h<=0)             {                system.out.println("\nenter valid h value");                system.out.print("please enter h value:  ");          h = keyboard.nextdouble();          }            system.out.print("please enter amount of results want:  ");          = keyboard.nextint();          if (i<1)             {                system.out.println("\nplease enter amount of 1 or greater");                system.out.print("please enter amount of results want:  ");          = keyboard.nextint();             }           system.out.println();           system.out.print("your results printed\n"                              + "to file. please enter name\n"                              + "for file:   ");          string filename = keyboard.next();           system.out.println();           system.out.println("x values\t" + "y values");          system.out.println("___________________________");               double e1, e2, e3, e4, e5;              file file = new file(filename);           printwriter outputfile = new printwriter(filename);               (int number=0; number<=i; number++)                 {                 system.out.printf("while x = %.2f\t", x);              system.out.printf("y = %.4f\n", y);             outputfile.printf("when x = %.2f\t" + "y = %.4f", x,y);                outputfile.println();                  e1 = 3*(x*x)*math.pow((y-4), 2);                  e2 = x+h;                  e3 = y+h*e1;                  e4 = (3*(e2*e2))*math.pow((e3-4), 2);                  e5 = y+h/2*(e1+e4);                  x = x+h;                  y = e5;                 }                 outputfile.close();             }                 public static void rungekutta3()           {             scanner keyboard = new scanner(system.in);           double y;          double h;          double x;          int i;           system.out.print("\nplease enter initial y value:  ");          y = keyboard.nextdouble();           system.out.print("please enter initial x value:  ");          x = keyboard.nextdouble();           system.out.print("please enter h value:  ");          h = keyboard.nextdouble();          if (h<=0)             {                system.out.println("\nenter valid h value");                system.out.print("please enter h value:  ");          h = keyboard.nextdouble();          }            system.out.print("please enter amount of results want:  ");          = keyboard.nextint();          if (i<1)             {                system.out.println("\nplease enter amount of 1 or greater");                system.out.print("please enter amount of results want:  ");          = keyboard.nextint();             }           system.out.println();           system.out.print("your results printed\n"                              + "to file. please enter name\n"                              + "for file:   ");          string filename = keyboard.next();           system.out.println();           system.out.println("x values\t" + "y values");          system.out.println("___________________________");           double r1, r2, r3, r4, r5, r6, r7, r8, r9, r10;           file file = new file(filename);           printwriter outputfile = new printwriter(filename);           (int number=1; number<=i; number++)             {                system.out.printf("while x = %.2f\t", x);              system.out.printf("y = %.4f\n", y);             outputfile.printf("when x = %.2f\t" + "y = %.4f", x,y);                outputfile.println();                 r1 = 3*(x*x)*math.pow((y-2), 2);                 r2 = x+h/2;                 r3 = y+(h/2)*r1;                 r4 = (3*(r2*r2))*math.pow(r3-2, 2);                 r5 = y+(h/2)*r4;                 r6 = (3*(r2*r2))*math.pow(r5-2, 2);                 r7 = x+h;                 r8 = y+h*r6;                 r9 = (3*(r7*r7))*math.pow(r8-2, 2);                 r10 = y+h/6*(r1+2*(r4+r6)+r9);                  x = x+h;                 y = r10;                }                outputfile.close();             }                 public static void euler3()           {             int i;             double y;             double h;             double x;           scanner keyboard = new scanner(system.in);           system.out.print("\nplease enter initial y value:  ");          y = keyboard.nextdouble();           system.out.print("please enter initial x value:  ");          x = keyboard.nextdouble();           system.out.print("please enter h value:  ");          h = keyboard.nextdouble();          if (h<=0)             {                system.out.println("\nenter valid h value");                system.out.print("please enter h value:  ");          h = keyboard.nextdouble();          }            system.out.print("please enter amount of results want:  ");          = keyboard.nextint();          if (i<1)             {                system.out.println("\nplease enter amount of 1 or greater");                system.out.print("please enter amount of results want:  ");          = keyboard.nextint();             }           system.out.println();           system.out.print("your results printed\n"                              + "to file. please enter name\n"                              + "for file:   ");          string filename = keyboard.next();           system.out.println();           system.out.println("x values\t" + "y values");          system.out.println("___________________________");               double e1, e2, e3, e4, e5;              file file = new file(filename);           printwriter outputfile = new printwriter(filename);               (int number=0; number<=i; number++)                 {                 system.out.printf("while x = %.2f\t", x);              system.out.printf("y = %.4f\n", y);             outputfile.printf("when x = %.2f\t" + "y = %.4f", x,y);                outputfile.println();                  e1 = 3*(x*x)*math.pow((y-2), 2);                  e2 = x+h;                  e3 = y+h*e1;                  e4 = (3*(e2*e2))*math.pow((e3-2), 2);                  e5 = y+h/2*(e1+e4);                  x = x+h;                 y = e5;                 }                outputfile.close();              }             } 

on method

public static void euler1()throws ioexception 

you declare method might throw ioexception filenotfoundexception.

you have in every method might happen including.

public static void euler2() { 

i suggest use ide to

  • help format code.
  • refactor class there not many unrelated methods in it.
  • add these exceptions you type.

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -