Posts Tagged ‘Java’
Design and implement a class called Sphere that contains instance data that represents the sphere’s diameter.
LANGUAGE: Java CHALLENGE: Design and implement a class called Sphere that contains instance data that represents the sphere’s diameter. Define the Sphere constructor to accept and initialize the diameter, and include getter and setter methods for the diameter. Include methods calcVolume and calcSurfaceArea that calculate and return the volume and surface area of the sphere.…
Read MoreAssume that an array named salarySteps whose elements are of type int and that has exactly five elements has already been declared.
LANGUAGE: Java CHALLENGE: Assume that an array named salarySteps whose elements are of type int and that has exactly five elements has already been declared. Write a single statement to assign the value 30000 to the first element of this array.
Read MoreGiven Suppose the values of the array a BEFORE your code executed were: 15,7,22,4.
LANGUAGE: Java CHALLENGE: Given Suppose the values of the array a BEFORE your code executed were: 15,7,22,4. Then, AFTER your code executed, the values of the array a would be: 3,7,22,4. Note that the value of the first element was changed to 3. that an array named a with elements of typeint has been declared,…
Read MoreWrite a method, getSecondLine, that is passed a String argument and that returns the second line, without its newline character.
LANGUAGE: Java CHALLENGE: Write a method, getSecondLine, that is passed a String argument and that returns the second line, without its newline character. (Recall that lines are terminated with the “\n” character .) Assume that the argument contains at least two complete, newline-terminated lines.
Read MoreWrite a method, getFirstLine, that is passed a String argument and that returns the first line.
LANGUAGE: Java CHALLENGE: Write a method, getFirstLine, that is passed a String argument and that returns the first line. (Recall that lines are terminated with the “\n” character.) Assume that the argument contains at least one complete, newline-terminated line.
Read MoreWrite a method, makeEmailAddress, that is passed two String arguments: the first is a username, like “leadbelly” and the second is a domain name, like “blues.com”.
LANGUAGE: Java CHALLENGE: Write a method, makeEmailAddress, that is passed two String arguments: the first is a username, like “leadbelly” and the second is a domain name, like “blues.com”. The method returns an email address formed from joining these with an “@”: “[email protected]”.
Read MoreWrite a method, getEmailDomain, that is passed a String argument that is an email address and returns the domain name part. So if “[email protected]” is passed, the method returns “salzberg.de”.
LANGUAGE: Java CHALLENGE: Write a method, getEmailDomain, that is passed a String argument that is an email address and returns the domain name part. So if “[email protected]” is passed, the method returns “salzberg.de”. Assume that the argument will always be a correctly formatted email address.
Read MoreWrite a method, getEmailUserName, that is passed a String argument that is an email address and returns the user-name part.
LANGUAGE: Java CHALLENGE: Write a method, getEmailUserName, that is passed a String argument that is an email address and returns the user-name part. So if “[email protected]” is passed, the method returns “mozart”. Assume that the argument will always be a correctly formatted email address.
Read MoreWrite a method, makeSubjectLine, that gets a String argument and returns the same String but with “Subject: ” in front of it. So if the argument is “Are you going to the show?” the method returns “Subject: Are you going to the show?”.
LANGUAGE: Java CHALLENGE: Write a method, makeSubjectLine, that gets a String argument and returns the same String but with “Subject: ” in front of it. So if the argument is “Are you going to the show?” the method returns “Subject: Are you going to the show?”.
Read MoreWrite the definition of a class Counter containing: An instance variable named counter of type int An instance variable named limit of type int. A constructor that takes two int arguments and assigns the first one to counter and the second one to limit
LANGUAGE: Java CHALLENGE: Write the definition of a class Counter containing: An instance variable named counter of type int An instance variable named limit of type int. A constructor that takes two int arguments and assigns the first one to counter and the second one to limit A method named increment. It does not take…
Read MoreWrite an application that reads the (x,y) coordinates for two points.
LANGUAGE: Java CHALLENGE: Write an application that reads the (x,y) coordinates for two points. Compute the distance between the two points using the following formula: Distance = the square root of the sum of the square of the difference of the x coordinates and the square of the difference of the y coordinates
Read MoreDesign a class named MyInteger
LANGUAGE: JAVA CHALLENGE: (The MyInteger class ) Design a class named MyInteger. The class contains: * An int data field named value that stores the int value represented by this object. * A constructor that creates a MyInteger object for the specified int value. A getter method that returns the int value. * The methods…
Read More