how to return to main menu after adding all the info.

how to return to main menu after adding all the info.

View Answers

October 6, 2009 at 3:25 PM

Hi Friend,

Try the following code:

import java.io.*;
import java.util.*;

class Student{
public int id;
public String name;

public Student(){}
public Student(int id, String name) {
super();
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
}
public class RegistrationSystem {

public static void main(String[] args) throws Exception {
List<Student> list = new ArrayList<Student>();
list.add(new Student(1, "A"));
list.add(new Student(2, "B"));
list.add(new Student(3, "C"));
list.add(new Student(4, "D"));

Scanner scan = new Scanner(System.in);
int menu = 0;
System.out.println("School Registration System Main Menu");
System.out.println();
System.out.println("1. Add a student");
System.out.println("2. Remove a student");
System.out.println("3. Display student list");

System.out.print("Please enter your choice: ");
menu = scan.nextInt();
System.out.println();

switch(menu) {
case 1:
System.out.print("Enter student ID: ");
int ID = scan.nextInt();
System.out.print("Enter your name: ");
String name= scan.next();
list.add(new Student(ID,name));
for (Student s : list){
System.out.println(s.getId()+" " +s.getName());
}
case 2:
System.out.print("Enter Student id to remove the student from list: ");
int id = scan.nextInt();
int i=id-1;
list.remove(i);
case 3:
System.out.println("Id Name");
for (Student s : list){
System.out.println(s.getId()+" " +s.getName());
}
}
}
}

Thanks









Related Tutorials/Questions & Answers:
how to return to main menu after adding all the info. - Java Beginners
how to return to main menu after adding all the info.  import...; System.out.println("School Registration System Main Menu...("School Registration System Main Menu"); System.out.println(); System.out.println
how update JTable after adding a row into database
how update JTable after adding a row into database  J have two... in JTable, and it's OK, but after adding a row into database table does't update. How update JTable after adding a row into database? package djile pak.java
Advertisements
ModuleNotFoundError: No module named 'odoo9-addon-menu-technical-info'
: ModuleNotFoundError: No module named 'odoo9-addon-menu-technical-info' How to remove... with following command: pip install odoo9-addon-menu-technical-info After...ModuleNotFoundError: No module named 'odoo9-addon-menu-technical-info
What is the return type of the main method?
What is the return type of the main method?  hi, What is the return type of the main method? thanks   Hi, In the java programming the Main() method doesn't return anything hence declared void. In Java, you need
How to Create Animated Main Menu Application with Java Swnig Buttons - Java Beginners
How to Create Animated Main Menu Application with Java Swnig Buttons  Hello sir I want to display Main Menu after Log in i have created Log in Form but I want More attractive Animated Main Menu which includes Following
i am getting an error in adding a menu item to a menu.
i am getting an error in adding a menu item to a menu.   i am not able to execute the menu program. i am getting an error at menu.add(menuitem); it says add method is undefined for type menu. but as far as i know that is only way
Adding pop up menu on headlines.
Adding pop up menu on Headlines Here you will learn sticking a pop up menu...() { if (window.mm_menu_0715193556_0) return; window.mm_menu_0715193556_0 = new Menu("... on to pop up menu, it opens the list of the menu automatically. For generating
return all rows mysql php
return all rows mysql php  How to find or return results that are not available in another table .. using join method in PHP and MYSql.   SELECT * FROM Declined LEFT JOIN Request ON Declined.RequestID
ModuleNotFoundError: No module named 'ip-info-all'
'ip-info-all' How to remove the ModuleNotFoundError: No module named 'ip... with following command: pip install ip-info-all After the installation of ip...ModuleNotFoundError: No module named 'ip-info-all'  Hi, My Python
ModuleNotFoundError: No module named 'ip-info-all'
'ip-info-all' How to remove the ModuleNotFoundError: No module named 'ip... with following command: pip install ip-info-all After the installation of ip...ModuleNotFoundError: No module named 'ip-info-all'  Hi, My Python
ModuleNotFoundError: No module named 'ip-info-all'
'ip-info-all' How to remove the ModuleNotFoundError: No module named 'ip... with following command: pip install ip-info-all After the installation of ip...ModuleNotFoundError: No module named 'ip-info-all'  Hi, My Python
common Menu bar(toolBar) at the top of all view
common Menu bar(toolBar) at the top of all view  I creat on login page and after sign in I move to next page. Now I want to add menu bar at the top of my all view. Any one have any idea abt how to do
in string how will write the return statement..........?
in string how will write the return statement..........?  import java.util.Scanner; class BinaryConversion12{ static int j=1; static int l=1; public static void main(String args[]){ int i=Integer.parseInt(args[0
How to return a string from a JTextField
How to return a string from a JTextField  Hi, Am new to java, and am.... The problem is i have no clue how to get the very string i need because i think... { public static void main(String[] args) { JFrame f=new JFrame
ModuleNotFoundError: No module named 'cloudgenix_get_all_interface_info'
: ModuleNotFoundError: No module named 'cloudgenix_get_all_interface_info' How to remove... After the installation of cloudgenix_get_all_interface_info python library...ModuleNotFoundError: No module named 'cloudgenix_get_all_interface_info
ModuleNotFoundError: No module named 'cloudgenix_get_all_interface_info'
: ModuleNotFoundError: No module named 'cloudgenix_get_all_interface_info' How to remove... After the installation of cloudgenix_get_all_interface_info python library...ModuleNotFoundError: No module named 'cloudgenix_get_all_interface_info
How to refresh a jTable On adding or deleting record ....
How to refresh a jTable On adding or deleting record ....   Hii... from same panel and i want jtable to be refreshed after every addition... that updates the jtable automatically after some interval of time. import
Java Method Return Multiple Values
Java Method Return Multiple Values In this section we will learn about how a method can return multiple values in Java. This example explains you how a multiple values can be return by a method. This example explains you all
How to return dictionary keys as a list in Python
How to return dictionary keys as a list in Python  Hi, I want to access the keys of dictionary as list in Python program. Here is dictionary data...:"Seven", 8:"Eight", 9:"Nine", 10:"Ten"} print(word_dict) How to get all keys
How to return dictionary keys as a list in Python
How to return dictionary keys as a list in Python  Hi, I want to access the keys of dictionary as list in Python program. Here is dictionary data...:"Seven", 8:"Eight", 9:"Nine", 10:"Ten"} print(word_dict) How to get all keys
Should a main method be compulsorily declared in all java classes?
Should a main method be compulsorily declared in all java classes?  hi, Should a main method be compulsorily declared in all java classes? thanks... in all java classes. Where as the main method we should be defined only if the source
How to create dynamic buttons for adding products on a cart.
How to create dynamic buttons for adding products on a cart.  Hi. I... dynamic products from a database, and i would like to know how to group this products... containing the main table --> <div id="table"> <table
how to write a query for adding records in database
how to write a query for adding records in database  How write fire query in JSP for adding records in database
How to prevent adding duplicate items to the shopping cart
How to prevent adding duplicate items to the shopping cart  this is saved as index.php <html> <head> <title>Catalog</title> <link rel="stylesheet" href="mm_travel2.css" type="text/css" />
how to solve the nullPointer Exception in main - Java Beginners
how to solve the nullPointer Exception in main  New to Java ,pls help me how fix Null pointer Exception in main: two files , split .java another... main(String[] args) { String actualState; String str1 = "s0;input
menu
menu  Hi,i want write the menu that repeat several time
menu
menu  fibonaci & prime no. display in menu driven in java programme
How to return multiple values from a method - Java Beginners
How to return multiple values from a method  I came the following method "How do I return multiple values from a method?" posted elsewhere... result. Can someone tell me how my Driver.java program [see below] should
How to return multiple values from a method - Java Beginners
How to return multiple values from a method  I came the following method "How do I return multiple values from a method?" posted elsewhere... result. Can someone tell me how my Driver.java program [see below] should
return code - Java Beginners
: "); String name = scan.next(); break;//What code to use to return to main menu after...(System.in); int menu = 0; System.out.println("School Registration System Main...(System.in); int menu = 0; System.out.println("School Registration System Main
menu with scrollbar
(true); frame.setSize(500,500); } public static void main(String arg[]) { menu m...menu with scrollbar  I want to use MenuBar with Scrollbar. I tried it. I dont know how to do it. so please help me. The program should be.... 1.add
Return keyword
Return keyword  how do we use return in methods?   Java use of return keyword import java.util.*; public class ReverseString{ public...).reverse().toString(); return rev; } public static void main(String
I need to join three tables and return data that may not be in all three tables
I need to join three tables and return data that may not be in all three tables  How do I join three tables and return information even... that are in all three tables. How do I get all the information for students from table
How to Differenciate Main Thread and Child Thread in Java
How to Differenciate Main Thread and Child Thread in Java  hi... Main Thread and Java Child Thread. Please Suggest any example or online link... Language. These are Java Main Thread and the Child Thread. The Below reference
Menu
Menu  Pl make a program which generates the following output. "Select from this menu" 1. Array 2. Stack 3. Queue. 4. Exit. If users press 1.... for traversing press 4. for sortiing. press 5. for go back. All the will give
How to Creating Pop Up Menu in PHP?
How to Creating Pop Up Menu in PHP?  Hi, I am a beginner in the PHP Application. Can somebody give an example of how to creating pop up Menu in PHP. Please feel free to suggestion........ Thanks
How to remove the background color of bootstrap menu bar?
How to remove the background color of bootstrap menu bar?  Hi, What css can be used to remove the color of bootstrap menu bar? thanks   ... the background image for the nabvar in a bootstrap based menu. Thanks
How can I go to ISRO after BSc?
How can I go to ISRO after BSc?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: How can... that I can learn the topic "How can I go to ISRO after BSc?". Also
how to disable submit button after login in jsp
how to disable submit button after login in jsp  Hi, I have... on the back button in browser it stars displaying login page. How to prevent this? how to disable submit button after login in jsp? Thanks   Hi, You can
How to save image after edit in php
How to save image after edit in php  Hello, I have create a simple image editor with the effected of brightness, contrast, and desaturat etc. I have... successfully but i don't know how to replace orignal image with the effects. please
Version of struts-menu>struts-menu dependency
List of Version of struts-menu>struts-menu dependency
adding loop
getPrice(){ return price; } public static void main(String...adding loop  Hi I have a program that is not compiling when I add...; } public String getCode(){ return code; } public
Maven dependency for struts-menu - struts-menu version 1.2 is released. Learn to use struts-menu version 1.2 in Maven based Java projects
on Maven and Gradle. How to use  struts-menu - struts-menu version 1.2... be used to see the dependency tree of the given project. After adding the Maven...Maven dependency for  struts-menu  - Version 1.2 of struts-menu
Maven dependency for struts-menu - struts-menu version 1.2-dev is released. Learn to use struts-menu version 1.2-dev in Maven based Java projects
project if it is based on Maven and Gradle. How to use  struts-menu - struts... tool can be used to see the dependency tree of the given project. After adding...Maven dependency for  struts-menu  - Version 1.2-dev of struts-menu
How to get javascript function return value in xsl - XML
How to get javascript function return value in xsl  Hi friends , i have a doubt on xsl, i want to know how to get value from javascript function to xsl variable with small piece of code,i need immediately , if anybody plz send ur
How to change image size before adding to mysql using jsp
How to change image size before adding to mysql using jsp  I want to upload an image to MySQL DB, before inserting the image I want to change the image size as per defined by me and then I want to store that image into my DB
how to get harddisk info using S.M.A.R.T using java
how to get harddisk info using S.M.A.R.T using java   how to get harddisk info using S.M.A.R.T using java
main() method
main() method  Can we define two main() methods having same parameter but with different return type in a program
How to Use Java Functions In EL
and static. It should have a non- void type return type. After all, its all the matter... folder. After all this class is not for everyone to see. The TLD file: TLD...How to Use Java Functions In EL     
How I call the function union from the main - Java Interview Questions
How I call the function union from the main  Please, from public static void main(String[] args) I would like to call the function union and I... declared in main function //------------------------------- package model

Ads