0 Replies - 543 Views - Last Post: 24 November 2008 - 07:36 PM Rate Topic: -----

#1 markorulz1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 18-September 08

Need help with my Project !

Post icon  Posted 24 November 2008 - 07:36 PM

import java.util.*;
import java.io.*;
class Sostojka{
	private String ime;
	protected int poc_mesec;
	protected int kraj_mesec;
	private int kalorii;
	Sostojka(){};
	Sostojka(String ime, int poc_mesec, int kraj_mesec, int kalorii){
		this.ime = ime;
		this.poc_mesec = poc_mesec;
		this.kraj_mesec = kraj_mesec;
		this.kalorii = kalorii;
	}	
	int vrati_mesec()
	{return poc_mesec;}
	public int vrati_kraj()
	{return kraj_mesec;}
}

public class Jadenje extends Sostojka {
	private String jadenje_ime;
	private int kol_sostojki,poc_spremi,kraj_spremi;
	Jadenje(){};
	Jadenje(int a, int b){
		this.poc_spremi = a;
		this.kraj_spremi = b;
		//System.out.println(a+" "+b);
		//System.out.println("------------------");
	};
	Jadenje(String ime, int poc_mesec, int kraj_mesec, int kalorii,String jadenje_ime,int kol_sostojki){
		super(ime,poc_mesec,kraj_mesec,kalorii);
		this.jadenje_ime = jadenje_ime;
		this.kol_sostojki = kol_sostojki;
	}

	public void spremi()
	{
		
			if(poc_spremi <= poc_mesec) 
			poc_spremi = poc_mesec;
			
			if(kraj_spremi >= kraj_mesec)
			kraj_spremi = kraj_mesec;
			System.out.println(poc_spremi+" "+kraj_spremi);
		}
	
	public String zadnja(){
		
		String h = new String();
		spremi();
		try{
		if(poc_spremi > kraj_spremi){
			throw new Exception();
		}
		else{
			 h = poc_spremi +" "+ kraj_spremi;
		}
		}catch(Exception e){
			System.out.println("Jadenjeto nemoze da se zgotvi");
		}
		return h;
	}
		

		
	
	
	
	public static void main(String[] args)throws IOException {
		Jadenje ob,ob1;
		Jadenje objekt = new Jadenje();
		int br=1,broj_linii=0,broj1=0,broj2=0;
		LinkedList<String> s = new LinkedList();
		String pom = new String();
		BufferedReader vlez = new BufferedReader(new FileReader("vlez.txt"));
		for(int i = 0;(pom=vlez.readLine())!=null;i++){
			s.add(i, pom);
		}
		int i=0;
		while(i<s.size()){
			String c = s.get(i).substring(0,1);
			
			if(c.compareTo("<") == 0){
				String [] p = s.get(i).split(",");
				++i;
				int broj = Integer.parseInt(p[1]);
				while(c.compareTo("<")!=0){
					String [] g = s.get(i).split(",");
					//System.out.println(g[0]+" "+g[1]+" "+g[2]+" "+g[3]+" "+p[0]+" "+p[1]);
					ob = new Jadenje(g[0],Integer.parseInt(g[1]),Integer.parseInt(g[2]),Integer.parseInt(g[3]),p[0],Integer.parseInt(p[1]));
					if(broj2 == 0){
					objekt.spremi();
					broj2++;}
					if(broj1 == 0){
					ob1 = new Jadenje(Integer.parseInt(g[1]),Integer.parseInt(g[2]));
					broj1++;}
					i++;
					broj_linii++;
					
					
					
				}
				/*try{
					if(broj_linii != broj)
					{
						throw new Exception();
					}
				}catch(Exception e)
					{System.out.println("Ima poveke sostojki od navedenite");
					}
					*/
				}
				
				
				
				}
			
				System.out.println(objekt.zadnja());
			
			  //System.out.println("------------------");
			  
			}

			
		}
	

			

This is the txt file:
<food>Kompir manja,3
voda,1,12,0
kompir,2,7,33
magdonos,4,12,50
<food>pastrmajlija,4
brasno,2,6,34
meso,1,12,28
jajca,2,7,24
kvasec,3,8,25


i need help here, in this project, if find char < thats is food, and the lines after are ingredients of that food, the next two numbers after ingredients are the months which knows when that ingredients are ready for cooking, and now my problem is, the result need to be, average, when that food can be cooked, exemple first food can be cooked from 4 to 7 month. And my results are 0 0 :( i cant fix the problem :S
Thanks

Is This A Good Question/Topic? 0
  • +

Page 1 of 1