Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Alex
return code
1 Answer(s)      5 years ago
Posted in : Java Beginners



Advertisement
View Answers

October 7, 2009 at 5:41 PM


Hi Friend,

Try the following code:

/*import java.util.Scanner;
public class RegistrationSystem {

public static void main(String[]args){
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();
}
}
}
*/
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.println("4. Exit");
boolean quit = false;
do{
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());
}
break;
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);
break;
case 3:
System.out.println("Id Name");
for (Student s : list){
System.out.println(s.getId()+" " +s.getName());
}
break;
case 4:
quit = true;
break;
default:
System.out.println("Invalid Entry!");
}
}

while (!quit);
}
}

Thanks


Related Tutorials/Questions & Answers:
return code - Java Beginners
: "); String name = scan.next(); break;//What code to use to return to main menu after...return code  import java.util.Scanner; public class... the following code: /*import java.util.Scanner; public class
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
Advertisements
What it will return ..... ?
What it will return ..... ?   import java.util.*; public class Name { private final String first, last; public Name(String first, String last...) { if (!(o instanceof Name)) return false; Name n = (Name)o; return n.first.equals
return item in jquery
return item in jquery  How to return items/variables in JQuery?   See the code below to find out how to return an Item in Jquery: function... for the variable item } return item; } var item = findItem(); // do
JDialog return value to JDialog ????
JDialog return value to JDialog ????  hello all.... legend. JD1 = JDialog1 JD2 = JDialog2 JD1 open JD2......JD2 has any values, how I return this values to JD1 ??? [code] // JD1 open JD2 JD2 jd2 = new JD2(null
uikeyboard disable return key
uikeyboard disable return key  uikeyboard - hot to disable return key
use of return statement
use of return statement  what is the use of return statement
function to return value in java
function to return value in java  How to return maximum value in java?   Return Value in Java
Return Array in PHP
Return Array in PHP  my question is how to return Array from PHP script
Java Method Return Value
Java Method Return Value       Java  method Return Value return to the code when... value. In case you try to get the return value from void .the code show you
JDialog return value to JDialog ????
JDialog return value to JDialog ????  hello all.... legend. JD1 = JDialog1 JD2 = JDialog2 JD1 open JD2......JD2 has any values, how I return...); jd2.setVisible(true); //now I need that JD2 return a value to JD1 JD2 make
php return true false
php return true false  i wanted to create php function that returns true/false
uikeyboard done button/return button
uikeyboard done button/return button  Hi everyone!!! Just worried about ..how to return the UIKeyboard on done or return button click in my iPhone application. Thanks   Hi, Find the given code that will allow you
Return Java Keyword
Return Java Keyword       The return is a keyword defined in the java programming language. Keywords... in java programming language likewise the return keyword indicates the following
Search and return lines of text file
Search and return lines of text file  I wrote the following code...)) { System.out.println(line); RL = line; //return "Lines: "+RL; (if I write... (IOException ex) { ex.printStackTrace(); } return "Lines: "+RL
Return Statement in PHP
In PHP Return is a Statment that returns value back to the calling program. For example if the Return Statment is called from within a function it will end the excution on it(return statment) and will return the value or argument back
PHP Functions and Return values
PHP Functions and Return values A function is the a block of code whom you can... the code into a function. A function will only be executed by a call... of the function is given below : function functionName() { code to be executed
return 0 vs exit 0
return 0 vs exit 0  what is the difference between return 0 and exit 0 in c? i could not find any difference in their behaviour (both terminates the process execution) in a program
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
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
return the position of last occurrence of an element
return the position of last occurrence of an element  A method " findLast(E element) " returns the position of the last occurrence of the given element. If this element is not in the list, then the null reference should
return the position of last occurrence of an element
return the position of last occurrence of an element  A method " findLast(E element) " returns the position of the last occurrence of the given element. If this element is not in the list, then the null reference should
Return Value from One Form
Return Value from One Form  I have two buttons in main form client and bank.when i click client button new form will open, in this dedupe button is there.when i click dedupe button another form will open. i want to get a field
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 trying to get a string from a JTextField so that I can compare it with another String using either compare or equals or compareTo methods of the String class
Java error missing return statement
, then you must specify the return type in it. The given below code is missing a return statement in the non-void method so, whenever the compiler execute the code the code returns a missing return statement error. There are two way to resolve
carriage return with javascript - JSP-Interview Questions
carriage return with javascript  Dear, Please in one webpage, I need a carriage return in javsacript code \r. I use it BUT no effects. Can you help me. Regards
PHP Return Statements
PHP Returning Statement Values: PHP Return statement is used to return a value.... In PHP we can return values, arrays, or object. If the function is called from within the function then execution will immediately stops, return is also used
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
File download return value - Java Beginners
File download return value  How to get the return value of Open/Save/Cancel buttons in a File Download pop up using javascript
SQL select statement doesn't return any rows,
SQL select statement doesn't return any rows,  When an SQL select statement doesn't return any rows, is an SQLException thrown
Advertisements
 

 

 

DMCA.com