1. Homepage
  2. Programming
  3. ELEC 279 Introduction to Object Oriented Programming - Assignment III: GuessMaster

ELEC 279 Introduction to Object Oriented Programming - Assignment III: GuessMaster

Engage in a Conversation
JavaGuessMasterELEC 279ELEC279Introduction to Object Oriented ProgrammingCanadaQueen's University

ELEC 279 - Winter 2023 CourseNana.COM

Introduction to Object Oriented Programming Assignment III

Due Date: Thursday April 6th, 2023 at 9:00 PM. CourseNana.COM

Objective

Practise Android programming by implementing a game with GUI. CourseNana.COM

Submission Guide

• Submit a zip folder containing your entire Android Project Folder plus a packaged app .apk file to “Assignment III” Dropbox folder on onQ. • Late submission: If you are late, for every 2 hours, you will lose 15% of your assignment marks. • Add a comment at the beginning of your source code to include your name and student number as a proof of authorship. • Ensure that your Java source code has good indentation, proper white spaces, clear variable names, and appropriate comments. Add comments for important parts of your code to explain what the code is doing. • CAUTION: This is an individual assignment. You are allowed to discuss the assignment but any form of plagiarism will lead to a score of 0 for your assignment. Please kindly understand that we have zero tolerance to plagiarism. CourseNana.COM

Grading

• 100% - Solve the problem as expected – 40% - Correctly implement GuessMaster.java as the main activity file (or launcher) in Android – 15% - Correctly define all app components in Android Manifest file – 25% - Correctly implement GUI with an acitivty .xml file – 20% - Game works as expected using the GUI CourseNana.COM

Problem: GuessMaster Version 3.0

Assignment III is based on assignments I and II. You can continue with your assignment II source code or use the starting code we provide together with this assignment. In the former case, you may consider saving a copy of your assignment II code somewhere else for future reference. CourseNana.COM

This new version of game, GuessMaster 3.0, is played with the same rule as in assignment I and II. However, you will build a graphical user interface (GUI) in Android Studio. You do NOT need to modify the Date, Entity, Person, Politician, Country and Singer classes. You will basically be reusing these classes in this assignment and modifying GuessMaster.java class. CourseNana.COM

Moving from a Command Line program to GUI, you need to use AlertDialog in Android to print welcome message and a closing message to your user. As in Assignment II, your user will be awarded some tickets if his or her guess is correct. When a user’s guess is correct or incorrect, you will use AlertDialog to inform the user. While working on this assignment, keep in mind that all initial actions or instances of variables should be implemented in the onCreate() method as discussed in class. CourseNana.COM

A Recap of Assignment II

In assignment II, you designed a simple game that allows users to guess the birthday of a named entity, e.g., a celebrity, country, or prominent leader. It requires a player to guess the correct birthday held secretly in the computer program (e.g. Justin Trudeau was born on December 25, 1971). In this assignment, you will create a GUI that looks similar to the one above in Fig. 1(Feel free to be as creative as possible with the interface color, layout etc., but do not make your project too complicated ). CourseNana.COM

To start, the program welcomes the player and inform him/her whose birthday to guess. More specifically, from a set of entities saved or hard-coded in the program, the program randomly picks one entity (e.g., a celebrity or country), show the corresponding image of the entity using ImageView and print the name on the screen using TextView and ask the user to guess the birth date using an EditText. After reading the answer from the EditText, the program responds with “Incorrect. Try an earlier date.” or “Incorrect. Try a later date.”, if the user’s guess is incorrect, or “BINGO. You got it!” if the user is right. All these responses will be shown to user using AlertDialog. CourseNana.COM

Assignment III Instructions

