javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Use a while loop:

while (true) {
  ....
}

Keep reading input from the keyboard. When, for example, you enter "quit", exit from the loop using the "break" command. Else convert that input into a number and add it to the list.

String input;
while (true) {
  // read input
  if ("quit".equals(input)) {
     break;
  } 
  // convert it into a number and add it to the list
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all study some html. The "select" tag misses the "option" tag which is the one that has the "value" attribute. If you look at the tag, you don't give it any value. So of course it displays null since you don't send anything.

http://www.w3schools.com/default.asp

Second don't just call methods and expect them to do whatever you want or think they do. The getParameterValues method returns an array. If you don't know what happens when you print an array, or what are those strange numbers are: "string java lang @ numbers numbers numbers letters numbers" then STOP right now what you are doing and start studying basic java. Because what you just saw was the call of the toString method that was inherited by the Object class. And if you look at the API of the Object class then the toString method prints just that.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

And I already told you what to do. You have declared a constructor (Employee) with 6 arguments and you are not calling it. You are calling it with 3 arguments.
It is very basic. When you have a method with a certain number of arguments, you call that method with the right type and amount of arguments.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You changed the contructor of the Employee class. So it is normal that you get an error when you try to call the old constructor: super(String, String, String) .
Such contructor with 3 arguments does not exist. The new takes 6 arguments.
So the new is this:

public Employee( String first, String last, String ssn, String date, int month, int day, int year ) {

}

But you are calling this:

public SalariedEmployee( String first, String last, String ssn, 
      double salary )
   {
      [B]super( first, last, ssn );[/B] // pass to Employee constructor
      setWeeklySalary( salary ); // validate and store salary
   }
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

super, calls the constructor of the super class and in this case the Employee class:

public SalariedEmployee( String first, String last, String ssn, ... {
    [U]super( first, last, ssn );[/U]

}

Does the Employee has a constructor that takes as parameters 3 Strings.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You need to post the line that you get the error. The error messages, indicates the line that it happened as well as the file.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Print the query that you are executing:

String query = ".....";
System.out.println(query);
i1=st1.executeUpdate(query);
System.out.println(i1);

What does it print?
Also try to take the query that was printed and run it to an sql command promt.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Post your whole code.
And this: <%=employeeIDArray%> suppose to be put in the "html" code. Not in the scriplet

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I have a. done but i cant get b. down, can anybody help?

Start a new thread. Don't hijack someone else's. Do you want us to stop helping the OP just for you?

Start a new thread and post some code. There are examples in this thread that can help you. If you could do the a) part then what is the problem with b) ? Since you have code for a) make changes and post the new code.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Is is against the forum rules to spam; and any other forum. When you have nothing useful to add or post new information dont post at all.

ProgrammersTalk's post which was quoted in peter_budo's reply was such:

that's just the same thing haha..

What did it contribute to the discussion? How was it helpful for the question that was initially made. It dind't do anything. So posting to a thread to say nothing is against the rules. You may don't know it, but in this forum such as others, there are sometimes people that just make posts that say nothing just for the reason to increase their post counter.

I am not referring to your post, but to the post that had no contribution and resulted in peter_budo's intervantion.

Also your post is a total violation to the rules. And if you start talking about freedom, then when people sign in there are rules to follow. No one is forcing them to sign in and no one is forcing them to stay to this forum. But they have agreed to the rules. So they must follow them.

You critised others without helping anyone. And I am not saying that you are not allowed to express your opinion, I am saying that in this forum, we don't critise others, we help people with their code. I would like to see you do that some time.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Try this:

for(i=1;i<=number;i++)
{             
  for(j=1;j<=i;j++)
  {
    System.out.print(j); 
  }
  System.out.println();
}

The inner loop will do the printing, and the outer loop will only change lines:

Now instead of printing the 'j', declare another int variable outside the loops. Print that, and each time you print it, increase its value.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Look at the API of the methods you are using. If getSessionMap returns a Map object, then try to print the keys that it has.

Also when you call that code. You need to post your code, so we can see what exactly are doing.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I think that when the page loads, you can remove the object from the session, or take the object and create a new instance.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't know anything about jsf, but can you make it so it won't be session scope?
If you had already thought of that, then sorry, but that's all I can think of.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

For starters notice that the input will determine the number of lines. So use the input as upper limit to a for loop.
Then each line has that many number as the number of line.
First line: 1 number
Second line: 2 numbers
....

This will tell you the upper limit, which will be dynamic, of the inner loop

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Another thing that I would like to add, that might not be clear. That code using the ObjectOutputStream and ObjectInputStream, is best used to save whole objects. Not only int numbers: out.writeInt(1) If you look at the API, there is a method: ObjectOutputStream.writeObject(Object obj) that takes as argument any object. So if you have a class with many attributes, you can call only that method and that's it.
For reading just call: ObjectInputStream.readObject() . It returns an Object and all you have to do is cast to the right one.
These classes have examples:
ObjectOutputStream
ObjectInputStream

Remember in order to do that, the class that you are trying to save must implement the Serializable interface. And if your class has other classes as attributes, those must also implement that interface:

class CustomObject1 implements java.io.Serializable {
    private CustomObject2 cust = null;
    private String s = null;
    private int i = 0;
}
class CustomObject2 implements java.io.Serializable {

}

If you look at the API of String class you will see that it already implements that interface. And primitive types "int" can be written with no extra work. So you are good to go.
That means that not all classes of the JAVA API can be written with that way if they don't implement Serializable.

You can write collections as well:

SomeObject [] array = new SomeObject[5];
....
....

File f = new File("filename");
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(f)); …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

SELECT col1, col2, .... FROM table_name

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Each class must the other as global attribute. When a button is clicked call setVisible(false) method of the one you want to hide and setvisible(true) of the one you want to show. The above methods are methods of the JFrame class. You can also have the constructors so they can take each other as parameters.

class Frame1 extends JFrame {
    Frame2 fr2 = null;

    public Frame1() {
           ......
    }

   public void buttonClicked() {
       if (fr2==null) fr2 = new Frame2(this);
       setVisible(false);
       fr2.setVisible(true);
   }
}
class Frame2 extends JFrame {
   Frame fr1 = null;
   
   public Frame2(Frame fr1) {
        this.fr1 = fr1;
   }

   public void buttonClicked() {
       setVisible(false);
       fr1.setVisible(true);
   }
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Look at the API of the Scanner class. Use the methods hasNextInt and nextInt.
Read the numbers and use a for-loop for each line, in the while loop. The numbers will tell you how many asterisk you will print. Also read the assignment for that matter.
Surely you know how to write a for loop:

while has next int {
   read that int
   for loop {
      System.out.print("*") // to print asterisks at the same line
  }
  System.out.println(); // to change lines
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Inside the overridden method use code that checks the color. If it is purple, don't change it

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Just because it creates a jar file, doesn't mean it is executable. It only contains all the classes of your project. Then you can take that jar and you can import it to another project and call the classes that are inside.

If that jar file has a class that has a main method inside then you can run the class from command prompt from the jar file.

So my answer is that I don't know how BlueJ creates a jar file. I read somewhere that the jar file has a MANIFEST file inside where you declare if the jar is executable and what class contains the main method.

I would suggest to search the internet on how to create an executable jar file.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Since vchandra has already answered your question, I would like to add that any class that implements the Comparable interface can be sorted using the compareTo method. If you look at the API the String class implements the Comparable, so it has a "compareTo" method that you can call.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What kind of data, you want to save and do you have any "homework" restrictions concerning how the data will be saved?

There is the easy way using the Serializable interface. The code is only a few lines, but you will not learn much.

And the hard way would be to write the values of the attributes of your classes to a text file. With this way you will learn how to write and read from files.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In this thread you ask the same question:
http://www.daniweb.com/forums/thread274702.html

An answer has been given to your question. Don't go around making new threads with the same question. NO one is going to write the code for you no matter how many thread you start.

You have been given suggestions; now post some code, make an effort.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Assuming that you are using java 1.5 or later then:

public class SomeObject implements Comparable<SomeObject> {
    

     public boolean equals(Object obj) {
         if (obj==null) return false;
         if (obj instanceof SomeObject) {
               SomeObject so = (SomeObject)obj;
               // write your code here that compares the values of the so attributes with the attributes of this class.
         }
         return false;
     }

     public int compareTo(SomeObject o) {
          // look at the API of the Comparable interface. It explains how this method should be implemented.
     }
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Since you start the index from 0 the first loop would be this:

for (int i = 0; i < sides; i++)

If sides = 3, then i = 0,1,2. 3 sides.
Or:

for (int i = 1; i <= sides; i++)

If sides = 3, then i = 1,2,3. 3 sides.

As you have noticed you entered 3 and the program asked for 4 points.

Also it is not a good idea to have the methods of an object (Point, Line) to call the System.out.println. What if you want to use it in desktop gui, or a web page. You will have to make additional changes.
If you had methods that return values, you could use them anywhere you want:

class Point {
   int a = 0;
   int b = 0;

   public String toString() {
       return "("+a+","+b+")";
   }
}
class Line {
   Point p1,p2;

   public Point getP1() {
      return p1;
  }

   public double length() {
       // calculate length;
       return 123.45;
   }
}
System.out.println("Point 1: "+ L1.getP1());
System.out.println("Point 2: "+ L1.getP2());
System.out.println("The length of the line is: "+ L1.length());

Now that you have the length, you can add all the lengths in the for loop:

[B]double sum = 0;[/B]
for (int i = 0; i < pointsArray.size() - 1; i++)
{
// YOUR CODE
   Point P1 = (Point) pointsArray.get(i);
   ...
   System.out.println("The length of the line is: "+ L1.length());

[B]sum = sum + L1.length();[/B]
}
[B]System.out.println("Perimeter: "+sum);[/B]
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You need to provise more information. How was the jar file created, how do you run it, and do you get any error messages?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have you tried reading the errors that you get? Because If you had the solution would be very easy:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Transfer.actionPerformed(Transfer.java:111)

You get a NullPointerException at the Transfer.java file, at the actionPerformed method at line 111.

You are using something which is null. Initialize it.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I believe the set and get methods are used for code reusability...?

This is what happens when I try to run the program.

Please enter radius of circle:4
The radius of the circle is
Exception in thread "main" java.util.IllegalFormatConversionException: d != java
.lang.Double
at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:399
2)
at java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2708)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2660)
at java.util.Formatter.format(Formatter.java:2432)
at java.io.PrintStream.format(PrintStream.java:920)
at java.io.PrintStream.printf(PrintStream.java:821)
at Circles.displayMessage(Circles.java:29)
at CirclesTest.main(CirclesTest.java:23)
Press any key to continue...

