Design and implement a Java program that get trafficviolation number and output
ID: 3617812 • Letter: D
Question
Design and implement a Java program that get trafficviolation number and output the traffic violation number and outputthe traffic violation title and price based on the following table: NumberTitlePenalty 1 Traffic Signal ViolationRs 300 2 Improper Lights Rs800 3 Speed Limit ViolationRs 500 4 Sudden Start-up Rs200 5 Violation of STOP signRs 200 Also implement this program with making Class and methods init. Note Use JOptionPane in input andoutput You can use Keyboard class as well Use Integer.paraseInt() method to convert from string tointNumberTitlePenalty 1 Traffic Signal ViolationRs 300 2 Improper Lights Rs800 3 Speed Limit ViolationRs 500 4 Sudden Start-up Rs200 5 Violation of STOP signRs 200 Also implement this program with making Class and methods init. Note Use JOptionPane in input andoutput You can use Keyboard class as well Use Integer.paraseInt() method to convert from string toint
Explanation / Answer
importjavax.swing.*; classTrafficViolation { staticvoid getTrafficViolationID(int n) { switch(n) { case 1: JOptionPane.showMessageDialog(null,"TrafficSignal Violation Rs 300"); break; case 2: JOptionPane.showMessageDialog(null,"Improper Lights Rs 800"); break; case 3: JOptionPane.showMessageDialog(null,"SpeedLimit Violation Rs 500"); break; case 4: JOptionPane.showMessageDialog(null,"SuddenStart-up Rs 200"); break; case 5: JOptionPane.showMessageDialog(null,"Violationof STOP sign Rs 200"); break; default: if(n != 0) JOptionPane.showMessageDialog(null,"InvalidInput"); break; } } } public classTrafficViolationTest { public staticvoid main(String[] args) { int number; do{ number= Integer.parseInt(JOptionPane.showInputDialog("Please Enter Traffic Violation Number and zero toQuite")); TrafficViolation.getTrafficViolationID(number); }while(number != 0); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.