• Create a new project in Android studio call GuessMaster, keep the default SDK version and choose Phone and Tablet as the platforms. Name the activity java class as GuessMaster.java. • When you create your project, specify activity guess activity as the .xml layout file name and modify it as follows (Create these items in this order to obtain layout similar to Fig. 1): (i) Create a TextView with android:id=“@+id/ticket” to store user ticket later in the game. Remember from our Android lectures that id allows us to reference each item in our .xml file in the Java or Activity class file. (ii) Create an ImageView with an id entityImage to display the image of an entity later on. (iii) To print the name of current entity, add a TextView with id entityName (iv) To accept input from user, add an EditText with an id guessinput. (v) Now, we need two Buttons to control user interaction with our game app. For the layout in Fig. 1, add TableLayout and inside the TableLayout tags, add TableRow. Inside the TableRow tags, add one Button with id btnGuess and below it, add another Button with id btnClear. (vi) We are now done with the layout file. Make sure the main container of your layout file is LinearLayout. If you get stuck, please, see sample code (Android In-class Example) on onQ under Week 9. • Before you modify the GuessMaster class, copy your .java classes (Date, Entity, Person, Politician, Country and Singer) from Assignment II into the current Android project directory, paste them in the src folder where you have GuessMaster.java class under your package directory. Note: You might need to remove assignment II package name and add the current package name for Android project in each class you just copied. • Next, modify your GuessMaster class to be an activity .java class that extends AppCompatActivity specify it as the main acitivity class in the AndroidManifest.xml file if Android studio hasn’t done that for you when you created the project. (i) Specify the GuessMaster as an activity class using the AppCompatActivity as thus: public class GuessMaster extends AppCompatActivity. If you follow the new project creation dialog when creating your project, Android studio does this for you by default. If not, let your GuessMaster class extends AppCompatActivity and add import android.support.v7.app.AppCompatActivity; (ii) Import the widget class object since we will be using TextView, EditText, Button and ImageView. add import android.widget.*; (iii) In the class-level of your GuessMaster class, define the following view components: CourseNana.COM

private TextView entityName;
private TextView ticketsum;
private Button guessButton;
private EditText userIn;
private Button btnclearContent;
private String user input;
private ImageView entityImage;
String answer;

(iv) Copy your instances and variables from GuessMaster file in Assignment II and paste in the class-level as well; your instances might look something like this: CourseNana.COM

private int numOfEntities;
private Entity[] entities;
private int[] tickets;
private int numOfTickets;
//Stores Entity Name
String entName;
int entityid = 0;
int currentTicketWon = 0;

(v) Now, let us create the entity objects right after the view components. You can copy the codes from your Assignment II GuessMaster class and paste it right before the onClickListener methods. Your code to create the objects might look like this snippet: CourseNana.COM

Country usa= new Country(“United States”, new Date(“July”, 4, 1776), “Washingston DC”, 0.1);
Person myCreator= new Person(“myCreator”, new Date(”May”, 6, 1800), ”Male”,
1);
Politician trudeau = new Politician(“Justin Trudeau”, new Date(”December”,25,1971),”Male”,
”Liberal”, 0.25);
Singer dion= new Singer(“Celine Dion”, new Date(“March”, 30, 1961), “Female”,
“La voix du bon Dieu”, new Date(“November”,6,1981),0.5);

Add final keyword so that we can access the class within. final GuessMaster gm = new GuessMaster(); CourseNana.COM

