Question: JAVA Question - Evaluate String If the user enters a weekend day, I want the cost of the park to equal 5.00 dollars if the

JAVA Question - Evaluate String

If the user enters a weekend day, I want the cost of the park to equal 5.00 dollars if the users enters a week day I want the cost of the park to be 2.50.

I have a string called arrivalDay which gathers input data from the user. The String arrivalDay does return day. Perhaps that is the cause of my problem.

public static void main(String[] args) { // MAIN /////////////////////////////////////////////////////////////////////

String getDay = getString("Enter day : ");

if (arrivalDay == "Saturday" || arrivalDay == "Sunday") { cost = 5.00; } else {

cost = 2.5

}

But if I run the math using "get cost = 1.25; }

System.out.println("Park ticket costs " + cost + " ");

// END MAIN ///////////////////////////////////////////////////////////////////////

public static String getString(String message) { System.out.println(message); Scanner sc = new Scanner(System.in); String day = ""; weekDay = sc.next(); // input chx while (!day.equalsIgnoreCase("Sunday") && !day.equalsIgnoreCase("Monday") && !day.equalsIgnoreCase("Tueday") && !day.equalsIgnoreCase("Saturday")) { // Input chx

System.out.println("Please pick days "Sunday", "Monday", or "Tuesday". ");

// Input try ag day = sc.next(); } // End WHILE

// Input chx System.out.println("Entered " + day );

return day; } // End Get Day

The cost always defaults to 2.5 and never prompts 5.00. I must not be evaluating the string appropriately.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!