Java for Android Week 1 Coursera
course link : https://www.coursera.org/learn/java-for-android
Module 1 Quiz
Question 1
Which of the following are key concepts found in all object-oriented programming languages, according to the lessons in this module?
Inheritance
Concurrency
Polymorphism
Lambda expressions
Transactional memory
Abstraction
2.
Question 2
Which of the following are examples of data abstraction features supported by Java, according to the lessons in this module?
if statements
for loops
Classes
Interfaces
3.
Question 3
Which of the following is the best definition of an “abstract data type” (ADT), according to the lessons in this module?
An ADT selectively alters the flow of control through an app so it performs different computations based on programmer-specified conditions.
An ADT defines an anonymous method that can be passed as an argument or returned as the value of method calls.
An ADT separates the control flow paths of normal app execution from the control flow paths of anomalous app execution.
An ADT defines a set of data values and a set of operations on these values.
4.
Question 4
Which of the following are accurate descriptions of differences between Java classes and interfaces, according to the lessons in this module?
A Java class can be part of a package, where as a Java interface can’t.
A Java interface cannot be instantiated directly, whereas a class can.
A Java class is a data abstraction mechanism, whereas a Java interface is a control abstraction mechanism
A Java interface provides a subset of the features provided by a Java class.
These are answers of Java for Android Week 1 Coursera course
5.
Question 5
Which of the following are benefits of Java generics, according to the lessons in this module?
They help eliminate unnecessary duplication of code.
They automatically reclaim and recycle objects that are not currently in use by an app.
It separates the control flow paths of normal app execution from the control flow paths of anomalous app execution.
They ensure compile-type safety when operating on different types.
6.
Question 6
Which of the following are benefits of inheritance in Java, according to the lessons in this module?
It provides a namespace for organizing Java code in a logical manner.
It enhances reuse by allowing classes to reuse common state and behavior from other class.
It hides a class’s internal representation to ensure apps using the class can only access its public operations.
It determines the order in which individual statements or method calls are evaluated or run.
7.
Question 7
Which of the following describe the purpose of exception handling in Java, according to the lessons in this module?
It simplifies the management of large software projects by avoiding collisions between classes that have the same common name.
It makes Java apps more robust and easier to understand and evolve.
It enables the repetition of a block containing one or more statements within an app.
It separates the control flow paths of normal app execution from the control flow paths of anomalous app execution.
8.
Question 8
Which of the following describe the purpose of polymorphism in Java, according to the lessons in this module?
It enables transparent customization of methods in a subclass that are inherited from a super class.
It enables the passing of types as parameters to the definition of classes, interfaces, and methods.
It separates the control flow paths of normal app execution from the control flow paths of anomalous app execution.
It defines an anonymous method that can be passed as an argument or returned as the value of method calls.
9.
Question 9
Which of the following are expectations of learners who take this MOOC, according to the lessons in this module?
You are expected to know how to program Java for Android apps.
You are expected you to have a Computer Science degree.
You are expected to be interested in both the concepts and practice of developing mobile apps
You are expected have basic computer literacy skills, such as knowing how to send & receive emails and browse the web.
10.
Question 10
Which of the following are recommended strategies for learning the material covered in this MOOC, according to the lessons in this module?
Follow the links to articles, tutorials, source code, and documentation provided in the lesson slides.
Watch the lessons carefully before taking the quizzes and doing the programming assignments.
Attend Coursera meet up groups near you.
Participate in the online discussion forums.
Module 2 Quiz
1.
Question 1
What version of the Android API are we going to use in this class?
Android API version 29
Android API version 22
Android API version 30
Android API version 28
These are answers of Java for Android Week 1 Coursera course
2.
Question 2
Which Android Studio wizard button will you use to -Open- an existing project?
Start a new Android Studio project
Open an existing Android Studio project
Import project (Gradle, Eclipse ADT, etc.)
Configure
3.
Question 3
There is a folder in Android Studio projects called ‘res’. What does ‘res’ mean?
regular expression system
responsible
resources
reveal
4.
Question 4
By convention which of these names is in proper formatting for a Java class?
Mathlibrary
MathLibrary
mathlibrary
mathLibrary
5.
Question 5
Bugs(defects) in software can be categorized into two main groups. Which of these match those categories?
Syntax and Logical
Syntax and Grammar
Logical and Highlighting
Highlighting and Grammar
6.
Question 6
In Android Studio what does a word having a red squiggly line under it likely mean?
That word likely has a desire to be a blue line, but it didn’t study enough to get into ‘Squiggly Blue Line School’
That word likely has hurt feelings.
That word likely has too much teen spirit.
That word likely has a syntax error
These are answers of Java for Android Week 1 Coursera course
7.
Question 7
Which of the following is not a step in running our code in the supplied Android app?
Select “app” from the configuration drop-down menu
Select an AVD with API 29 that will run on our computer
Right-click on Logic.java and select Run
Press the Run button on the tool bar
8.
Question 8
To submit your solution to the auto-grader so that you can receive a grade…
You upload the file Logic.java to the Coursera server.
You use the submitForGrading gradle task to create submission.zip that you will upload to the Coursera server.
You will run the supplied unit tests on your computer to grade your submission.
You use the graderPreview gradle task to grade your submission.
Module Quiz 3
Module 3 Quiz
Total points 12
1.
Question 1
What is the value of this expression:
54 % 10 + 6 * 3 % 4
6
22
9
None of the other options
9.9
2.
Question 2
Which operator in the following expression will be evaluated first?
2 / (1.0 + 2 * 3) – 2
The multiplication * operator
The division / operator
The addition + operator
The subtraction – operator
These are answers of Java for Android Week 1 Coursera course
3.
Question 3
Overloading is a feature that allows the creation of two or more methods with the same name as long as the parameter lists are different.
TRUE
FALSE
4.
Question 4
Given a String object called str, the statement str.toUpperCase(); will change the object to have all uppercase letters:
TRUE
FALSE
5.
Question 5
The following string is a legal Java identifier that could be used as a variable name or a method name: _am_I_okay
FALSE
TRUE
6.
Question 6
The programmer can manually change data values from one type to another type by an operation called a type-_
cast
coercion
convert
alteration
7.
Question 7
- What is the output produced by running the program below? Read the code carefully before selecting the correct answer.
public void process() {
int x = 22;
out.print(x + " ");
modify_x(x);
out.print(x + " ");
}
public static void modify_x (int x) {
x = 99;
out.print(x + " ");
22 22 99
22 22 22
22 99 22
99 22 99
22 99 99
8.
Question 8
- Given variable x of type double, which of the following result in a different value being assigned to x?
They are all equivalent; i.e. all assign the same value to x
x = 32/5.0
x = 32.0/5
x = (double)(32/5)
x = 32.0/5.0
These are answers of Java for Android Week 1 Coursera course
9.
Question 9
The following code always prints the value 9:
int x = 8;
out.println(x++)
TRUE
FALSE
10.
Question 10
When calling a method, the name of the actual argument (at the call site) must match the name of the formal parameter used in the method’s parameter list.
FALSE
TRUE
11.
Question 11
What reserved word is used to indicate that a method does not return a value?
public
void
static
return
12.
Question 12
A bit can have __ different values.
2
256
100
8
Assignment
package mooc.vandy.java4android.shapes.logic;
import java.util.Locale;
import mooc.vandy.java4android.shapes.ui.OutputInterface;
import static java.lang.String.format;
/**
* This is where the logic of this App is centralized for this assignment.
* <p>
* The assignments are designed this way to simplify your early
* Android interactions. Designing the assignments this way allows
* you to first learn key 'Java' features without having to beforehand
* learn the complexities of Android.
*/
public class Logic
implements LogicInterface {
/**
* This is a String to be used in Logging (if/when you decide you
* need it for debugging).
*/
public static final String TAG = Logic.class.getName();
/*
* This is the variable that stores our OutputInterface instance.
* <p>
* This is how we will interact with the User Interface [MainActivity.java].
* <p>
* It is called 'out' because it is where we 'out-put' our
* results. (It is also the 'in-put' from where we get values
* from, but it only needs 1 name, and 'out' is good enough)
*/
private final OutputInterface mOut;
/**
* This is the constructor of this class.
* <p>
* It assigns the passed in [MainActivity] instance
* (which implements [OutputInterface]) to 'out'
*/
public Logic(OutputInterface out) {
mOut = out;
}
/**
* This is the method that will (eventually) get called when the
* on-screen button labeled 'Process...' is pressed.
*/
@Override
public void process() {
// Get which calculation should be computed. Do not worry
// about the specifics of this right now.
Shapes shapeForCalculations = mOut.getShape();
// Store the values returned by the User Interface.
double mLength = mOut.getLength();
double mWidth = mOut.getWidth();
double mHeight = mOut.getHeight();
double mRadius = mOut.getRadius();
// Determine which calculation to process right now. Again,
// do not worry about the specifics of how this works for now.
switch (shapeForCalculations) {
case Box:
mOut.print("A "
+ mLength
+ " by "
+ mWidth
+ " by "
+ mHeight
+ " box has a volume of: ");
mOut.println(format(Locale.getDefault(), "%.2f", boxVolume(mLength, mWidth, mHeight)));
mOut.println();
mOut.print("A "
+ mLength
+ " by "
+ mWidth
+ " by "
+ mHeight
+ " box has a surface area of: ");
mOut.println(format(Locale.getDefault(), "%.2f", boxSurfaceArea(mLength, mWidth, mHeight)));
mOut.println();
// If you are paying attention, you will notice that
// there is no 'break;' here like there is in other
// places, meaning that if 'Box' was selected, it will
// run the two sets of print statements above and the
// two statements below until the 'break;' statement.
case Rectangle:
mOut.print("A "
+ mLength
+ " by "
+ mWidth
+ " rectangle has a perimeter of: ");
mOut.println(format(Locale.getDefault(), "%.2f", rectanglePerimeter(mLength, mWidth)));
mOut.println();
mOut.print("A "
+ mLength
+ " by "
+ mWidth
+ " rectangle has area of: ");
mOut.println(format(Locale.getDefault(), "%.2f", rectangleArea(mLength, mWidth)));
mOut.println();
break;
case Sphere:
mOut.print("A sphere with radius " + mRadius + " has a volume of: ");
mOut.println(format(Locale.getDefault(), "%.2f", sphereVolume(mRadius)));
mOut.println();
mOut.print("A sphere with radius " + mRadius + " has surface area of: ");
mOut.println(format(Locale.getDefault(), "%.2f", sphereSurfaceArea(mRadius)));
mOut.println();
// Same here as with 'Box' above. If 'Sphere' is picked, it will run the
// two sets of print statements above and the two below until the 'break;'
case Circle:
mOut.print("A circle with radius " + mRadius + " has a perimeter of: ");
mOut.println(format(Locale.getDefault(), "%.2f", circleCircumference(mRadius)));
mOut.println();
mOut.print("A circle with radius " + mRadius + " has area of: ");
mOut.println(format(Locale.getDefault(), "%.2f", circleArea(mRadius)));
mOut.println();
break;
case Triangle:
mOut.print("A right triangle with base "
+ mLength
+ " and height "
+ mWidth + " has a perimeter of: ");
mOut.println(format(Locale.getDefault(), "%.2f", rightTrianglePerimeter(mLength, mWidth)));
mOut.println();
mOut.print("A right triangle with base "
+ mLength
+ " and height "
+ mWidth
+ " has area of: ");
mOut.println(format(Locale.getDefault(), "%.2f", rightTriangleArea(mLength, mWidth)));
mOut.println();
break;
default:
break;
}
}
// TODO -- add your code here
public static double rectangleArea(double length, double width){
return length*width;
}
public static double rectanglePerimeter(double length, double width){
return 2*(length+width);
}
public static double circleArea(double radius){
return Math.PI*(radius*radius);
}
public static double circleCircumference(double radius){
return 2*Math.PI*radius;
}
public static double rightTriangleArea(double base, double height){
return 0.5*base*height;
}
public static double rightTrianglePerimeter(double base, double height){
double hypotenuse=Math.sqrt(base*base+height*height);
return base+height+hypotenuse;
}
public static double boxVolume(double length, double width, double depth){
return length*width*depth;
}
public static double boxSurfaceArea(double length, double width, double depth){
return 2*(length*width+width*depth+depth*length);
}
public static double sphereVolume(double radius){
return (4.0/3.0)*Math.PI*Math.pow(radius,3);
}
public static double sphereSurfaceArea(double radius){
return 4*Math.PI*Math.pow(radius,2);
}
}
These are answers of Java for Android Week 1 Coursera course