+ 1

can anyone help me in this program for sorting part and even correct my mistakes if found because i m doing it first time

import java.util.*; import java.util.Scanner; public class project1 { static List<String> input=new ArrayList<String>(); public static void main(String[] args) { Scanner in=new Scanner(System.in); boolean y=true; do { System.out.println("Enter 1 to add a student personal details in list\n2 to edit details\n3 to search"); System.out.println("4 to delete\n5 to sort\n6 to print list\n7 to exit"); System.out.println("enter your choice"); int choice=in.nextInt(); switch(choice) { case 1: insert(); break; case 2: edit(); break; case 3: search(); break; case 4: delete(); break; case 5: sort(); break; case 6: print(); break; case 7: toexit(); break; default: System.out.println("bad input"); break; } System.out.println("want to process more? y/n"); String x=in.next(); char ch=x.charAt(0); if( ch=='n') y=false; } while(y!=false); } static public void insert() { Scanner in=new Scanner(System.in); boolean y=true; do { do{ int i=0; System.out.println("position/index:"+i); { System.out.println("enter student's name"); String name=in.n

26th Oct 2017, 1:46 PM
aasthasavla
aasthasavla - avatar
15 Antworten
+ 2
No adding a file. Copy/paste in the code pkayground and save. Next share code from your account
26th Oct 2017, 2:03 PM
Daniel
Daniel - avatar
+ 1
You're missing stuff. It would be better to insert a link to the code. However, I did notice you asked if they wish to process more. Given you have an exit option, it is redundant to do so. I'd get upset constantly getting asked that question.
26th Oct 2017, 1:22 PM
John Wells
John Wells - avatar
+ 1
input.add(name); System.out.println("enter standard"); String std=in.nextLine(); input.add(std); System.out.println("enter phone number"); String num=in.nextLine(); input.add(num); System.out.println("want to insert more?y/n"); String x=in.next(); char ch=x.charAt(0); if( ch=='n') y=false; } i++; } while(y==true); } while(y!=false); } static public void edit() { Scanner in=new Scanner(System.in); String num2;int num1; System.out.println("enter name/phone no/rollno you want to replace or update "); num2=in.nextLine(); try{ System.out.println("enter position you want to edit"); num1=in.nextInt(); input.set(num1, num2); }catch(IndexOutOfBoundsException e){ System.err.println("caught IndexOutOfBoundsException: specified position is empty "+e.getMessage()); } } static public void search() { Scanner in=new Scanner(System.in); int i,a=0,k=0; String st; String name[]=new String[30]; for(i=0;i<30;i++) { System.out.println("Enter your name"); name[i]=in.nextLine(); } System.out.println("enter name to search"); st=in.nextLine(); for(i=0;i<30;i++) { if(name[i].equals(st)) { k=1; a=i; } } if(k==1) System.out.println("details are in list"); else System.out.println("name not found
26th Oct 2017, 1:42 PM
aasthasavla
aasthasavla - avatar
+ 1
static public void delete() { Scanner in=new Scanner(System.in); System.out.println("enter position you want to delete"); int num=in.nextInt(); input.remove(num); } static public void sort() { } static public void print() { if(input.isEmpty()) System.out.println("list is empty "); else System.out.println("members of lists are:"); for(int i=0 ; i<input.size();i++) System.out.println("index "+i+" : "+ input.get(i)+" "); } static public void toexit() { System.exit(0); } }
26th Oct 2017, 1:43 PM
aasthasavla
aasthasavla - avatar
+ 1
Put your program into a source code file and post a link here. It is too big to deal with like this.
26th Oct 2017, 1:44 PM
John Wells
John Wells - avatar
+ 1
ok thanks
26th Oct 2017, 1:46 PM
aasthasavla
aasthasavla - avatar
0
Share your code
26th Oct 2017, 1:28 PM
Daniel
Daniel - avatar
0
i m really sorry i didn't notice i have messaged only half program
26th Oct 2017, 1:41 PM
aasthasavla
aasthasavla - avatar
0
there is no option of adding a file what should i do??
26th Oct 2017, 2:02 PM
aasthasavla
aasthasavla - avatar
0
post web link.
26th Oct 2017, 2:03 PM
John Wells
John Wells - avatar
0
you using web browser or app?
26th Oct 2017, 2:04 PM
John Wells
John Wells - avatar
0
web browser
26th Oct 2017, 2:08 PM
aasthasavla
aasthasavla - avatar
0
Have placed source in code playground?
26th Oct 2017, 2:09 PM
John Wells
John Wells - avatar
0
its not complete so how could i post it
27th Oct 2017, 11:30 AM
aasthasavla
aasthasavla - avatar
0
You can post a link to private code. Put in playground, leave private, hit share, copy the link, and post it here.
27th Oct 2017, 11:37 AM
John Wells
John Wells - avatar