in this code:
import java.util.*; import java.io.*; public class FinalProject { public static void main (String[] args) { Scanner in = new Scanner(System.in); System.out.println("how many pages do you want?"); int pages = in.nextInt(); Html[] site = new Html[pages]; for(int i = 0; i < pages; i++) { if(i==0) { System.out.println("black box line"); String blkBox = in.nextLine(); System.out.println("what do want the site titled?"); String title1 = in.nextLine(); System.out.println("what do you want on the home page?"); String content = in.nextLine(); System.out.println("what image do you want behind the page?"); String image = in.nextLine(); boolean home = true; site[0] = new Html(title1, content, image, home); System.out.println("bong " + site[i].titleGet() + " " + i); } else if(i>0) { System.out.println("what do you want page " + i + " titled?"); String title = in.nextLine(); System.out.println("what do you want on page" + i + "?"); String content = in.nextLine(); System.out.println("what image do you want behind the page?"); String image = in.nextLine(); boolean home = false; site[i] = new Html(title, content, image, home); System.out.println("bong " + site[0].titleGet() + " " + i); System.out.println("bong " + site[i].titleGet() + " " + i); } else { System.out.println("bing"); } } for(int j = 0; j < pages; j++) { if(j == 0) { try { BufferedWriter out = new BufferedWriter(new FileWriter(site[0].titleGet() + ".html")); out.write(site[0].homeGet(pages, site[0].titleGet())); out.close(); System.out.println("ding " + site[j].titleGet() + " " + j); } catch (IOException e) { } } else if(j > 0) { try { BufferedWriter out = new BufferedWriter(new FileWriter(site[0].titleGet() + j + ".html")); out.write(site[j].pageGet()); out.close(); System.out.println("ding " + site[j].titleGet() + " " + j); } catch (IOException e) { } } else { } } } }
using this object:
public class Html { static String title, content, image; static boolean home; public Html(String t, String c, String i, boolean h) { title = t; content = c; image = i; home = h; } public String titleGet() { return(title); } public String pageGet() { return("<html><head><title>" + title + "</title></head><body background=\"" + image + "\"><h1 align=\"center\" font color=\"#00FF00\">" + content + "</h1></body></html>"); } public String homeGet(int pages, String title) { String index = ""; for(int j = pages -1; j > 0; j--) { index = index + "<a font color=\"#00FF00\" href=\"" + title + j + ".html\">" + "page" + j + "</a> <br />"; System.out.println("dong " + j); } return("<html><head><title>" + title + "</title></head><body background=\"" + image + "\"><h1 align=\"center\" font color=\"#00FF00\">" + content + "</h1> <br />" + index + "</body></html>"); } }
all objects in the site array are writen over by the newest entry, why?
thanks