1. Write TWO (2) different ways to create an object from the String class. - define literally (String str = “Hello!”; ) - using new operator 2. What is the output for the following Java statements? String phr = new String("Big,blue sky"); System.out.println(phr.substring(phr.indjexOf(","),7)); Ans: ,blu 3. Give your description on the output that will be produced by the execution of the following statements. Random rd = new Random(); System.out.println(rd.nextInt(41) + 10); Ans: The output will be a random number from 0 to 40 which is added with 10. 4. Write Java code segment that use class Random to generate two random numbers that is great...
Task 1 // The Triangle class stores and manipulates data for a //triangle. public class Triangle { private double height; private double base; // The setHeight method accepts an argument which is //stored in the height field. public void setHeight(double len) { height = len; } // The setBase method accepts an argument which is //stored in the base field. public void setBase(double b) { base = b; } //The set method accepts two arguments which are //stored in the h...
TASK 1 Based on the following UML class diagram : a) Write a complete Student class. b) Next, write TestStudent class that invokes the methods of the Student class and applies the concept of an array of objects. c) Sample run as given below: User’s inputs Matric No : s1111 Test 1 : 67 Test 2 : 45 Matric No : s2222 Test 1 : 67 Test 2 : 98 Matric No : s3333 Test 1 : 67 Test 2 : 90 Program outputs ***************************** STUDENT INFORMATION ***************************** Matric No AverageMark s1111 ...
Comments
Post a Comment