{"id":10071,"date":"2022-09-22T03:54:33","date_gmt":"2022-09-21T22:24:33","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-creating-an-interface-by-adding-elements-using-arraylist\/"},"modified":"2022-09-22T03:54:33","modified_gmt":"2022-09-21T22:24:33","slug":"solved-creating-an-interface-by-adding-elements-using-arraylist","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-creating-an-interface-by-adding-elements-using-arraylist\/","title":{"rendered":"[Solved] Creating an Interface by adding elements using arraylist"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-45613812\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"45613812\" data-parentid=\"45613396\" data-score=\"0\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<pre><code>String studId = \"\";\nString firstName =\"\";\nString lastName =\"\";\nint number =0;\nint index = 0;\nStudentServiceImpl studServImpl = new StudentServiceImpl();\nScanner scan = new Scanner(System.in);\n\ndo{\n\nSystem.out.println(\"1.Add Student:\");\nSystem.out.println(\"2.Delete Student:\");\nSystem.out.println(\"3.Display Students:\");\nSystem.out.println(\"4.Exit\");\nSystem.out.println();\nSystem.out.print(\"Select number: \");\nSystem.out.println();\nnumber=scan.nextInt();\n\nif(number==1){\n    Student student =  new Student();\n    System.out.println(\"Enter Student No.\");\n    studId = scan.next();\n    student.setStudId(studId);\n\n    System.out.println(\"Enter First Name:\");\n    firstName = scan.next();\n    student.setFirstName(firstName);\n\n    System.out.println(\"Enter Last Name:\");\n    lastName = scan.next();\n    student.setLastName(lastName);\n\n    studServImpl.add(student);\n\n}\n\n\n    else if(number ==2){\n\n\n\n    }\n\n    else if (number == 3){\n\n    List&lt;Student&gt; studentList = new ArrayList&lt;Student&gt;();\n\n    studentList = studServImpl.getStudent();\n\n    System.out.println(\"\\nThe size of List: \"+studentList.size());\n\n\n\n    for (Student studentRec : studentList) {\n        System.out.println(\"Student ID: \"+ studentRec.getStudId());\n        System.out.println(\"First Name: \"+ studentRec.getFirstName());\n        System.out.println(\"Last Name: \"+ studentRec.getLastName()+\"\\n\");\n\n\n    }\n\n    }\n\n    else if(number == 4){\n\n        System.out.println(\"Thank you, Good Bye!\");\n    }\n\n\n\n    }\n\n\n    while(number!=0);\n\n}\n<\/code><\/pre>\n<p>Your code could have been this, note that the only change I made is making the student object a local variable inside the block where you do the input.<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">0<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Creating an Interface by adding elements using arraylist <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] String studId = &#8220;&#8221;; String firstName =&#8221;&#8221;; String lastName =&#8221;&#8221;; int number =0; int index = 0; StudentServiceImpl studServImpl = new StudentServiceImpl(); Scanner scan = new Scanner(System.in); do{ System.out.println(&#8220;1.Add Student:&#8221;); System.out.println(&#8220;2.Delete Student:&#8221;); System.out.println(&#8220;3.Display Students:&#8221;); System.out.println(&#8220;4.Exit&#8221;); System.out.println(); System.out.print(&#8220;Select number: &#8220;); System.out.println(); number=scan.nextInt(); if(number==1){ Student student = new Student(); System.out.println(&#8220;Enter Student No.&#8221;); studId = scan.next(); student.setStudId(studId); &#8230; <a title=\"[Solved] Creating an Interface by adding elements using arraylist\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-creating-an-interface-by-adding-elements-using-arraylist\/\" aria-label=\"More on [Solved] Creating an Interface by adding elements using arraylist\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[323],"class_list":["post-10071","post","type-post","status-publish","format-standard","hentry","category-solved","tag-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Creating an Interface by adding elements using arraylist - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-creating-an-interface-by-adding-elements-using-arraylist\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Creating an Interface by adding elements using arraylist - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] String studId = &quot;&quot;; String firstName =&quot;&quot;; String lastName =&quot;&quot;; int number =0; int index = 0; StudentServiceImpl studServImpl = new StudentServiceImpl(); Scanner scan = new Scanner(System.in); do{ System.out.println(&quot;1.Add Student:&quot;); System.out.println(&quot;2.Delete Student:&quot;); System.out.println(&quot;3.Display Students:&quot;); System.out.println(&quot;4.Exit&quot;); System.out.println(); System.out.print(&quot;Select number: &quot;); System.out.println(); number=scan.nextInt(); if(number==1){ Student student = new Student(); System.out.println(&quot;Enter Student No.&quot;); studId = scan.next(); student.setStudId(studId); ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-creating-an-interface-by-adding-elements-using-arraylist\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-21T22:24:33+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-creating-an-interface-by-adding-elements-using-arraylist\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-creating-an-interface-by-adding-elements-using-arraylist\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Creating an Interface by adding elements using arraylist\",\"datePublished\":\"2022-09-21T22:24:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-creating-an-interface-by-adding-elements-using-arraylist\/\"},\"wordCount\":49,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"java\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-creating-an-interface-by-adding-elements-using-arraylist\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-creating-an-interface-by-adding-elements-using-arraylist\/\",\"name\":\"[Solved] Creating an Interface by adding elements using arraylist - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-09-21T22:24:33+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-creating-an-interface-by-adding-elements-using-arraylist\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-creating-an-interface-by-adding-elements-using-arraylist\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-creating-an-interface-by-adding-elements-using-arraylist\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Creating an Interface by adding elements using arraylist\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Creating an Interface by adding elements using arraylist - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-creating-an-interface-by-adding-elements-using-arraylist\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Creating an Interface by adding elements using arraylist - JassWeb","og_description":"[ad_1] String studId = \"\"; String firstName =\"\"; String lastName =\"\"; int number =0; int index = 0; StudentServiceImpl studServImpl = new StudentServiceImpl(); Scanner scan = new Scanner(System.in); do{ System.out.println(\"1.Add Student:\"); System.out.println(\"2.Delete Student:\"); System.out.println(\"3.Display Students:\"); System.out.println(\"4.Exit\"); System.out.println(); System.out.print(\"Select number: \"); System.out.println(); number=scan.nextInt(); if(number==1){ Student student = new Student(); System.out.println(\"Enter Student No.\"); studId = scan.next(); student.setStudId(studId); ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-creating-an-interface-by-adding-elements-using-arraylist\/","og_site_name":"JassWeb","article_published_time":"2022-09-21T22:24:33+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-creating-an-interface-by-adding-elements-using-arraylist\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-creating-an-interface-by-adding-elements-using-arraylist\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Creating an Interface by adding elements using arraylist","datePublished":"2022-09-21T22:24:33+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-creating-an-interface-by-adding-elements-using-arraylist\/"},"wordCount":49,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["java"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-creating-an-interface-by-adding-elements-using-arraylist\/","url":"https:\/\/jassweb.com\/solved\/solved-creating-an-interface-by-adding-elements-using-arraylist\/","name":"[Solved] Creating an Interface by adding elements using arraylist - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-09-21T22:24:33+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-creating-an-interface-by-adding-elements-using-arraylist\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-creating-an-interface-by-adding-elements-using-arraylist\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-creating-an-interface-by-adding-elements-using-arraylist\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Creating an Interface by adding elements using arraylist"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/10071","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=10071"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/10071\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=10071"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=10071"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=10071"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}