(vi) Also, copy all methods (e.g. playGame(), addEntity(), genRandomEntityId() etc.) and constructor (public GuessMaster() from GuessMaster file in Assignment II and add them to the class-level of GuessMaster class in Android project. Remove the while() loops in the two playGame() methods, we will not that since most actions or events in the game will be triggered by Button click. Make sure these methods are pasted outside of the onCreate() call-back method. (vii) Now, dive into the onCreate() method in your GuessMaster acitivity class. In the setContentView( ) method, define the layout file to be used by your activity: CourseNana.COM

//Set the xml as the activity UI view
setContentView(R.layout.activity guess master);
(viii) Right after the setContentView( ) method in the onCreate() , define the view
components defined earlier in ((iii)):
//Specify the button in the view
guessButton = (Button) findViewById(R.id.btnGuess); (Please note that the
R.id references the name of the Guess Button defined in the xml file )
//EditText for user input
userIn = (EditText) findViewById(R.id.guessinput);
//TextView for total tickets
ticketsum = (TextView) findViewById(R.id.ticket);

Define the remaining view components yourself. (ix) Think about the importance of onCreate() method in the life-cycle of an app as discussed in class (refer to lecture slides on Android programming). While you are still in the onCreate(), we need to define actions to perform when the two Buttons defined earlier are clicked by the user. Define the actions as follows each button using the setOnClickListener() method: CourseNana.COM

// OnClick L i s t e n e r a c t i o n f o r c l e a r b u t t o n
b t n c l e a r C o n t e n t . s e t O n C l i c k L i s t e n e r (new View . O n C l i c k L i s t e n e r ( ) {
@Override
public void o n C l i c k ( View v ) {
changeEntity ( ) ;
}
});
// OnClick L i s t e n e r a c t i o n f o r s u b m i t b u t t o n
g u e s s B u t t o n . s e t O n C l i c k L i s t e n e r (new View . O n C l i c k L i s t e n e r ( ) {
@Override
public void o n C l i c k ( View v ) {
// p l a y i n g game
playGame ( ) ;
}
});

(x) Now, create the a method: changeEntity() to clear user entries from the userIn EditText and randomly choose another entity. (xi) Setting Images: Each entity that is randomly selected, there should be a corresponding image displayed in the ImageView defined earlier. Download the three (3) images provided with this assignment instruction. One is a USA flag, one is Trudeau’s picture and the third one is Celine’s picture. Copy this pictures to the drawable folder in your project directory. You should include any picture for the myCreator entity because you will need four (4) pictures in total. Then, create a method called ImageSetter() that sets appropriate picture for each entity when selected; you can use switch..case or if..else statements and use equals() method to compare strings. (xii) In this version, you should print the welcome message once as opposed to printing it multiple times in version 2. Create a method called welcomeToGame(Entity entity) and add the AlertDialog that shows your welcome message as follows: You can remove the Scanner instances since we are no longer using the console. To welcome user to your game, you will print the message to screen using AlertDialog instead of the System.out.println. To use AlertDialog, – Import android.content.DialogInterface; – Define your welcome message inside welcomeToGame(Entity Entity) as follows: //Welcome A l e r t AlertDialog . Builder welcomealert = new A l e r t D i a l o g . B u i l d e r ( G u e s s M a s t e r A c t i v i t y . t h i s ) ; // System . o u t . p r i n t l n ( ” (mm/ dd / yyyy ) ” ) ; w e l c o m e a l e r t . s e t T i t l e ( ” GuessMaster Game v3 ” ) ; w e l c o m e a l e r t . s e t M e s s a g e ( e n t i t y . welcomeMessage ( ) ) ; w e l c o m e a l e r t . s e t C a n c e l a b l e ( f a l s e ) ; //No Cancel Button w e l c o m e a l e r t . s e t N e g a t i v e B u t t o n ( ”START GAME” , new DialogInterface . OnClickListener () { @Override public void o n C l i c k ( D i a l o g I n t e r f a c e d i a l o p , int which ) { Toast . makeText ( g et Bas eC on te xt ( ) , ”Game i s S t a r t i n g . . . Enjoy ” , Toast .LENGTH SHORT ) . show ( ) ; } }); //Show D i a l o g AlertDialog dialog = welcomealert . create ( ) ; d i a l o g . show ( ) ; CourseNana.COM

(xiii) Modify your playGame(Entity Entity) where the game engine is located. First, remove the while(true) except for its contents. We do need not a while() loop Page 6 of 8 – ELEC 279 - Assignment 3 CourseNana.COM

here. As long as the activity is the current user view, the playGame(Entity Entity) method will be called every time a user clicks on the guessButton. While inside this method, remove the Scanner.nextLine() since we are not getting input from command line. Print the entity name to the entityName TextView and get the input from the EdiText userIn: //Name o f t h e e n t i t y t o be g u e s s e d i n t h e entityName t e x t v i e w entityName . s e t T e x t ( e n t i t y . getName ( ) ) ; // Get I n p u t from t h e EdiText answer = u s e r I n . getText ( ) . t o S t r i n g ( ) ; answer = answer . r e p l a c e ( ” \n” , ” ” ) . r e p l a c e ( ”\ r ” , ” ” ) ; Date d a t e = new Date ( answer ) ; CourseNana.COM

• For the two incorrect cases shown below in the playGame(Entity Entity) , create AlertDialog for each. Set their titles as “Incorrect.” The alert message for the first one should be “Try a later date,” and “Try an earlier date” for the second one. Then, use setNegativeButton(“Ok”, new ...) for each dialog. // Check User Date I n p u t i f ( d a t e . p r e c e d e s ( e n t i t y . getBorn ( ) ) ) { // System . o u t . p r i n t l n (” I n c o r r e c t . Try a l a t e r d a t e . ” ) ; ... } e l s e i f ( E n t i t y . getBorn ( ) . p r e c e d e s ( d a t e ) ) { ... } else { t i c k e t s [ numOfTickets++] = E n t i t y . getAwardedTicketNumber ( ) ; f o r ( int i = 0 ; i < 1 0 0 ; i ++) { totaltik = totaltik + tickets [ i ]; } // Use a l e r t h e r e t o l e t u s e r know t h e y have won // C a l l t h e ContinueGame ( ) method i n s i d e t h e o n C l i c k ( ) method // o f t h e D i a l o g I n t e r f a c e . } CourseNana.COM

• After the if...else block, use AlertDialog to inform users that they have won. Use the setNegativeButton(”Continue”, new ...) to continue playing the game. set title as ”You won” and message should be “BINGO! ”+ Entity.closingMessage(). In the onClick() method of the setNegativeButton(), make sure you add the awarded ticket to the Toast.makeText() using the getAwardedTicketNumber() method in Entity class. • Lastly, using the setText() method update the ticketsum TextView with the total ticket obtained. To ensure that the game Continues, create a method called ContinueGame() with the below sample code and call this method in the if...else statement that checks if user wins. Logically, the ContinueGame() method should be called after a user wins. Call the ContinueGame() method inside the onClick() method of the DialogInterface. CourseNana.COM

Page 7 of 8 – ELEC 279 - Assignment 3 CourseNana.COM

Figure 2: Sample Screenshot CourseNana.COM

// Continue Game Method − This method g e t s a n o t h e r E n t i t y randomly // Updates t h e Image v i e w and t h e E n t i t y Name F i e l d public void ContinueGame ( ) { e n t i t y i d = genRandomEntityId ( ) ; Entity e n t i t y = e n t i t i e s [ e n t i t y i d ] ; entName = e n t i t y . getName ( ) ; // C a l l t h e I m a g e S e t t e r method ImageSetter ( ) ; // P r i n t t h e name o f t h e e n t i t y t o be g u e s s e d // i n t h e entityName t e x t v i e w entityName . s e t T e x t ( entName ) ; // C l e a r P r e v i o u s Entry u s e r I n . getText ( ) . c l e a r ( ) ; } CourseNana.COM

• Test your code using physical device or the Emulator. See sample GUI on onQ under Week 11 Assignment III folder. • To submit zip the entire project folder and submit the zipped file. This folder should contain the app subfolder along with additional gradle Android Studio files. See the example in Fig 2. To test if the project is zipped properly you can unzip and run import/open the project in Android Studio and the app should be able to run. HOPE YOU ENJOY ANDROID PROGRAMMING :) CourseNana.COM

