Skip to content

Instantly share code, notes, and snippets.

View surendra554's full-sized avatar

Surendra Kumar Patel surendra554

View GitHub Profile
// Show an error message as a toast
Toast.makeText(this, "You cannot have less than 1 coffee", Toast.LENGTH_SHORT).show();
// Exit this method early because there's nothing left to do
@surendra554
surendra554 / Sleep debt source code Java
Last active September 25, 2022 12:26
// The user estimates how much they sleep on a weekday/weekend day. The equation assume you need 8 hours sleep of a night. The user in this case sleep hours on weekday and 9 hours on a weekend. //
int weekday = 5;
int weekend = 9;
int optimalHours = 7 * 8;
int actualHours = weekday;
actualHours = actualHours + weekend * 2;
int solution = optimalHours - actualHours;
display(solution);
@surendra554
surendra554 / Just Java MainActivity.java
Last active March 22, 2020 19:37 — forked from udacityandroid/MainActivity.java
Android for Beginners : Add the Chocolate Topping Checkbox Solution Java
package com.example.android.justjava;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;
/**
* This app displays an order form to order coffee.
@surendra554
surendra554 / Option A
Created February 13, 2020 10:02 — forked from udacityandroid/Option A
Android Development for Beginners : Calculate the Price Method
/**
* Calculates the price of the order based on the current quantity.
*
* @return the price
*/
private int calculate price(int quantity {
int price = quantity * 5;
return price;
}
@surendra554
surendra554 / Option A
Created February 3, 2020 19:45 — forked from anonymous/Option A
3 options for the layout of an activity for a quiz question
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
/**
* This method displays the given price on the screen.
*/
private void displayPrice(int number) {
TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
priceTextView.setText(NumberFormat.getCurrencyInstance().format(number));
}
@surendra554
surendra554 / MainActivity.java
Last active January 29, 2020 18:52 — forked from udacityandroid/MainActivity.java
IMPORTANT: Remember to add your package name before you copy and paste this java code into the JustJava app's MainActivity.java file.
/**
* IMPORTANT: Make sure you are using the correct package name.
* This example uses the package name:
* package com.example.android.justjava
* If you get an error when copying this code into Android studio, update it to match teh package name found
* in the project's AndroidManifest.xml file.
**/
package com.example.android.justjava;