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

  Design a boolean function named isprime,

A prime number is a number that is only evenly divisible by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime because it can be divided evenly by 1, 2, 3, and 6. Des..

  Questions of java programming

Write a program that opens a .txt, reads the contents of the file line by line, and prints the content of each line. To do this, you should use look up how to use the Buffered Reader class1. Remember to use the try and catch statements to handle e..

  1 write a recursive instance method called

1 write a recursive instance method called countconnectedpipesint row int col. the method must not contain any loops

  Method that receives an array and returns with no duplicate

Write a program that contrains a method that receives an array and returns a new array with no duplicates.

  Create a class for services offered by a hair-styling salon

Create a class for services offered by a hair-styling salon. Data fields include a String to hold the service description and write an application named Salon Report that contains an array to hold six Service objects and fill it with the data

  Summary of the case astrazeneca-unitedhealth

What is the summary of the case "AstraZeneca, UnitedHealth, and Others: IT-Asset Management- Do you know what youv've got?"

  Implement class that can be player in a game of tic tac toe

Specify, design, and implement a class that can be one player in a game of tic-toc-toe. The constructor should be specify whether the object is to be the first player (X's) or the second player (O's).

  Write a java program to register students for a college

Project is for designing and developing a College Registration program. Write a Java program to register students for a college

  Write complete java program assuming that the variables gpa

Write a complete java program assuming that the variables gpa, studentName and deanList have been declared, you should read in the gpa and studentName from keyboard.

  Program that initializes an array with ten random integers

Write a JAVA program that initializes an array with ten random integers and then prints four lines of output, containing

  1design an abstract data type in java that represents a

1.design an abstract data type in java that represents a musical pitch noteadt.java. the adt should store the note or

  Assignment related to java programming

Question 1: Write a java program to compute the squares of the numbers in the array list like 1, 2, 3, 4... up to 50. Question 2: Write a java program to compute the sum of numbers and average in the array list up to 50.

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