Sammen hold 2 klasser i hashmap
Hej alle.Er ny i java, men sidder og prøver at lave et skole program, der skal kunne tage en participant og holde et beløb, samt tilføje flere og lægge dem sammen. De skal så kunne hentes af en anden klasse og udskrive dem.
Men mit største problem er bare at få participants til at kunne holde flere betalinger afgange.
Mangler bare et lille hint, til at komme videre.
Håber i kan hælpe.
Mvh Java noob.
kode for participant.
public class Participants
{
private String Name;
private static int SSN;
private String Address;
private boolean Accomendation;
public Participants(String Name, int SSN, String Address)
{
this.Name = Name;
this.SSN = SSN;
this.Address = Address;
Accomendation = false;
}
static int getSSN()
{
return SSN;
}
public String getName()
{
return Name;
}
public String getAddress()
{
return Address;
}
public String toString()
{
String line = "Name : " +Name + "\n" + "SSN: " + SSN+ "\n " + "Address: " + Address;
return line;
}
public void print()
{
System.out.println(Name);
System.out.println(SSN);
System.out.println(Address);
}
/**
* If the participants wants to book a hotel room
* the parremeter true will set i to yes
* ohterwise it will be false = no
*/
public void SetAccomondation(boolean yes)
{
Accomendation = yes;
}
public boolean ShowAccomondation()
{
return Accomendation;
}
}
koden for betalinger
public class Consumption
{
private String Type;
private int date;
private int time;
private int price;
public Consumption(String Type, int date, int time, int price)
{
this.Type = Type;
this.date = date;
this.time = time;
this.price = price;
}
public String toString()
{
String line = Type + "\n" + "Date: " + date+ "\n" + "Time: " +time+ "\n " + "Price: " + price;
return line;
}
}
koden hvor participants og betalinger gerne skulle kunne holdes sammen.
import java.util.HashMap;
/**
* Write a description of class ConsumtionTakeplace here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class ConsumtionTakeplace
{
public HashMap<Participants, Consumption> map;
public ConsumtionTakeplace()
{
map = new HashMap<Participants, Consumption>();
}
public void putConsumption(Participants theParticipants, Consumption theConsumption)
{
map.put(theParticipants, theConsumption);
}
public void getConsumptions(Participants theParticipants)
{
map.get(theParticipants);
System.out.print(map.get(theParticipants));
}
}