Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ContainsMethod
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { static Customer cm = new Customer(); static Route ro = new Route(); static Scanner grab = new Scanner(System.in); public static void main(String[] args) { ro.makeRoute(); int index=ro.getIndex("Sarita Vihar"); System.out.println(index); } public static void display() { System.out.println("\n----------------------------------------------\n"); System.out.println("Name: " + cm.getCname()); System.out.println("Mobile no. - " + cm.getNumber()); System.out.println("Selected vhicle type : " + cm.getVanType()); System.out.println("Travelling from \"" + cm.getStart() + "\" to \"" + cm.getDest() + "\"."); System.out.println("Date of Travel : " + cm.getDot()); System.out.println("Fare to pay : " + cm.getAmount()); System.out.println("\n-----------------------------------------------\n"); } } class Route { private ArrayList<String> routeList = new ArrayList<String>(); public void makeRoute() { routeList.add("Sarai"); routeList.add("Badarpur"); routeList.add("Tugalagabad"); routeList.add("Mohan Estate"); routeList.add("Sarita Vihar"); routeList.add("Jasola Apollo"); routeList.add("Harkesh Nagar Okhla"); routeList.add("Govind Puuri"); routeList.add("Kalkaji"); routeList.add("JLN"); displayRoute(routeList); } public void displayRoute(ArrayList<String> routeList) { System.out.println("##ROUTE MAP BELOW##\n\n"); for (int counter = 0; counter < routeList.size(); counter++) { System.out.print(routeList.get(counter)); if (counter < 9) { System.out.print("--"); } } System.out.println(); System.out.println("\nVAN TYPES AVAILABLE: 1:[MICRO], 2:[MINI] & 3:[FULL]"); } public int getIndex(String str) { System.out.println("getIndex() function just sat on stack."); if (routeList.contains(str)) { System.out.println("Running if code."); int idx = routeList.indexOf(str); return idx; } else { System.out.println("Running else code."); return -1; } } } class Customer { private String cname; private String cmobile; private String vehicletype; private float netBillAmount = 40.00F; private String dot; private String start; private String destination; private String numPattern = "\\d{10}"; Route ro = new Route(); //Getter mehthods here public String getCname() { return cname; } public String getNumber() { return cmobile; } public String getVanType() { return vehicletype; } public float getAmount() { return netBillAmount; } public String getDot() { return dot; } public String getStart() { return start; } public String getDest() { return destination; } //Setter methods here public int setName(String str) { if (!(str.equals("null"))) { cname = str; return 0; } else { System.out.println("No name to store."); return 1; } } public void setNumber(String num) { if (num.matches(numPattern)) { cmobile = num; } else { System.out.println("Invalid mobile number.Try again"); String some; java.util.Scanner scanner = new java.util.Scanner(System.in); some = scanner.nextLine(); scanner.close(); this.setNumber(some); } } public int setVanType(String str) { if (str.equals("1") || str.equals("2") || str.equals("3")) { if (str.equals("1")) { vehicletype = "MICRO"; System.out.println(vehicletype + " selected"); } else if (str.equals("2")) { vehicletype = "MINI"; System.out.println(vehicletype + " selected."); } else { vehicletype = "FULL"; System.out.println(vehicletype + " selected"); } return 0; } else { System.out.println("Sorry! Option out of bounds."); return 1; } } public int setStart(String str) { start = str; return 0; } public int setDestination(String str) { destination = str; return 0; } public int setAmount() { System.out.println("Start of Journey = " + this.getStart()); System.out.println("End of Journey = " + this.getDest()); int temp = ro.getIndex(this.getDest()) - ro.getIndex(this.getStart()); System.out.println("Stations in way = " + temp); netBillAmount += temp * 20; return 0; } public int setDOT(String date) { dot = date; return 0; } }
run
|
edit
|
history
|
help
0
boundary vs core
polymorphic mapper
Minimum Vertices to Traverse Directed Graph
bookstore
Meena
Javaprog.java
Item battle rolyal
Nick-test
Print Longest String
Java Replace Method