Question: ava Practice Questions Topic: equals(), compareTo() and toString() methods What is the result of executing this code? Student s1 = new Student(Bill, Day, 8000089, 3.2,

ava Practice Questions Topic: equals(), compareTo() and toString() methods What is the result of executing this code? Student s1 = new Student(Bill, Day, 8000089, 3.2, 66); Student s1 = new Student(Bill, Day, 8000089, 3.2, 66); if(s1 == s2) System.out.println(Students have the same name); else System.out.println(Students have different names); 2) What is the result of executing this code? if(s1 > s2) System.out.println(Student 1 is greater than student 2); else System.out.println(Student 1 is not greater than student 20); 3) Suppose the fields for the student class are: lastName, firstName, ID, gap, credit hours, and an array of courses taken named sources. Write the toString() method for the student class. Topic: Generating a random number 1) Write the lines of code needed to generate a random even integer in the range of 2 to 100; Topic: Reading from and writing to a data file Write the code to create a Scanner object to read data from a file named C:\salesdata.txt 2) Suppose the file contains 12 items of data. All of the data is of type double and hold the sales amount for each month. Write the loop to a accumulate the total sales for the year. 3) Write the code to output the total sales to a file named: C:\salesdatayear2016.dat Topic: StringBuilder class to manipulate data in a String: What is the major difference in use for the API String class and the API StingBuilder class? Topic: Static Methods A static field belongs to the ______ and not to ________ 2) All static fields must have public access: true or false? 3) Write a call to the static method in the Math class named ceil(). 4) Static methods only have access to what type of fields? Topic: StringTokenizer class 1) What package is the StringTokenizer class in? 2) What is the difference between the three constructor methods of the StringTokenizer class? 3) Name three methods of the StringTokenizer class. 4) Suppose you have the following code: Scanner in = new Scanner(new File(myData.txt); StringTokenizer stok; stok = new StringTokenizer(in.nextLine()); Write the code to print how many tokens are in the line of text Write the code to print each token 5) What is the return type of the method nextToken() 6) Suppose to want to peel off the next token for a double price. Write the line of code to do this double value; Topic: Writing and using copy constructor What is the purpose of a copy constructor? 2) Write the code for a copy constructor for the student class described above. 3) What is the difference between a deep copy and a shallow copy where writing a copy constructor? Topic: Returning an objecto reference from a method What is the return type from this method: Public Fraction add(Fraction addend) 2) What is there parameter to this method: public Fraction add(Fraction addend) Topic: Aggregation What type of relationship is aggregation? 2) A class can only have primate fields. True or false 3) Write a short class definition of a class using aggregation. Only declare the fields and write the constructor and that toString() methods. Topic: Arrays of references Customer [ ] clients; How many objects were created when executing the above line of code? 2) clients = new Customer[25]; How many objects were created when executing the above line of code? 3) What is the result of executing the following line of code: System.out.println(clients[[3].getBalance()); // the Customer class has a getBalance() method 4) Write the code to create the 25 Customer objects using the default constructor and assign each slot in the array the address of a Customer object, 5) Write the code to print the balance of the 5th Customer. 6) Suppose you have this code: book[ ] library = new Book [100]; for (int k = 0; k< library.length; k++) library[k] = new Book( ); Book[ } backup; backup = library; How many arrays were created? How many objects were created? Topic: an array as an object What field does every array object have? 2) Suppose you have this code: double[ ] temperatures = new double[12]; write the lines of code to triple the capacity of the array. topic: Command line arguments What is the argument sent in to main( ) 2) Suppose you have a source code file named DoubleValidator.java that contains the main( ) method. Write the command to compile this class Write the command to run this class after it is compiled: 3) Suppose I type this command: java MyProgram sales.dat 12 What is the value of args.length? What is the value of args[0]? What is the value of args[1]?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!