4. Write an if/else statement in ternary format that compares the value of two int variables, firstNum and secondNum, and sets the value of an int variable minValue appropriately as follows: minValue should be the minimum of firstNum and secondNum.
5. Assume that Person is a predefined class and that the declaration Person[] people; has already been performed. Then the instruction
People = new Person [200];
Reserves memory space for(Circle the answer):
Option 1: a single Person object
Option 2: 200 Person objects
Option 3: a single reference variable that points to a single Person object
Option 4:200 reference variables and 200 Person objects
Option 5: 200 reference variable, each of which can point to a separate Person object
Option 6: a single reference variable to the memory that stores all 200 Person objects
6. Consider a method defined as follows:
Public void myMethod(double x, int y):
Circle which of the following method calls is legal? (zero, one, or more answers may be correct)
Option 1: myMethod();
Option 2: myMethod(-1);
Option 3: myMethod(7 * 3.0, 7 /14);
Option 4: myMethod(37, 0.5);
7. Given two String variables, string1 and string2, write a line of code that would determine if they have the same length
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Question 4:
Answer : minValue=(firstNum>secondNum)?secondNum:firstNum;
Explanation :Below screen shows the Java code for ternary operator.
*****************************
Question 6:
Answer : Option 3: myMethod(7 * 3.0, 7 /14);
Explanation :for myMethod(double,int) which calls myMethod(7 * 3.0, 7 /14);
*****************************
Question 7:
Explanation :Below code snippet gives the details
public class Main
{
public static void main(String[] args) {
//declaring strings
String string1="asdf",string2="pqrs";
//checking strings
if(string1.length()==string2.length())
{
System.out.println("Equal");//display equal
}
else{
System.out.println("Not Equal");//display not
equal
}
}
}
Output :
*****************************
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.
4. Write an if/else statement in ternary format that compares the value of two int variables,...
4. Write an if/else statement in ternary format that compares the value of two int variables, firstNum and secondNum, and sets the value of an int variable minValue appropriately as follows: minValue should be the minimum of firstNum and secondNum. 5. Assume that Person is a predefined class and that the declaration Person[] people; has already been performed. Then the instruction People = new Person [200]; Reserves memory space for(Circle the answer): Option 1: a single Person object Option 2:...
5. Assume that Person is a predefined class and that the declaration Person[] people; has already been performed. Then the instruction People = new Person [200]; Reserves memory space for(Circle the answer): Option 1: a single Person object Option 2: 200 Person objects Option 3: a single reference variable that points to a single Person object Option 4:200 reference variables and 200 Person objects Option 5: 200 reference variable, each of which can point to...
Download BankAccount.java and BankAccountTester.java starting files and drag and drop them into your eclipse project. The BankAccount class declaration in file BankAccount.java is the blueprint of a BankAccount object. Check out the design of a BankAccount class. 1. In BankAccount.java class, all of the method stubs ( methods with a header but empty bodies ) are present to help you get started. Your task is to complete the method bodies. All comments in red in the diagram above indicates what...
Lab 7 Add three instance variables to your class RightTriangle from lab 5. The first two are of type int and are called xLoc and yLoc and the third is of type int called ID. Also add a static variable of type double called scaleFactor. This should be initialized to a default value of 1. Update the constructor to set the three new instance variables and add appropriate get and set methods for the four new variables. All set methods...
Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters long encryptedPassword : String key int Must be between 1 and 10(inclusive) accountId - A unique integer that identifies each account nextIDNum – a static int that starts at 1000 and is used to generate the accountID no other instance variables needed. Default constructor – set all instance variables to a default value. Parameterized constructor Takes in clearPassword, key. Calls encrypt method to create...
-------------------------------------------------------------------- 1. How does Java support the concept of encapsulation? -------------------------------------------------------------------- 2. Describe the difference between an object and a class. -------------------------------------------------------------------- 3. What is the difference between the contents of a Java variable of a primitive type and a Java variable of a class type? -------------------------------------------------------------------- 4. (a) How is a 'static' class method different from a regular (non-static) class method? (b) How is a 'static' variable in a class different from a regular (instance) variable in a class?...
* The Map class is used to create and manipulate voting maps. The value of a * cell on the map denotes the party for which the majority of the population * of that cell votes for. For instance, in the following map, PARTY_X is the * choice of voters in three cells, while PARTY_O is preferred in the rest of * the map: * O X O * X O X * O O O * A map is...
In a new file located in the same package as the class Main, create a public Java class to represent a photograph that consists of a linear (not 2D) array of pixels. Each pixel is stored as an integer. The photograph class must have: (a) Two private fields to represent the information stored about the photograph. These are the array of integers and the date the photograph was taken (stored as a String). The values in the array must be...
In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program to create a database of dogs of your own. You will also include File I/O with this program. You will create 3 classes for this assignment. The first class: Create a Class representing the information that is associated with one item (one dog) of your database. Name this class Dog. Using Lab 3, this will include the information in regard to one dog. The...
Use BlueJ to write a program that reads a sequence of data for several car objects from an input file. It stores the data in an ArrayList<Car> list . Program should work for input file containing info for any number of cars. (You should not assume that it will always be seven lines in the input file). Use notepad to create input file "inData.txt". File should be stored in the same folder where all files from BlueJ for this program...