Hi there I need help using Gauss\' formula to find out what the Day(mon-fri) of
ID: 3553222 • Letter: H
Question
Hi there I need help using Gauss' formula to find out what the Day(mon-fri) of the week is selected by the use of spinners and an EditText box. Once calculated I need it to display in a textbox called textView. The button is used to be an event to calculate once clicked.
Here Is my code thus far.
package com.example.daycalculator;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.EditText;
public class MainActivity extends Activity {
private Spinner spinner1, spinner2;
private EditText EditText;
private Button btnSubmit;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addItemsOnSpinner2();
addListenerOnButton();
addListenerOnSpinnerItemSelection();
}
// add items into spinner dynamically
public void addItemsOnSpinner2() {
spinner2 = (Spinner) findViewById(R.id.day);
List<String> list = new ArrayList<String>();
list.add("1"); list.add("2");list.add("3");list.add("4");list.add("5");list.add("6");list.add("7");
list.add("8");list.add("9");list.add("10");list.add("11");list.add("12");list.add("13");list.add("14");
list.add("15");list.add("16");list.add("17");list.add("18");list.add("19"); list.add("20");list.add("21");
list.add("22");list.add("23");list.add("24");list.add("25");list.add("26");list.add("27");
list.add("28");list.add("29");list.add("30");list.add("31");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner2.setAdapter(dataAdapter);
}
public void addListenerOnSpinnerItemSelection() {
spinner1 = (Spinner) findViewById(R.id.month);
spinner1.setOnItemSelectedListener(new CustomOnItemSelectedListener());
}
// get the selected dropdown list value
public void addListenerOnButton() {
spinner1 = (Spinner) findViewById(R.id.month);
spinner2 = (Spinner) findViewById(R.id.day);
setEditText((EditText) findViewById(R.id.year));
btnSubmit = (Button) findViewById(R.id.btnSubmit);
btnSubmit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this,
"OnClickListener : " +
" Spinner 1 : "+ String.valueOf(spinner1.getSelectedItem()) +
" Spinner 2 : "+ String.valueOf(spinner2.getSelectedItem()),
Toast.LENGTH_SHORT).show();
}
});
}
public EditText getEditText() {
return EditText;
}
public void setEditText(EditText editText) {
EditText = editText;
}
}
Explanation / Answer
There are various methods to calculate the day of the week for any particular date in the past or future. These methods ultimately rely on algorithms to determine the day of the week for any given date, including those based solely on tables as found in perpetual calendars that require no calculations to be performed by the user. A typical application is to calculate the day of the week on which someone was born or any other specific event occurred.
A calendrical savant (or calendar savant) is someone who
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.