The stack trace tells you exactly where the error is. It would be helpful next time to read it and if you can't fix it, to point where that line is at the code you posted.

Exception in thread "main" java.util.IllegalFormatConversionException: d != java
.lang.Double

at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:399
2)
at java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2708)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2660)
at java.util.Formatter.format(Formatter.java:2432)
at java.io.PrintStream.format(PrintStream.java:920)
at java.io.PrintStream.printf(PrintStream.java:821)
at Circles.displayMessage(Circles.java:29)
at CirclesTest.main(CirclesTest.java:23)

The error is at the displayMessage method of the Circles.java file at line 29.

The getRadius method returns Double, which is an object. The printf method: "The radius of the circle is \n%d!\n"
expects a double primitive type.

So I think that if you change the return type of the getRadius method to double should correct your problem.
It is better, when you create get/set methods, to have the argument of the "set" and the return type of the "get" to be exactly the same type as the variable used.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You are using something which is null. The error tells you the line where that happened. Also you are trying to close the 'stmt' variable but you are using the 'pstmt' to execute the query.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Post your error messages.

Also you have a method: setRadius
Why don't you use that instead of this: myCircles.radius = input.nextDouble()
What's the point of having it?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Actually you need to convert String to int. If this: emarks_txt is a JTextFiled then this: emarks_txt.getText() returns String. But your Enrollment constructor takes as argument an int:
Enrollment(String student_id,String subject_code,String Grade, int Marks)

So you can do this:

int Marks = Integer.parseInt(emarks_txt.getText());

Enrollment e = new Enrollment(eid_txt.getText(),ecode_txt.getText(),egrade_txt.getText() , Marks );

Or better:

try {
     int Marks = Integer.parseInt(emarks_txt.getText());

     Enrollment e = new Enrollment(eid_txt.getText(),ecode_txt.getText(),egrade_txt.getText() , Marks );

     e.SaveEnrollment();
} catch (NumberFormatException nfe) {
      System.out.println("Error. Mark entered not a number: " + nfe.getMessage());
       // OR
     JOptionPane.showMessageDialog(null, "Mark entered not a number")
}
scratchwiz commented: thanks :) scrathwiz.. +1
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

2 for loops.
Outer: 1 to 5 for the lines.
Inner: Depending on the index of the first loop you will decide how many stars will be printed. The number of stars will be the number of times the inner loop will run.

Also:
System.out.println() : Changes lines
System.out.print("*") : Prints '*' at the same line

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Don't use throws Exception at main!!!! If it is thrown then your program will crash. You need to catch it:

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class QuickFileRead {
public static void main(String[] args) {


Scanner scanner = null;

try {
    scanner = new Scanner(new File("c:/temp/text.txt"));

    String line = null;

     while (scanner.hasNextLine()) {

         line = scanner.nextLine();  
         System.out.println("Line: " + line);

     }
} catch (FileNotFoundException fe) {
   System.out.println("Error: " + fe.getMessage());
} finally {
   scanner.close();
}
}
}

After you get each line, you can use it in any way you want. What is the format of your file. Can you post part of it?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Actually I have to make a hashtable. My data is in a datafile and I have to retrieve data from that without using Java Class Library, that means I cant use import java.io...
I have to take first two words to be the key and then the next word to be the value. Right now I am stuck in reading the data from file.

Thanks for your help.

Can you post the exact description of your assignment, because I find it strange to read a file without using the java.io ?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Can you post the latest code.

Also you can do this:

Scanner sc = new Scanner(System.in);
System.out.println("Enter numbers separated by space:");

String input = sc.nextLine();

// FOR TESTING YOU CAN TRY THIS:
// String input = "10 20 35 11";

String [] numbers = input.split(" ");
for (int i=0;i<numbers.length;i++) {
   System.out.println("Number: " + numbers[i]);
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Assuming that their files are classes with methods, then in your swing class, you will have instances of those classes. Then according to what the user clicks you will call the methods of those classes and display the results.

If those classes have main methods, then they are doing it wrong. The idea is to have classes with functionality inside, and in a "Main" class (swing, console), create those classes, call their methods and display the results.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all, write a main method in a separate class and test the ParseClean in order to see that it works.

Then post some more code of the a.html file so we can see how you submit the form.

And finally don't use this: out.println(ch.ParseClean(trans)); Use this:

<%@page import="gaveshan.checking;"%> 
<% 
checking ch=new checking(); 
String trans=request.getParameter("key"); 
session.setAttribute( "trans", trans ); 
%>
<%= ch.ParseClean(trans) %>
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The NumberFormatException tells you that what you used as argument is not a number. It also says that the value you passed is the String: undefined

threw exception java.lang.NumberFormatException: For input string: "undefined"

That would mean that the value of rowsPerPageStr is the String: "undefined": String rowsPerPageStr = request.getParameter("rowsPerPage"); So here:

window.location = "hwdisplay?rowsPerPage=" + rowsPerPage;

The variable rowsPerPage has the value: "undefined"

Try putting some alerts and see what you pass as parameter:

alert(rowsPerPage);
window.location = "hwdisplay?rowsPerPage=" + rowsPerPage;
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

the only way to kill it is to inter a character and not an integer. sc.hasNextInt() suppose to return a boolean true if the next token is an integer and false if anything else including eol.

Well apparently the last part is not correct. I just checked the API and it doesn't say such thing. It simply returns true or false if the next token is int BUT the the next token is not a new line. It is when you enter value. The new line, or many empty spaces followed by <ENTER> at the keyboard doesn't constitute as next token. Look at the description of the method:

Returns true if the next token in this scanner's input can be interpreted as an int value in the default radix using the nextInt() method.

I understand that you want the user to enter this and stop at the New Line:

10 20 30

Instead of this:

10 20 30 a

Then perhaps you can try this:

Scanner KEY_BRD=new Scanner(System.in);
System.out.println("Please enter elements...");
String input = KEY_BRD.nextLine(); // enter 10 20 30 40
System.out.println("input: "+input );


Scanner sc = new Scanner([B]input[/B]);
int j=0;
			while (  sc.hasNextInt())
			{
				a[j]=sc.nextInt();
				System.out.println(" a[j]  " + j +"  " + a[j]);	
				j++;
			}

And Diomedes is right. You don't need to decrease the value of j. Whenever you add a number, you increase j. So at the end, the value of j gives you what you want

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

*
***
*****
***
*
display the output as above using c++ or c

This is a java forum. Start a new thread in the C forum but don't expect people to give you the answer if don't show some effort and post what you have done so far.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Call all the methods in the main like you are doing and after each call, print the instance.

This: System.out.println (x); will not work because: When you call the System.out.println with an object as argument, the toString method of that object is called. Since you haven't defined such method, the inherited from the Object super class is called, which returns that funny looking String you see.

So either call the Rational.printRational(x); or much, much better create such method. That method will return whatever you want to see being printed:

public String toString() {
  return num + " / " + den;
}

And call it:

Rational x = new Rational ();           
        x.num = 2.0;
        x.den = 3.0;

        System.out.println ("Before: " + x);

        Rational.negate (x);

        System.out.println ("After: " + x);

The reduce method is totally wrong. You need to call the gcd with arguments the values of the Rational argument, take the result in a separate variable and use it to alter the values of the Rational argument.

In the add method you need to do some actual calculations, not just call the same method which result in the same method calling itself, which will call itself, which will call itself, which will call itself,

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hi I have designed the food part but I dont understand the machine part, is it possible u can send me ur email in a private message, then I can show u the scenario. Thanks.

No this is a forum and people post their questions here.

Also the machine method will take as argument a food, process it and return another class.
What the method will do is up to you to decide. I don't know what kind of processing is required, that is up to you. You have been told to write something that processes food. Well ask whoever gave you the assignment how the food will be processed and what they want the result to be. Maybe it will be a class called "PackagedFood".

Maybe the idea is for you to think some processing ways. It is not difficult to say this:

Food tomato = new Food();
Food ketcup = process(tomato);

Now come up with other examples like this and think what attributes are required. Maybe instead of Food you will use subclasses of that class.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You haven't given us much to work with.
You might want to create a "Food" class. Maybe you should also create subclasses of the "Food" class for different foods.
And perhaps different foods can be inputted in specific types of machines so you have some business logic here.
Have a method in the Machine class that takes as argument a Food and based on what kind of food it is, it returns the result, which is probably some other class.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

i don't understand cues the input method & the so many method u use i need a code by switch and also sacrifice the continuity

You cannot String with switch so these if-else are necessary. All the methods are self explanatory. If you don't understand them, search the API or the internet in general.

And for other questions start a new thread

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
{
// piggy is NULL
this.piggy.setColour(Colour.PINK); // error

// piggy is NULL
this.piggy.setPosition(0); // error

// now you give piggy value.
this.piggy = aPig;
}

First you give value to an object or create it and then you use its methods

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

thanks javaddict ::):) I appreciate your example...very clear and also very helpful..

