Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ANDROID STUDIO Our objective in this chapter is to learn how to create images ba

ID: 3670594 • Letter: A

Question

ANDROID STUDIO

Our objective in this chapter is to learn how to create images based on user input. This will introduce us to the vast set of Canvasmethods at our disposal. Our project will require us to build a tutorial to help users visualize and add fractions via colored slices of pie. The app needs to generate random fractions for you to add. Aslo needs to generate a slice of pie that is equal to the fraction asked. One slice needs to be blue the other fraction red. The apps needs to look like the pic.

Explanation / Answer

There are two parts to this solution:

1) Code to generate random fractions

2) Represent the fraction using different colours in the form of pie chart.

Generate Random fraction:

import java.util.*;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class chooseRandom extends Activity

{

Button gr; //When this button is clicked, a random number is generated
TextView Result; // The generated number is visible here
Random R1;


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
gr = (Button)findViewById(R.id.generate);
Result = (TextView)findViewById(R.id.randomresult);

gr.setOnClickListener(new Button.OnClickListener()

{

@Override
public void onClick(View arg0)

{

String final = "";

String final2="";

String res;
R1= new Random();

for(int i = 0; i < 10; i++)

{
final= final+ String.valueOf(R1.nextInt()) + " ";

final2= final2+ String.valueOf(R1.nextInt()) + " ";

res=final+" / "+final2;
}

Result.setText(res);
}});

}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote