how to add try and catch validation and how to fix my switch, do-while error java -
i cant post code in here not sure why error post on reddit
https://www.reddit.com/r/javahelp/comments/3izvy2/how_to_add_try_and_catch_validation_and_how_to/
your try/catch syntax fine, what's problem?
however, do/while wrong, see while way down there, remove last curly bracket , put right before while:
do{ try{ system.out.println("choose option"); system.out.println(" 1. create list of used car"); system.out.println(" 2. print list of used car"); system.out.println(" 3. search "); system.out.println(" 4. exit"); int choose = read.nextint(); if ( choose <= 4){ throw new exception(); } }catch (exception e){ system.out.println("please enter input option 1-4"); ..rest of code... }while(choose <= 4);
and in switch, choose
not avaliable - choose
local variable try/catch only, nothing other try/catch can access it. best make choose
global variable putting @ top of do:
do{ int choose; ..blah blah.. }
and reference without int - choose
:
choose = read.nextint();
finally, need break
@ end of every case
, , what's point of return
s?:
case 1: for(int i=0; i<a.length; i++){ system.out.print("enter model: "); model = read.next(); system.out.print("enter plate number: "); plateno = read.next(); system.out.print("enter manufactured year: "); manufacturedyear = read.nextint(); system.out.print("enter transmission type: "); transmissiontype = read.next(); system.out.print("enter color: "); color = read.next(); carlist used = new carlist(model, plateno, manufacturedyear, transmissiontype, color); a[i] = used; return; } break; ...keep on going....
you shouldn't rely on others fix simple syntax problems, don't panic when error, go through code , learn how debug messages!
Comments
Post a Comment