Question
Application title: Reserve a Restaurant App Purpose: A restaurant reservation app provides a listing of at least 5 restaurants. By selecting a restaurant, users get
Application title: Reserve a Restaurant App
Purpose: A restaurant reservation app provides a listing of at least 5 restaurants. By selecting a restaurant, users get info about the restaurant.
Algorithm: 1. An opening screen displays a welcome message (such as Welcome to Restaurant App!) and a button for users to go to the next screen.
2. The second screen displays a listing of restaurants.
3. Some restaurants can be selected to view a Web site.
4. The others are local/small restaurants that do not have a Web site. When the user selects this type of restaurants, a third screen displays the name, street address, and city of the restaurant. In addition, and a Phone button is included in the screen.
5. After the Phone is touched, a popup message is displayed to show the restaurants phone number. If the restaurant does not have a phone number, you display the message: No phone number!.
Conditions: 1. Create a Restaurant class including the Id, Name, City, Address, URL, and Phone Number properties. An array of Restaurant objects must be created by your Android activity and used by your Android adopter to show information of the restaurants.
2. In the second page, create a custom layout for the list items.
3. Each list item displays the name and city of a restaurant in the list view.
4. If the phone number of the selected restaurant is not available (empty in the corresponding Restaurant object), you display a popup message saying that the restaurant phone number is not available.
5. Each list item include an image (same for all of the restaurants). You go to find/use your own image.
6. Create/use a single activity class & its layout for all the restaurants without a Web site.
7. Include at least three restaurants without a Web site.
8. Include at least one restaurant without a phone number (the Phone Number property value is null or empty).
Bonus Points (10 pts): Add an image Id property in the Restaurant class and a custom ArrayAdapter; then, you use them to display a list of 5 restaurants and show the image of each restaurant on the second screen.
I have: 4 java activities so far: ActivityMain.java Restaurant > Class constructor SecondActivity ThirdActivity
MainActivity.Java has:
import android.app.ListActivity; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Button NextScreen = findViewById(R.id.btnWelcome); NextScreen.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(getApplicationContext(),SecondActivity.class); startActivity(intent); } }); } }
Restaurant Class: public class Restaurant {
public Restaurant(String ID, String name, String city, String address, String URL, String phone) { ID = ID; this.name = name; this.city = city; this.address = address; this.URL = URL; this.phone = phone; } //ID, name, city, address, URL, phone private int ID; private String name; private String city; private String address; private String URL; private String phone; //Code > Generate > Get/Set-for all variables in CL. //this gives def.of beans public int getID() { return ID; } public void setID(int ID) { this.ID = ID; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getURL() { return URL; } public void setURL(String URL) { this.URL = URL; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } @Override public String toString() { //return super.toString(); //instruction say to return the name and city of a restaurant in the list view //creates toString to be able to call return name + " " + city; } }
SecondActivity:
mport java.util.ArrayList; import java.util.List; import java.util.Map; public class SecondActivity extends ListActivity { ListlistRestaurants; @Override protected void onListItemClick(ListView l, View v, int position, long id) { // super.onListItemClick(l, v, position, id); // listRestaurants.get(); //provides index // Restaurant selectedRestaurants = listRestaurants.get( ); //method triggers info you get. // Use index to find info abt that thing/selection //Get listAttractions error. B/c local var. So need to make connection instance var. Outside method, inside class! //how can we display position? TOAST // Toast.makeText(this,"position" + position + "city" + // selectedRestaurants.getPhone(), Toast.LENGTH_LONG).show(); //parameter for method } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String[] restaurants = {"restOne","restTwo","restThree.","restFour","restFive"}; Restaurant r1 = new Restaurant("101","restOne","City","955 south street","http://","587-996-9999"); Restaurant r2 = new Restaurant("102","restTwo","City","950 east lane","http://","592-669-0082"); Restaurant r3 = new Restaurant("103","restThree ","City","9110 Hwy north","http://","217-899-9550"); Restaurant r4 = new Restaurant("104","restFour","City","555 West Beach","http://","588-889-9995"); Restaurant r5 = new Restaurant("105","restFive","","","",""); //make objects in activity, send list to arrays, IE add beans to array Restaurant[] arrayRestaurants = {r1, r2, r3, r4, r5}; listRestaurants = new ArrayList (); listRestaurants.add(r1); listRestaurants.add(r2); listRestaurants.add(r3); listRestaurants.add(r4); listRestaurants.add(r5); setListAdapter(new ArrayAdapter (SecondActivity.this,R.layout.activity_second,R.id.txtRestInfo, arrayRestaurants)); // Toast.makeText(this,"position" + position + "cost" + // selectedRestaurants.getPhone(), Toast.LENGTH_LONG).show(); //parameter for method } }
Notes: In the second activity I was told that if I set the restuaruants up with using Keys that It would be easier in the long run. But I don't really know how to do this. Essentially It would be: public static final string KEYID = "KeyID"; for each attribute in the Resturant class...then I would need to do List
then I would do an onCreate to add the different lines to the list like: restaurantArrayList.Add(new resturant (1, "name","city", "phone ",.......)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started