Page 8 of 8 – ELEC 279 - Assignment 3 CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
Java代写,GuessMaster代写,ELEC 279代写,ELEC279代写,Introduction to Object Oriented Programming代写,Canada代写,Queen's University代写,Java代编,GuessMaster代编,ELEC 279代编,ELEC279代编,Introduction to Object Oriented Programming代编,Canada代编,Queen's University代编,Java代考,GuessMaster代考,ELEC 279代考,ELEC279代考,Introduction to Object Oriented Programming代考,Canada代考,Queen's University代考,Javahelp,GuessMasterhelp,ELEC 279help,ELEC279help,Introduction to Object Oriented Programminghelp,Canadahelp,Queen's Universityhelp,Java作业代写,GuessMaster作业代写,ELEC 279作业代写,ELEC279作业代写,Introduction to Object Oriented Programming作业代写,Canada作业代写,Queen's University作业代写,Java编程代写,GuessMaster编程代写,ELEC 279编程代写,ELEC279编程代写,Introduction to Object Oriented Programming编程代写,Canada编程代写,Queen's University编程代写,Javaprogramming help,GuessMasterprogramming help,ELEC 279programming help,ELEC279programming help,Introduction to Object Oriented Programmingprogramming help,Canadaprogramming help,Queen's Universityprogramming help,Javaassignment help,GuessMasterassignment help,ELEC 279assignment help,ELEC279assignment help,Introduction to Object Oriented Programmingassignment help,Canadaassignment help,Queen's Universityassignment help,Javasolution,GuessMastersolution,ELEC 279solution,ELEC279solution,Introduction to Object Oriented Programmingsolution,Canadasolution,Queen's Universitysolution,