Results 1 to 1 of 1
- 10-21-2011, 12:59 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 1
- Rep Power
- 0
Making string insensitive to upper or lower case
I have two questions. I finally realized that if I just use ignore case under if parentheses it does work. But is it possible to acquire the same results using the switch statement?
My second question is for variables s1 and s4 . if i kept s1 = "South Bend". and when I entered in whatever case, it wouldn't work because of the space between south and bend. How do I fix that portion. Thank you for time and effort in resolving my issue.
import java.util.*;
import java.text.DecimalFormat;
public class TicketCalc {
public static void main(String[] args){
Scanner s = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("0.00");
//Declare Stations
String s1 = new String("South"); //variable is actually South Bend
String s2 = new String("Dunes");
String s3 = new String("Gary");
String s4 = new String("East"); //variable is actually East Chicago
String s5 = new String("Hammond");
System.out.println("Enter one of the stops <South Bend, Dunes, Gary, East Chicago, or Hammond>: ");
//Input
String stop = s.next();
//arguements
double price = 0;
double single = 0;
double ten = 0;
double monthly = 0;
/*** switch (stop){
case "south":
single = 8.10;
ten = single*10*0.98;
monthly = single*30*0.95;
break;
case "dunes":
single = 7.30;
ten = single*0.98*10;
monthly = single*30*0.95;
break;
case "gary":
single = 4.60;
ten = single*0.98*10;
monthly = single*30*0.95;
break;
case "east":
single = 4.00;
ten = single*0.98*10;
monthly = single*30*0.95;
break;
case "hammond":
single = 3.75;
ten = single*0.98*10;
monthly = single*30*0.95;
break;
} ***/
//output
if (stop.equalsIgnoreCase(s1)) {
single = 8.10;
ten = single*10*0.98;
monthly = single*30*0.95;
System.out.println("\n\nFares from South Bend to Chicago are: ");
System.out.println("\nSingle - Ride Ticket: " +"$" +df.format(single));
System.out.println("Ten - Ride Ticket: " +"$" +df.format(ten));
System.out.println("Monthly pass: " +"$" +df.format(monthly));
System.out.println("\n");
}//end if
else if (stop.equalsIgnoreCase(s2)) {
single = 7.30;
ten = single*0.98*10;
monthly = single*30*0.95;
System.out.println("\n\nFares from South Bend to Chicago are: ");
System.out.println("\nSingle - Ride Ticket: " +"$" +df.format(single));
System.out.println("Ten - Ride Ticket: " +"$" +df.format(ten));
System.out.println("Monthly pass: " +"$" +df.format(monthly));
System.out.println("\n");
}//end if
else if (stop.equalsIgnoreCase(s3)) {
single = 4.60;
ten = single*0.98*10;
monthly = single*30*0.95;
System.out.println("\n\nFares from South Bend to Chicago are: ");
System.out.println("\nSingle - Ride Ticket: " +"$" +df.format(single));
System.out.println("Ten - Ride Ticket: " +"$" +df.format(ten));
System.out.println("Monthly pass: " +"$" +df.format(monthly));
System.out.println("\n");
}//end if
else if (stop.equalsIgnoreCase(s4)) {
single = 4.00;
ten = single*0.98*10;
monthly = single*30*0.95;
System.out.println("\n\nFares from South Bend to Chicago are: ");
System.out.println("\nSingle - Ride Ticket: " +"$" +df.format(single));
System.out.println("Ten - Ride Ticket: " +"$" +df.format(ten));
System.out.println("Monthly pass: " +"$" +df.format(monthly));
System.out.println("\n");
}//end if
else if (stop.equalsIgnoreCase(s5)) {
single = 3.75;
ten = single*0.98*10;
monthly = single*30*0.95;
System.out.println("\n\nFares from South Bend to Chicago are: ");
System.out.println("\nSingle - Ride Ticket: " +"$" +df.format(single));
System.out.println("Ten - Ride Ticket: " +"$" +df.format(ten));
System.out.println("Monthly pass: " +"$" +df.format(monthly));
System.out.println("\n");
}//end if
else { System.out.println("Incorrect Input. Try again");}//end else
}//end main
}//end classLast edited by ahmedaa16; 10-21-2011 at 01:10 PM.
Similar Threads
-
String Title case
By bugger in forum New To JavaReplies: 6Last Post: 01-31-2012, 01:21 PM -
How to convert a String to upper case
By Valeriano in forum New To JavaReplies: 16Last Post: 03-01-2010, 12:39 PM -
[SOLVED] Making Switch Case Insensitive?
By iPetey in forum New To JavaReplies: 6Last Post: 04-09-2009, 04:46 PM -
How can we write case insensitive queries for Xpath xml parsing
By vijayvcs in forum XMLReplies: 3Last Post: 09-11-2008, 03:00 AM -
String manipulation example (Title case)
By Java Tip in forum Java TipReplies: 0Last Post: 01-29-2008, 09:04 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks