Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- * Create person. A new person is created by the program asks for the name. If there is already a person in the registry with that name, an error message will inevitably person and is entered in the Register.
- * Create item. An item is created through a dialogue. The program asks for the name of the person who shall have the thing, what kind of item that's the thing, and different attributes. Then created a gadget items that added up to that person's item collection. If no person with the specified name, an error message. The dialogue would for example could look like this:
- What a person owns the thing: Sara
- What kind of stuff: Jewellery
- What kind of jewelry: Necklaces
- Is the jewelry of gold? yes
- Number of jewels: 7
- This is what i did so far:
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- ArrayList<Person> personList = new ArrayList<Person>();
- ArrayList<Pryl> prylList = new ArrayList<Pryl>();
- while (true){
- System.out.print("\n1: Skapa person \n2: Skapa pryl \n3: Visa alla \n4: Visa rikaste \n\n");
- int command = sc.nextInt();
- switch (command){
- case 1:
- System.out.print("Namn på person: ");
- String namn=sc.next();
- prylList.add(new Pryl(namn));
- break;
- case 2:
- System.out.println("Vilken person äger prylen: ");
- String tempNamn=sc.next();
- for(Pryl x : prylList){
- if(x.getNamn().equalsIgnoreCase(tempNamn)){
- Person Person = new Person();
- Person.setName(tempNamn);
- System.out.println("Vilken sorts pryl: ");
- String sortsPryl=sc.next();
- if(sortsPryl.equalsIgnoreCase("smycke")){
- System.out.println("Vilken sorts smycke: ");
- String Sort=sc.next();
- System.out.println("Antal ädelstenar: ");
- int antal = sc.nextInt();
- Person.setAntal(antal);
- personList.add(Person);
- etc...
- case 3:
- for (int x = 0; x < personList.size(); x++){
- Person tempPerson = personList.get(x);
- System.out.println(tempPerson.getName()+tempPerson.getSort()+tempPerson.getAntal());
- break;
- }
Add Comment
Please, Sign In to add comment