Write a program that prompts the user to enter an integer

Assignment Help JAVA Programming
Reference no: EM13858091

Multiple Choice and T/F Questions-

1. What is the output of the following statements? _______________

int x = 10;
x++;
int y = 11;
System.out.println(x);

A. 10
B. 11
C. y
D.x

2. 5 % 4 is _____

A. 0
B. 3
C. 4
D. 1

3. The equal comparison operator in Java is __________.

A. !==
B. ^=
C. <>
D. !=

4. To add a to b and store result in a, you write (Note: Java is case-sensitive)

A. b = A + b;
B. b += a;
C. a += b;
D. a = B + a;

5. Which of the following should be declared as a void method?

A. Write a method that converts an uppercase letter to lowercase.
B. Write a method that returns a random integer from 1 to 100.
C. Write a method that prints integers from 0 to 10.
D. Write a method that checks whether current second is an integer from 1 to 60.

6. Android apps are developed with Java.

True/False

7. Microsoft Visual Studio is the recommended integrated development environment for Android development, though developers may also use a text editor and command-line tools to create Android apps.

True/False

8. Layout files are stored in the project's res/menu folder.

True/False

9. A LinearLayout always arranges GUI components horizontally.

True/False

10. Android development is a combination of GUI design, Java, and XML coding.

True/False

Short Answer Questions-

11. Assume x is 80. What is the output of the following statement? Briefly explain your answer.

if (x >= 80){
System.out.print("A");
}
else if (x >=60){
System.out.print("B");
}
else{
System.out.print("C");
}

12. Write a program that prompts the user to enter an integer. If the number is a multiple of 3, print "Multiple of 3."Otherwise, print "Not Multiple of 3." Here are the sample runs:

<Output>
Enter an integer: 6
Multiple of 3
<End Output>

<Output>
Enter an integer: 10
Not Multiple of 3
<End Output>

13. What is the output for y?Briefly explain your answer.

int y = 0;
for (int i = 2; i <4; i++) {
y += i;
}
System.out.println(y);

14. What is the output of running the class C. Briefly explain your answer.

class A {
public String toString() {
return "AA";
}
}

class B extends A {
public String toString() {
return "BB";
}
}

public class C extends B{
public static void main(String[] args) {

A a = new A();
Bb = new B();
C c = new C();
System.out.println(a.toString()); // toString "A"
System.out.println(b.toString()); // toString "B"
System.out.println(c.toString()); // toString "B"
}
}

15. Change the following whilestatement using thefor statement.

int x = 1;
while (x <5){
System.out.println(x);
x++;
}

16. Complete the code:

public class Test {
public static void main(String[] args) {
int i = 4; int j = 5;

// Fill in the code to invoke the printAverage method to display the average of i and j.

}

public static void printAverage(int i, int j) {
// Fill in the code here to display the average of i and j.

}

}

17. How many times x will be printed? Briefly explain your answer.

int x = 1;
while (x <10){
System.out.println(x);
x++;
}

18. Create setter and getter for each member variable in the following class:

public class Stock {
private String stockName;
private double currentPrice;

// create a setter for "stockName"

// create a getter for "stockName"

// create a setter for "currentPrice"

// create a getter for "currentPrice"

}

19. Assume that you have the following xml file in your res/layout folder and the name of the xml file is activity_main.xml:

119_Code.png

(a) In order to display this user interface, what method call in Java will you use and how would you write that entire method call?

(b) How would the above layout xml file display on the screen?

20. Short Answer Questions (10 points)

(a) Suppose that "car_small.png" file is located in res/drawable folder.

- How can you refer to this file in Java code?

- How can you refer to this file in the layout XML file?

Reference no: EM13858091

Questions Cloud

Complete a whs hierarchy for home construction business : In this assessment you are required to complete a WHS Hierarchy for one of the following; Home construction business and Car crash repair business
Why does shell find out about the views of interest groups : Why does shell find out about the views of interest groups and pressure groups? How can this information help shell to make better decisions?
Describe the initial cause of the adverse event : Describe the initial cause of the ‘adverse event', what actually happened, what the aftermath was, and your chosen positive outcome that came from it.(oil spills disaster 1967).
Prepare a budgeted income statement for 2014 : Prepare a budgeted income statement for 2014 and Interest expense is expected to be $3,500 for the year. Income taxes are expected to be 40% of income before income taxes.
Write a program that prompts the user to enter an integer : Write a program that prompts the user to enter an integer. If the number is a multiple of 3, print "Multiple of 3."Otherwise, print "Not Multiple of 3." Here are the sample runs:
Question regarding the central limit theorem : Problem 1: In a population µy = 100 and σ2y = 43. Use the central limit theorem to answer the following question:
Prepare the intangible assets section of montana matt : Prepare the intangible assets section of Montana Matt's Golf Inc. at December 31, 2013. How much amortization expense is included in Montana Matt's income for the year ended December 31, 2013? Show all supporting computations.
Us coffee market- size of the total retail market : U.S. Coffee Market- Make and justify the following forecasts, a. the size of the total retail market in 1983 and 1988, b. the split of the market by major segments (decaf versus caf., etc.)
Economy with the production function : Consider an economy with the production function Y  = L(1 / 3) a) Derive the Labor demand Curve

Reviews

Write a Review

JAVA Programming Questions & Answers

  Palindrome is a sequence of char that reads backward forwrd

A palindrome is a sequence of characters that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554, and 11611. Write an application called Palindrome.java that asks the user t..

  Various ways of exception handling

Various ways of exception handling

  The java code conventions

The database must be able to retrieve client information and display it on the screen for a specific telephone number match. The program must be well commented and documented using javadoc. The program must conform to the Java Code Conventions

  The program randomly generates the quiz question one by

the program randomly generates the quiz question one by one from a set of available questions on general knowledge

  Writing a java program that provides simple statistics

You will be writing a Java program that provides simple statistics about the input data. The method stubs are given below. This assignment will give you experience with methods

  Afterwards a way for the user to input

And so on and so forth then afterwards a way for the user to input that they finished a particular task on the list. After the user has input that they have finished a particular task the program should be print "Good Job!" or "Keep it up!"

  Typical industrial engineering problem

A company manufactures two products, A and B. Product A can be sold for $145 per unit and B for $75 per unit. Management requires that at least 1850 units be manufactured each month.

  Using your musicalinstrument class

Finally, create a Java test class that simulates using your MusicalInstrument class.  In your test class you should at a minimum: a) Construct 4 instances of your instrument, b) tune your instruments, c) print the name of your instrument d) print ..

  Java application that asks a user to enter two integers

Write a Java application that asks a user to enter two integers (A and B) and then display the results of A/B. Catch any division by zero errors and prompt the user to reenter the value of B. Be sure your code compiles and runs as expected. Name your..

  Run the code

Run the following code, Explain the output aYer you let it run 20 seconds, 5 minutes, 10 minutes.

  Rationale for declaring an array of objects of the class

Explain the dimension of the array and why you chose that number of elements for the object array.Can you give the answer ASAP?

  Anbsp build a student record managing system application by

a.nbsp build a student record managing system application by doing the following1.nbsp create a student inheritance

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd