Results 1 to 1 of 1
  1. #1
    ahmedaa16 is offline Member
    Join Date
    Oct 2011
    Posts
    1
    Rep Power
    0

    Exclamation 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 class
    Last edited by ahmedaa16; 10-21-2011 at 02:10 PM.

Similar Threads

  1. String Title case
    By bugger in forum New To Java
    Replies: 6
    Last Post: 01-31-2012, 02:21 PM
  2. How to convert a String to upper case
    By Valeriano in forum New To Java
    Replies: 16
    Last Post: 03-01-2010, 01:39 PM
  3. [SOLVED] Making Switch Case Insensitive?
    By iPetey in forum New To Java
    Replies: 6
    Last Post: 04-09-2009, 05:46 PM
  4. Replies: 3
    Last Post: 09-11-2008, 04:00 AM
  5. String manipulation example (Title case)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-29-2008, 10:04 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •