package is.hi.hbv601g.mathstermind; import android.content.Intent; import android.os.Handler; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import com.google.firebase.auth.FirebaseAuth; import is.hi.hbv601g.mathstermind.model.MyDataHelper; public class PlayGameActivity extends AppCompatActivity { private static final int easyQuestionNumber = 4; private static final int mediumQuestionNumber = 4; private static final int hardQuestionNumber = 4; private static final String[] easyQuestions = {"1+2 =", "7-2 =", "5*3 =", "12/4="}; private static final String[][] easyAnswers = { {"3", "4", "6", "1"}, {"5", "8", "9", "4"}, {"10", "8", "15", "20"}, {"0", "8", "3", "4"}}; private static final String[] easyCorrect = {"3", "5", "15", "3"}; private static final String[] mediumQuestions = {"5+(3*7)+5=", "12+3*9-2=", "3^2 + 4^2 - 2^3 =", "4^2(5^2-16/4)-1="}; private static final String[][] mediumAnswers = { {"10", "42", "31", "20"}, {"27", "47", "57", "37"}, {"15", "17", "26", "6"}, {"204", "335", "125", "225"}}; private static final String[] mediumCorrect = {"31", "37", "17", "335"}; private static final String[] hardQuestions = {"(1/6 + 1/12 + 1/20 + 1/30) -2 =", "10*9*8*7*6*5*4*3*2*1 =", "Y=log x\nIf y=10, then what is x?", "20% of 2 is equal to"}; private static final String[][] hardAnswers = { {"-5/3", "1.6667", "5/4", "4/5"}, {"100", "1000", "10^10", "10!"}, {"x=10", "x=1", "x=5", "x=15"}, {"20", "4", "0.4", "0.04"}}; private static final String[] hardCorrect = {"-5/3", "10!", "x=1", "0.4"}; // uniform structures to use no matter what level is chosen private String[] questions; private String[][] answers; private String[] correct; private int questionNumber; private TextView question; private Button button1; private Button button2; private Button button3; private Button button4; private Button btnSkip; private int currQuestion; private int score; private Toast toast; private MyDataHelper model; private FirebaseAuth firebaseAuth; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_play_game); question = (TextView) findViewById(R.id.question); button1 = (Button) findViewById(R.id.button1); button2 = (Button) findViewById(R.id.button2); button3 = (Button) findViewById(R.id.button3); button4 = (Button) findViewById(R.id.button4); btnSkip = (Button) findViewById(R.id.btnSkip); currQuestion = -1; score = 0; Intent intent = getIntent(); String level = intent.getStringExtra("level"); model = new MyDataHelper(this); firebaseAuth = FirebaseAuth.getInstance(); switch (level) { case "easy": questions = easyQuestions; answers = easyAnswers; correct = easyCorrect; questionNumber = easyQuestionNumber; break; case "medium": questions = mediumQuestions; answers = mediumAnswers; correct = mediumCorrect; questionNumber = mediumQuestionNumber; break; case "hard": questions = hardQuestions; answers = hardAnswers; correct = hardCorrect; questionNumber = hardQuestionNumber; break; } displayNextQuestion(); } private void displayNextQuestion() { currQuestion++; if (currQuestion < questionNumber) { question.setText(questions[currQuestion]); button1.setText(answers[currQuestion][0]); button2.setText(answers[currQuestion][1]); button3.setText(answers[currQuestion][2]); button4.setText(answers[currQuestion][3]); }else{ toast.cancel(); Toast.makeText(this, "Your score is: "+score, Toast.LENGTH_LONG ).show(); String email = firebaseAuth.getCurrentUser().getEmail(); model.writeScore(email, score); finish(); } } public void answerClicked(View view) { switch (view.getId()){ case R.id.button1: if (correct[currQuestion].equals(answers[currQuestion][0])){ toast = Toast.makeText(this, "Correct Answer", Toast.LENGTH_SHORT); score++; }else{ toast = Toast.makeText(this, "Wrong Answer", Toast.LENGTH_SHORT); } break; case R.id.button2: if (correct[currQuestion].equals(answers[currQuestion][1])){ toast = Toast.makeText(this, "Correct Answer", Toast.LENGTH_SHORT); score++; }else{ toast = Toast.makeText(this, "Wrong Answer", Toast.LENGTH_SHORT); } break; case R.id.button3: if (correct[currQuestion].equals(answers[currQuestion][2])){ toast = Toast.makeText(this, "Correct Answer", Toast.LENGTH_SHORT); score++; }else{ toast = Toast.makeText(this, "Wrong Answer", Toast.LENGTH_SHORT); } break; case R.id.button4: if (correct[currQuestion].equals(answers[currQuestion][3])){ toast = Toast.makeText(this, "Correct Answer", Toast.LENGTH_SHORT); score++; }else{ toast = Toast.makeText(this, "Wrong Answer", Toast.LENGTH_SHORT); } break; } toast.show(); displayNextQuestion(); } }
Complete the following function for the button: "btnSkip" - when clicked it is supposed to show the next question on the android quiz.
// below function will give next question. Also find comments inline private void skipQuestion() { currQuestion++; // increase the count of currQuestion by 1 if (currQuestion < questionNumber) { // check if currQuestion is less than total ques question.setText(questions[currQuestion]); // set question text button1.setText(answers[currQuestion][0]);// set option 1 button2.setText(answers[currQuestion][1]); // set option 2 button3.setText(answers[currQuestion][2]); // set option 3 button4.setText(answers[currQuestion][3]); // set option 4 }else{ // if skipping to next question make count more than available question show score and finish toast.cancel(); Toast.makeText(this, "Your score is: "+score, Toast.LENGTH_LONG ).show(); // show score String email = firebaseAuth.getCurrentUser().getEmail(); model.writeScore(email, score); // write score finish(); // finish current activity } }
Package is.hi.hbv601g.mathstermind; import android.content.Intent; import android.os.Handler; im...
Why is my app crashing? Following is an app that takes notes from users and shows it's encrypted string. It also decrypt and encrypted strings. It saves the note in a file and also loads it back. Please help me identify what I am doing wrong? activity_krypto_note.xml <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".KryptoNoteActivity"> <EditText android:id="@+id/key" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:ems="10" android:hint="Cryptographic Key" android:inputType="number" app:layout_constraintEnd_toStartOf="@+id/encrypt" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <Button android:id="@+id/encrypt" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:onClick="enryptClicked" android:text="ENCRYPT" android:textSize="9sp"...
Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class translatorApp extends JFrame implements ActionListener { public static final int width = 500; public static final int height = 300; public static final int no_of_lines = 10; public static final int chars_per_line = 20; private JTextArea lan1; private JTextArea lan2; public static void main(String[] args){ translatorApp gui = new translatorApp();...
please help me to creating UML class diagrams. Snake.java package graphichal2; import java.awt.Color; import java.awt.Font; import java.awt.Frame; import java.awt.Graphics; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.Random; enum Dir{L, U, R, D}; class Food { public static int FOODSTYLE = 1; private int m = r.nextInt(Yard.WIDTH / Yard.B_WIDTH); private int n = r.nextInt(Yard.HEIGHT / Yard.B_WIDTH - 30/Yard.B_WIDTH) + 30/Yard.B_WIDTH;// 竖格 public static Random r = new Random(); public int getM() { return m; } public void setM(int m)...
Java debugging in eclipse package edu.ilstu; import java.util.Scanner; /** * The following class has four independent debugging * problems. Solve one at a time, uncommenting the next * one only after the previous problem is working correctly. */ public class FindTheErrors { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); /* * Problem 1 Debugging * * This problem is to read in your first name, * last name, and current year and display them in *...
Solver.java package hw7; import java.util.Iterator; import edu.princeton.cs.algs4.Graph; import edu.princeton.cs.algs4.BreadthFirstPaths; public class Solver { public static String solve(char[][] grid) { // TODO /* * 1. Construct a graph using grid * 2. Use BFS to find shortest path from start to finish * 3. Return the sequence of moves to get from start to finish */ // Hardcoded solution to toyTest return...
Make a FLOWCHART for the following JAVA Prime Number Guessing Game. import java.util.Random; import java.util.Scanner; public class Project2 { //Creating an random class object static Random r = new Random(); public static void main(String[] args) { char compAns,userAns,ans; int cntUser=0,cntComp=0; /* * Creating an Scanner class object which is used to get the inputs * entered by the user */ Scanner sc = new Scanner(System.in); System.out.println("*************************************"); System.out.println("Prime Number Guessing Game"); System.out.println("Y = Yes , N = No...
Java BlackJack Game: Help with 1-4 using the provided code below Source code for Project3.java: import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; public class Project3 extends JFrame implements ActionListener { private static int winxpos = 0, winypos = 0; // place window here private JButton exitButton, hitButton, stayButton, dealButton, newGameButton; private CardList theDeck = null; private JPanel northPanel; private MyPanel centerPanel; private static JFrame myFrame = null; private CardList playerHand = new CardList(0); private CardList dealerHand = new CardList(0);...
PLEASE COMPLETE THE CODES. package javaprogram; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; /** * Movie class definition. * * @author David Brown * @version 2019-01-22 */ public class Movie implements Comparable { // Constants public static final int FIRST_YEAR = 1888; public static final String[] GENRES = { "science fiction", "fantasy", "drama", "romance", "comedy", "zombie", "action", "historical", "horror", "war" }; public static final int MAX_RATING = 10; public static final int MIN_RATING = 0; /** * Converts a string of...
Why can't the 'length' be resolved? import java.util.*; enum Commands { UNKNOWN, QUIT, LOOK, NORTH, SOUTH, EAST, WEST } public class Main { public static void main(String[] args) { System.out.println("Welcome to Zork!"); SpawnPlayer(); Scanner scanner = new Scanner(System.in); Commands command = Commands.UNKNOWN; while (command != Commands.QUIT) { System.out.println(rooms[]locationRow[locationColumn]); System.out.print(">"); String inputString = scanner.nextLine(); command = ToCommand(inputString); switch (command) { case QUIT: System.out.println("Thank you for playing!"); break; case LOOK: System.out.println("A rubber mat saying 'Welcome to Zork!' lies by the door."); break;...
package cards; import java.util.ArrayList; import java.util.Scanner; public class GamePlay { static int counter = 0; private static int cardNumber[] = {1,2,3,4,5,6,7,8,9,10,11,12,13}; private static char suitName[] = { 'c', 'd', 'h', 's' }; public static void main(String[] args) throws CardException, DeckException, HandException { Scanner kb = new Scanner(System.in); System.out.println("How many Players? "); int numHands = kb.nextInt(); int cards = 0; if (numHands > 0) { cards = 52 / numHands; System.out.println("Each player gets " + cards + " cards\n"); } else...