Alex
how to return to main menu after adding all the info.
1 Answer(s)      5 years and 11 months ago
Posted in : Java Beginners
Advertisement
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
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
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
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
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
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
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
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
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
menu
menu  fibonaci & prime no. display in menu driven in java programme
menu
menu  Hi,i want write the menu that repeat several time
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.... All the will give the user. Same as above. If user press 2. Stack
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 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
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
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.... How do I get all the information for students from table A and table B even
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 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
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
menu with scrollbar
); } public static void main(String arg[]) { menu m=new menu(); } }   Hi... static void main(String[]args){ menu me=new menu(); } } Thanks...menu with scrollbar  I want to use MenuBar with Scrollbar. I tried
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... in Java Programming Language. These are Java Main Thread and the Child Thread
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 backup a selected file from the dropDown Menu in JSP?
How to backup a selected file from the dropDown Menu in JSP?  I am trying to create a dropdown menu list for some type of files contained ina directory and upon selecting one, I'll have a click button backFile to copy the selcted
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     
date_sun_info
  date_sun_info() Function of PHP date_sun_info function returns... on success or False on failure.  Description on PHP date_sun_info() Function array date_sun_info ( int $time , float $latitude , float $longitude
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