Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

More Books

Students also viewed these Databases questions

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago