daily pastebin goal
28%
SHARE
TWEET

Untitled

a guest May 16th, 2018 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. * 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.
  2.  
  3.      * 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:
  4.  
  5. What a person owns the thing: Sara
  6. What kind of stuff: Jewellery
  7. What kind of jewelry: Necklaces
  8. Is the jewelry of gold? yes
  9. Number of jewels: 7
  10.  
  11. This is what i did so far:
  12.  
  13. public static void main(String[] args) {
  14.        
  15.     Scanner sc = new Scanner(System.in);
  16.     ArrayList<Person> personList = new ArrayList<Person>();
  17.     ArrayList<Pryl> prylList = new ArrayList<Pryl>();
  18.    
  19.      
  20.     while (true){
  21.              
  22.     System.out.print("\n1: Skapa person \n2: Skapa pryl \n3: Visa alla \n4: Visa rikaste \n\n");
  23.     int command = sc.nextInt();
  24.    
  25.       switch (command){
  26.      
  27.           case 1:
  28.             System.out.print("Namn på person: ");
  29.             String namn=sc.next();
  30.             prylList.add(new Pryl(namn));
  31.                  break;
  32.              
  33.           case 2:
  34.               System.out.println("Vilken person äger prylen: ");
  35.               String tempNamn=sc.next();
  36.              
  37.               for(Pryl x : prylList){
  38.                   if(x.getNamn().equalsIgnoreCase(tempNamn)){
  39.                       Person Person = new Person();
  40.                       Person.setName(tempNamn);
  41.                       System.out.println("Vilken sorts pryl: ");
  42.                       String sortsPryl=sc.next();
  43.                      
  44.                       if(sortsPryl.equalsIgnoreCase("smycke")){
  45.                          
  46.                           System.out.println("Vilken sorts smycke: ");
  47.                           String Sort=sc.next();
  48.                          
  49.                           System.out.println("Antal ädelstenar: ");
  50.                           int antal = sc.nextInt();
  51.                           Person.setAntal(antal);
  52.                           personList.add(Person);
  53.  
  54. etc...
  55.  
  56.         case 3:
  57.  
  58.                for (int x = 0; x < personList.size(); x++){            
  59.         Person tempPerson = personList.get(x);
  60.                 System.out.println(tempPerson.getName()+tempPerson.getSort()+tempPerson.getAntal());
  61.                 break;
  62.                
  63.                }
RAW Paste Data
Top