Getting Started To start this exercise, you should: 1. Open eclipse and start a
ID: 3563671 • Letter: G
Question
Getting Started To start this exercise, you should:
1. Open eclipse and start a new Java project named Lab05
2. Add a Class (named Lab05) to this project.
3. Cut the program from this document and paste (replacing everything) in the Eclipse editor
window.
Lab05.java
import java.util.Scanner;
public class Lab05
{
public static void main(String[] args)
{
Scanner stdIn = new Scanner(System.in);
//
System.out.println("CS 201 Restaurant Guide ");
String response;
char s, f;
boolean spicy, fancy;
// Ask user for his/her preference
System.out.print("Do you like spicy food? (y / n) : ");
// Get the next token
response = stdIn.next();
// Look only at first character
s = response.charAt(0);
if (s ==
Explanation / Answer
import java.util.Scanner;
public class Lab05
{
public static void main(String[] args)
{
Scanner stdIn = new Scanner(System.in);
System.out.println("CS 201 Restaurant Guide ");
String response;
char s, f;
boolean spicy, fancy;
// Ask user for his/her preference
System.out.print("Do you like spicy food? (y / n) : ");
// Get the next token
response = stdIn.next();
// Look only at first character
s = response.charAt(0);
if (s == 'y' || s == 'Y')
spicy = true;
else
spicy = false;
// Ask user for his/her preference
System.out.print("Do you want to go to a fancy restaurant? (y / n) : ");// Get the next token
response = stdIn.next();
// Look only at first character
f = response.charAt(0);
fancy = (f == 'y') || (f == 'Y');
// Make suggestion
if(spicy){
if(fancy)
System.out.println("I suggest you go to Thai Garden Palace.");
else
System.out.println("I suggest you go to Alberto
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.