Closed ErSKS closed 7 years ago
Program package decodecrn;
import java.util.Scanner; import java.util.regex.Pattern;
/*
@author m-lan */ public class DecodeCrn {
/**
@milan604 Display useful error message of the input ABCDEF : It's not a CRN.
package stringinput;
import static java.lang.Integer.parseInt; import javax.swing.JOptionPane;
/*
@author Jagdish Duwal */ public class StringInput {
/**
@param args the command line arguments */ public static void main(String[] args) { int invalid=0; String roll; roll = JOptionPane.showInputDialog("Enter your full roll no(eg.710310)\n");
System.out.println(); for(int i = 0 ; i< roll.length(); i++){ char c = roll.charAt(i); int ascii = (int)c; //ascii value of 0 = 48 and 9 = 57 boolean len = roll.length()==6; boolean number = ascii< 48 || ascii> 57; if(!len || number ) { invalid++; } }
if(invalid == 0){ String batch; batch = roll.substring(0,2); System.out.printf("Batch: 20%s\n",batch);
String department;
department = roll.substring(2,4);
switch(parseInt(department)){
case 01:
department = "Civil Department";
break;
case 02:
department = "Architechture Department";
break;
case 03:
department = "Computer Department";
break;
case 04:
department = "Electronics Department";
break;
default:
department = "invalid input";
}
System.out.printf("Department: %s\n",department);
String rollno;
rollno = roll.substring(4);
System.out.printf("Roll no: %s\n",rollno);
}else{ JOptionPane.showMessageDialog(null,"Please Enter your CRN"); }
}
}
package day8tasklast;
import javax.swing.JOptionPane;
/*
@author DELL */ public class Day8tasklast {
/**
@param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here String crn; String department = "00"; int roll, depart, batch; while (true) { crn = JOptionPane.showInputDialog("Enter your Roll no.");
for (char c : crn.toCharArray()) {
if (!Character.isDigit(c)) {
JOptionPane.showMessageDialog(null, "Roll no should be in number", "Try again", 1);
crn = JOptionPane.showInputDialog("Enter your Roll no.");
break;
}
}
if (crn.length() != 6) {
JOptionPane.showMessageDialog(null, "Number should be of 6 digits", "Try again", 1);
continue;
}
batch = Integer.parseInt(crn.substring(0, 2));
if (batch > 74) {
JOptionPane.showMessageDialog(null, "Batch is grater than current year", "Invalid", 1);
continue;
}
depart = Integer.parseInt(crn.substring(2, 4));
if (depart == 1) {
department = "Civil";
} else if (depart == 2) {
department = "Architecture";
} else if (depart == 3) {
department = "Computer";
} else if (depart == 4) {
department = "Architecture";
} else {
JOptionPane.showMessageDialog(null, "Unknown department", "Invalid", 1);
continue;
}
roll = Integer.parseInt(crn.substring(4, 6));
if (roll >= 50 || roll < 1) {
JOptionPane.showMessageDialog(null, "Roll grater than 50 is not accepted", "Invalid", 1);
continue;
}
JOptionPane.showMessageDialog(null, "Batch=20" + batch + "\nDepartment=" + department + "\nRoll No.=" + roll, "Your info", 1);
break;
} }
/*
import static java.lang.Integer.parseInt; import javax.swing.JOptionPane;
/*
@author Anish */ public class Day8Task {
/**
@param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here String crn, b = "", d = "", r = ""; boolean f; do { f = true; crn = JOptionPane.showInputDialog("Enter your college roll number"); if (crn.length() != 6) { JOptionPane.showMessageDialog(null, "The entered data is not valid", "Error", 0); f = false; } else { for (int i = 0; i < crn.length(); i++) { char c = crn.charAt(i); if (!Character.isDigit(c)) { JOptionPane.showMessageDialog(null, "The entered data is not a number", "Error", 0); f = false; break; } } } if (f) { b = crn.substring(0, 2); d = crn.substring(2, 4); r = crn.substring(4); switch (d) { case "01": d = "Architecture"; break; case "02": d = "Civil"; break; case "03": d = "Computer"; break; case "04": d = "Electronics & Communication"; break; default: JOptionPane.showMessageDialog(null, "Incorrect department id", "Error", 0); f = false; break;
}
}
} while (!f); JOptionPane.showMessageDialog(null, "Batch of: 20" + b + "\nDepartment: " + d + "\nRoll: " + r);
}
}
/*
import java.util.Scanner; import javax.swing.JOptionPane;
/*
@author Dragon15423 */ public class Decode {
/**
@param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here
String roll = JOptionPane.showInputDialog("Enter your full roll no(eg.710310)\n"); System.out.println("Your input =" + roll);
if (roll.matches("[0-9]+") && roll.length() == 6) { System.out.println("Decoded Ouput"); System.out.println("Batch: 20" + roll.substring(0, 2)); System.out.print("Department: "); String com = roll.substring(2, 4);
switch (com) {
case "01":
System.out.println("Civil Engineering");
break;
case "02":
System.out.println("Architecture Engineering");
break;
case "03":
System.out.println("Computer Engineering");
break;
case "04":
System.out.println("Electronics Engineering");
break;
default:
System.out.println("not valid");
break;
}
System.out.println("Roll no.: " + roll.substring(4, 6));
} else { JOptionPane.showMessageDialog(null, "Not a valid CRN", "Error", 0); }
}
}
/*
import javax.swing.JOptionPane;
/*
@author LORDsajan */ public class DecodeCrn {
/**
@param args the command line arguments */ public static void main(String[] args) { String test2; OUTER: do { String s8; String dep; s8 = JOptionPane.showInputDialog("Enter College RollNo");
if (s8.length() == 6 && s8.matches("[0-9]+")) {
String s9 = s8.substring(0, 2);
String s10 = s8.substring(3, 4);
String s11 = s8.substring(4, 6);
switch (s10) {
case "1":
dep = "Civil Engineering";
break;
case "2":
dep = "Architect";
break;
case "3":
dep = "Computer Engineering";
break;
case "4":
dep = "Electronics Engineering";
break;
default:
System.out.println("invalid rollno");
break OUTER;
}
System.out.println("DECODED OUTPUT");
System.out.println("Batch: 20" + s9);
System.out.println("Department: " + dep);
System.out.println("RollNo: " + s11);
test2 = "true";
} else {
JOptionPane.showMessageDialog(null, "Invalid Input", "Oops", 2);
test2 = "false";
}
} while (test2.equals("false"));
}
}
package day08lastone;
import javax.swing.JOptionPane;
/*
@author Samikshya */ public class Day08Lastone {
/**
@param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here String crn; String department = "00"; int roll, depart, batch; while (true) { crn = JOptionPane.showInputDialog("Enter your Roll no.");
for (char c : crn.toCharArray()) {
if (!Character.isDigit(c)) {
JOptionPane.showMessageDialog(null, "Roll no should be in number", "Try again", 1);
crn = JOptionPane.showInputDialog("Enter your Roll no.");
break;
}
}
if (crn.length() != 6) {
JOptionPane.showMessageDialog(null, "Number should be of 6 digits", "Try again", 1);
continue;
}
batch = Integer.parseInt(crn.substring(0, 2));
if (batch > 74) {
JOptionPane.showMessageDialog(null, "Batch is grater than current year", "Invalid", 1);
continue;
}
depart = Integer.parseInt(crn.substring(2, 4));
if (depart == 1) {
department = "Civil";
} else if (depart == 2) {
department = "Architecture";
} else if (depart == 3) {
department = "Computer";
} else if (depart == 4) {
department = "Architecture";
} else {
JOptionPane.showMessageDialog(null, "Unknown department", "Invalid", 1);
continue;
}
roll = Integer.parseInt(crn.substring(4, 6));
if (roll >= 50 || roll < 1) {
JOptionPane.showMessageDialog(null, "Roll grater than 50 is not accepted", "Invalid", 1);
continue;
}
JOptionPane.showMessageDialog(null, "Batch=20" + batch + "\nDepartment=" + department + "\nRoll No.=" + roll, "Your info", 1);
break;
}
/*
import java.util.Scanner;
/*
@author dell */ public class ToIdentifyUser {
/**
@param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here String roll, batch, dept, dept_nm; int b; Scanner crn = new Scanner(System.in); System.out.println("enter the roll number: eg. 710340"); roll = crn.next(); while (true) { for (char c : roll.toCharArray()) { if (!Character.isDigit(c)) { System.out.println("input must be a number of 6 digits"); roll = crn.next(); break; } } if (roll.length() != 6) { System.out.println("enter the number of 6 digits"); roll = crn.next(); continue; }
batch = roll.substring(0, 2);
if (Integer.parseInt(batch) > 74) {
System.out.println("year greater than present year");
break;
}
dept = roll.substring(3, 4);
switch (dept) {
case "1":
dept_nm = "Civil department";
break;
case "2":
dept_nm = "ArchitectureDepartment";
break;
case "3":
dept_nm = "Computer Department";
break;
case "4":
dept_nm = "Electronics Department";
break;
default:
dept_nm = "Not in the list";
break;
}
String r = roll.substring(4, 6);
if (Integer.parseInt(r) >= 50 || Integer.parseInt(r) < 1) {
System.out.println("invalid roll");
break;
}
System.out.println("Batch:20" + batch);
System.out.println("department:" + dept_nm);
System.out.println("your roll number is:" + r);
break;
} } }
/*
import javax.swing.JOptionPane;
/*
@author kajal */ public class Day8Task9 {
/**
@param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here String crn, department = "00"; int batch, roll, depart;
crn = JOptionPane.showInputDialog("Enter your roll number:"); if (crn.length() != 6) { JOptionPane.showInputDialog("Enter your correct roll number:"); }
for (char c : crn.toCharArray()) { if (!Character.isDigit(c)) { crn = JOptionPane.showInputDialog("Enter your correct Roll no."); continue; } }
batch = Integer.parseInt(crn.substring(0, 2)); if (batch > 74) { JOptionPane.showInputDialog("Enter the correct roll no:"); }
depart = Integer.parseInt(crn.substring(2, 4)); if (depart == 1) { department = "Civil"; } else if (depart == 2) { department = "Architecture"; } else if (depart == 3) { department = "Computer"; } else if (depart == 4) { department = "Architecture"; } else { JOptionPane.showMessageDialog(null, "Unknown department", "Invalid", 1);
}
roll = Integer.parseInt(crn.substring(4, 6)); if (roll >= 50 || roll < 1) { JOptionPane.showMessageDialog(null, "Roll grater than 50 is not accepted", "Invalid", 1);
} JOptionPane.showMessageDialog(null, "Batch = 20" + batch + "\nDepartment=" + department + "\nRoll No.= " + roll, "crn", 1); } }
/*
import javax.swing.JOptionPane;
/*
@author mahesh */ public class DecodeCRN {
/**
}
}
package day8a2;
import javax.swing.JOptionPane;
/*
@author Awal */ public class Day8a2 {
/**
@param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here String crn = JOptionPane.showInputDialog("Enter your full roll no(eg.710101)\n"); System.out.println("Your input =" + crn);
if (crn.matches("[0-9]+") && crn.length() == 6) { System.out.println("Decoded Ouput"); System.out.println("Batch: 20" + crn.substring(0, 2)); System.out.print("Department: "); String s = crn.substring(2, 4);
switch (s) {
case "01":
System.out.println("Architecture Engineering");
break;
case "02":
System.out.println("Civil Engineering");
break;
case "03":
System.out.println("Computer Engineering");
break;
case "04":
System.out.println("Electronics Engineering");
break;
default:
System.out.println("not valid");
break;
}
System.out.println("Roll no.: " + crn.substring(4, 6));
} else { JOptionPane.showMessageDialog(null,"Roll no should be in numbers"); }
}
}
/*
import java.util.Scanner; import javax.swing.JOptionPane;
/*
@author DELL */ public class Decode {
/**
OUTPUT
public static void main(String[] args) { // TODO code application logic here String str; int cg, ch, rn;
str = JOptionPane.show
String str; int cg, ch, rn;
str = JOptionPane.showInputDialog("Enter your id number");
if (str.length() == 6) {
cg = Integer.parseInt(str.substring(0, 2));
System.out.println("Batch:20" + cg);
ch = Integer.parseInt(str.substring(2, 4));
if (ch == 01) {
System.out.println("Department:Civil Engineering");
} else if (ch == 02) {
System.out.println("Department:Architecture");
} else if (ch == 03) {
System.out.println("Department:Computer Engineering");
} else if (ch == 04) {
System.out.println("Department:Electronics Engineering");
}
rn = Integer.parseInt(str.substring(4, 6));
System.out.println("Roll No:" + rn);
String sp = "true";
} else {
JOptionPane.showMessageDialog(null, "not valid");
}
}
I saw your coding diversity. Try to understand and write as clean & atomic as you can. Still I found error on your code, check your solution again.
@milan604 7103ab ab is not a roll number @jagdish4249 Ok @rivab 7103ab - java.lang.NumberFormatException @karmi214 Ok Susan Ok @sajanbasnet75 Ok @kajalmaharjan After 1st mistake attempt, your code doesn't function well
Note:- Try to find out bug of your friend's code too.
Develop a java program to display Batch, Department & Roll Number of user input. User input should be 6-character string such as 710339, 650101, etc.
Example:
User Input: 71AB39 - Not a valid CRN User Input: 7103396 - Not a valid CRN User Input: Nepal - Not a valid CRN User Input: 710339 - Valid CRN
Decoded Output
Batch: 2071 Department: Computer Engineering Roll No.: 39