no więc mam klasę, która łyka sobie dane <nazwa,wartosc> podawane w klasie Start.
mój problem polega na tym, że metoda Map<String, Integer> get(int totalMass) ma wykonac 2 rzeczy:
1) ma pobierać map
2)Suma wartosci wszystkich intow zmodyfikowanego przepisu ma byc mozliwie zblizona do przekazanej wartosci calkowitej, ale proporcje intow maja byc takie same jak w wersji oryginalnej.
no i zabijcie, ale nie mam pojęcia, co zrobić by edytować/dodawać/dobrać się do tych intów i poczarować żeby zachowały proporcje.
chwilowo mam coś takiego:
Kod PHP:
class Recipe implements RecipeInterface {
Map<String, Integer> recipe= new HashMap<String, Integer>();
int klucz;
String napis=new String();
int sum=0;
int sum2=0;
int pomoc=0;
public void set(Map<String, Integer> recipe){
recipe.put(new String(napis),new Integer(klucz));
System.out.println("\n"+recipe);
for(int x : recipe.values())
sum=sum+x;
//System.out.println(sum);
}
public Map<String, Integer> get(int totalMass){
if(totalMass==sum){
System.out.println("okay! ");
return recipe;
}
else{
System.out.println("Masy sie nie zgadzaja! Pozwol, ze poprawie...");
System.out.println(sum);
System.out.println("total mass "+totalMass);
return recipe;
}
}
public int size() {
return recipe.size();
}
public boolean isEmpty() {
return napis.isEmpty();
}
}
class Start{
public static void main(String[] args){
Map<String, Integer> Oceny = new HashMap<String, Integer>();
Oceny.put("Polski", 2);
Oceny.put("Matematyka", 4);
Oceny.put("Matematyksadaa", 5);
Oceny.put("Matematykadxca", 6);
Oceny.put("Matemdsdfatyka", 7);
Oceny.put("Matematyeqweqrka", 8);
Oceny.put("Matemaweqwtyka", 9);
Recipe recka= new Recipe();
recka.set(Oceny);
System.out.println(recka.isEmpty());
System.out.println(Oceny.size());
recka.set(recka.get(90));
}}
Zakładki