What i don't get is.. running the first of the last two pieces of codes,

public static void MyNumber(String x) throws TryCatchException1{	
		String y = x.substring(0,200);	}

I get the output ..

AAAAAA : String index out of range: 200

of type StringIndexOutOfBoundsException. why is that happening? why not of type TryCatchException1...it is the type thrown so i'm wondering why :):) :) ..thanks for the help :)

Because in the last example even though you declare the method to throw a TryCatchException1, the x.substring(0,200) threw a StringIndexOutOfBoundsException . So that was caught.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

At the btnOkActionPerformed whenver the button is clicked, you read the file and the you add the new DVD to the list. It is not necessary. You need to read only once the file and sotre those value at the list. Of course I don't know the purpose of that button.

Usually you read the file into a list at the begining of your program once, then add as many as you want new DVDs to the list and when you are done save the entire list back to the file.

So you don't need to append the new values.


If you want to keep your code, adn you do want to append the new DVD:

File file = new File(DVDlist);
            FileWriter fw = new FileWriter(file);
            PrintWriter pw = new PrintWriter(fw);

            pw.println(dvd.getTitle() + ":" + dvd.getCategory() + ":" + dvd.getYear() + ":" + dvd.getRate());
            pw.flush();
            fw.close();

Then look the API of those classes. One of the constructors has an extra argument that when set to true, whatever you write, is appended to at the end of the file.
Look the constructors at the API of the class FileWriter or PrintWriter.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You throw it, but you don't catch it. Exceptions tend to terminate your program in a bad way. You need to catch them so that it won't terminate your program:

public static void main(String args[]) {
A a = new A();
int x1;
int x2;
x1 = 7;
x2 = 0;
  try {
     a.printer(x1, x2);
  } catch (ArithmeticException ae) {
     System.out.println("An error occured: "+ar.getMessage());
  }
}
System.out.println("Finishing the program");
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I already explained the the piggy attribute is null because you never set its value, with the argument of the constructor:

public class Animal
private Pig piggy;
private int reset;
private int position;

/*Constructor of the object Animal*/
public Animal(Pig aPig) {
this.position = 0;
this.reset = 0;
piggy = aPig
}

public void resetCount()
{
 // do whatever the assignment says
 // change the position
 pig.setPosition(0);
 // change the color
 pig.setColour(Colour.PINK);
}