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

  Write a java statement to have the object from manage

Write a Java statement to have the object from manage its display area by dividing it into 3 rows which have 4 columns each.

  The objective is to implement a menu-based system

The objective is to implement a menu-based system for Bank Accounts in order to simulate a very simple banking system. Many structures have to be declared to manage bank accounts.

  Create an application that keeps tracks of the information

Create an application that keeps tracks of the information in such a simple social network. More specifically, your application will allow for user profiles to be added to, deleted from, or looked-up in the social network.

  Program 2 classes one called student one called grades

program 2 classes one called student one called grades functional requirements ask for how many students u need to

  Write a program called drawing in the form of a public class

Write a program called Drawing in the form of a public class Drawing that extends a Java JFrame and provides the following features.

  Count the occurrences of words in a songs lyrics

Count the Occurrences of words in a song's lyrics, State the approach you will use if you get a hard copy of a song's lyrics.

  The ai player will not be asking

The AI player will not be asking the user for any input. This means that placeShips() and fire() should not ask the user for locations. The AI player should choose locations of ships and automatically place them

  Create a class that implements movieloader

Fill in the empty Frame class that has been provided. Each object of this type will store data consisting of a single frame from an input le.

  Describe the swing applet life cycle

Describe the swing applet life cycle. Create a swing applet that displays the date and time in a JTextField with the JLabel "Today is" when the user clicks a JButton

  Advantages and disadvantages of inline functions

advantages and disadvantages of inline functions

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Create a class to encapsulate the data and behavior

Create a class to encapsulate the data and behavior of a product in a store's inventory. The class should have the following data for an inventory item

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