Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Exercise AnswerLab2.txt A. This question refers to variables data1 and data2 in class TestDataTypes. For each one of the following statements indicate whether the

Java Exercise

image text in transcribed

AnswerLab2.txt

A. This question refers to variables data1 and data2 in class TestDataTypes. For each one of the following statements indicate whether the comparison will return the value true or false

data1 == data2: true or false? data1.intVar == data2.intVar: true or false? data1.charVar == data2.charVar: true or false? data1.boolVar == data2.boolVar: true or false? data1.doubleVar == data2.doubleVar: true or false? data1.varA == data2.varA: true or false? data1.varA.numItems == data2.varA.numItems: true or false? data1.varA.arrItems == data2.varA.arrItems: true or false?

B. How many of your answers to question 1 were incorrect?

C. Why was the result of the last comparison true, even though arrays are non-primitive types?

image text in transcribed

Given information: image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Exercise 1 - Comparing Primitive and Non-Primitive Data Types 1. Create a new Project (select File > New > Java Project) and name it: Lab2 2. Add to this project all provided classes. 3. Note. Eclipse might indicate that there are compilation errors in some of these classes. We will deal with these errors later. For the time being ignore any warnings that Eclipse gives about compilation errors (if any popup windows appear when you try to compile and run the code, just close them and continue with the exercises). 4. Open and read the provided java classes DataTypes.java, ClassA.java, and TestDataTypes.java. Do not modify TestDataTypes.java yet! 5. Answer question 1 in AnswersLab2.txt 6. Add code to TestDataTypes.java to perform all comparisons in question 1 of AnswersLab2.txt. If a comparison is true the code must print "true", otherwise it must print "false. For example, to compare data1 and data2 you can add this code if (data1 == data2) System.out.println("data1 == data2 is true"); else System.out.println("data1 == data2 is false); 7. Indicate in AnswersLab2.txt how many of your answers for question 1 were incorrect. Also, answer question 3. DataTypes.java TestDataType... J TestEquals.java ClassA.java X J ClassB.java ClassC.java CountObject... 1 ublic class ClassA { 2 private final int SIZE_ARRAY = 5; 3 public int numItems; 4 public int[] arrItems; 5 60 public ClassA(int n, int[] arr) { 7 numItems = n; 8 arrItems = arr; 9 } 10 110 public ClassA() { 12 numItems = 0; 13 arrItems = new int[SIZE_ARRAY]; 14 } 15 } 16 J DataTypes.java J TestDataType... TestEquals.java ClassA.java ClassB.java X J ClassC.java CountObject... 1| 2 public class Class { 3 4 private int counter = 0; 5 6e public Class() { 7 counter = 1; 8 } 9 100 public void incCounter() { 11 ++counter; 12 } 13 140 public int getCounter() { 15 return counter; 16 } 17 180 public static void main(String[] args) { 19 int i; 20 21 i = counter; 22 incCounter(); 23 System.out.println("i = + i + counter = 24 } 25 26 } 27 + counter); 3 DataTypes.java TestDataType... TestEquals.java J ClassA.java J ClassB.java ClassC.java X CountObject... 1| 2 public class ClassC { 3 4 private int counter = 0; 5 60 public Class() { 7 counter = 1; 8 } 9 100 public void incCounter() { 11 ++counter; 12 } 13 140 public int getCounter() { 15 return counter; 16 } 17 18 } 19 TestEquals.java 5 6 ClassA.java ClassB.java J ClassC.java CountObject... X DataTypes.java TestDataType... 1 2 public class CountObjects { 3 40 public static void main(String[] args) { int numObjects; Class C = null; 7 for (int i = 0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management With Website Development Applications

Authors: Greg Riccardi

1st Edition

0201743876, 978-0201743876

More Books

Students also viewed these Databases questions

Question

How reliable is this existing information?

Answered: 1 week ago

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago