Introduction to Java Programming and Data Structures Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134700144
Author: Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 6.4, Problem 6.4.10CP
Program Plan Intro
Block styles:
In
Example of next-line style:
public class Sample
{
public static void main(String[] args)
{
System.out.println("Sample");
}
}
Example of End-of-line style:
public class Sample{
public static void main(String[] args){
System.out.println("Sample");
}
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Method Overloading is a feature that allows a class to have two or more methods having
same name, if their argument lists are different. Argument lists could differ in:
1. Number of parameters.
2. Data type of parameters.
3. Sequence of Data type of parameters.
Write different version of method sum() that display the sum of the values received as
parameter according to the following main method content:
public static void main(String[] args)
{
sum ( 10, 10 );
sum ( 10, 10, 10 );
sum ( 10.0, 10.0 );
sum ( 10, 10.0 );
sum ( 10.0, 10);
}
You have to define five functions with the specified types. Then, demonstrate the Argument
Promotion concept by reducing the number of method to two.
C++ OOP use classes only...
Complete the following piece of java code (MyDate class). The semicolon after each method must be replaced with a set of curly braces, in which the instructions for the method are placed.
Think of one error and add error handling to your program
Create a class diagram for the MyDate class.
Create a test class to test mydate (main class with a main method)
public class MyDate { /* If no arguments were provided then default the date January 1st, 1970 (epoch time). */ public MyDate(); /* Creates a new MyDate from an existing MyDate */ public MyDate( MyDate date); /* Creates a new MyDate from a day, month, and year */ public MyDate( int day, int month, int year); /* Returns the day of the month for this MyDate */ public int getDay(); /* Returns the month of the year for this MyDate */ public int getMonth(); /* Returns the year for this MyDate */ public int getYear(); /* Returns true if this MyDate represents a date in a leap year */…
Chapter 6 Solutions
Introduction to Java Programming and Data Structures Comprehensive Version (11th Edition)
Ch. 6.4 - What are the benefits of using a method?Ch. 6.4 - Prob. 6.4.2CPCh. 6.4 - How do you simplify the max method in Listing 6.1...Ch. 6.4 - Prob. 6.4.4CPCh. 6.4 - Prob. 6.4.5CPCh. 6.4 - Prob. 6.4.6CPCh. 6.4 - Prob. 6.4.7CPCh. 6.4 - Write method headers (not the bodies) for the...Ch. 6.4 - Identify and correct the errors in the following...Ch. 6.4 - Prob. 6.4.10CP
Ch. 6.5 - Prob. 6.5.1CPCh. 6.5 - Identify and correct the errors in the following...Ch. 6.5 - Prob. 6.5.3CPCh. 6.5 - Prob. 6.5.4CPCh. 6.6 - Prob. 6.6.1CPCh. 6.6 - Prob. 6.6.2CPCh. 6.7 - What is hexCharToDecimal ( B)) ? What is...Ch. 6.8 - What is method overloading? Is it permissible to...Ch. 6.8 - What is wrong in the following program? public...Ch. 6.8 - Given two method definitions, public static double...Ch. 6.9 - Prob. 6.9.1CPCh. 6.9 - What is the scope of a local variable?Ch. 6 - (Math: pentagonal numbers) A pentagonal number is...Ch. 6 - (Sum the digits in an integer) Write a method that...Ch. 6 - (Palindrome integer) Write the methods with the...Ch. 6 - (Display an integer reversed) Write a method with...Ch. 6 - (Sort three numbers) Write a method with the...Ch. 6 - (Display patterns) Write a method to display a...Ch. 6 - (Financial application: compute the future...Ch. 6 - (Conversions between Celsius and Fahrenheit) Write...Ch. 6 - Prob. 6.9PECh. 6 - (Use the isPrime Method) Listing 6.7,...Ch. 6 - (Financial application: compute commissions) Write...Ch. 6 - (Display characters) Write a method that prints...Ch. 6 - (Sum series) Write a method to compute the...Ch. 6 - (Estimate ) can be computed using the following...Ch. 6 - (Financial application: print a tax table) Listing...Ch. 6 - Prob. 6.16PECh. 6 - Sections 6.10 and 6.11 6.17 (Display matrix of 0s...Ch. 6 - (Check password) Some Websites impose certain...Ch. 6 - (Triangles) Implement the following two methods: /...Ch. 6 - (Count the letters in a string) Write a method...Ch. 6 - (Phone keypads) The international standard...Ch. 6 - (Math: approximate the square root) There are...Ch. 6 - (Occurrences of a specified character) Write a...Ch. 6 - (Display current date and time) Listing 2.7,...Ch. 6 - Prob. 6.25PECh. 6 - (Palindromic prime) A palindromic prime is a prime...Ch. 6 - (Emirp) An emirp (prime spelled backward) is a...Ch. 6 - (Mersenne prime) A prime number is called a...Ch. 6 - (Twin primes) Twin primes are a pair of prime...Ch. 6 - (Game: craps) Craps is a popular dice game played...Ch. 6 - (Financial: credit card number validation) Credit...Ch. 6 - (Game: chance of winning at craps) Revise...Ch. 6 - (Current date and time) Invoking System....Ch. 6 - (Print calendar) Programming Exercise 3.21 uses...Ch. 6 - (Geometry: area of a pentagon) The area of a...Ch. 6 - (Geometry: area of a regular polygon) A regular...Ch. 6 - (Format an integer) Write a method with the...Ch. 6 - (Generate random characters) Use the methods in...Ch. 6 - (Geomentry: point position) Programming Exercise...
Knowledge Booster
Similar questions
- Note: It`s python coding 1. Class Implementationa) Implement a class Rectangle with two attributes, width and height.b) Implement an init method with an optional parameter type. Set the default value of the attributes of width and height to 1.c) Implement a display method to print the values of width and height.d) Instantiate two objects of type rectangle, one with arguments one without. r1 = Rectangle(4, 5) r2 = Rectangle()e) Call display() to print width and height.Example OutputWidth: 4Height: 5Width: 1Height: 1arrow_forwardFind the errors in the following code: The following is someone’s definition for the Checking class. public class Checking { //Only one attribute (for simplicity, nothing wrong here) private double balance; public void Checking(double iniBalance){ setbalance(iniBalance); } // Define getter and setter public String getbalance(){ return balance; } public void setbalance(double newbalance){ double balance = 0; if(newbalance>0){ //validity check balance = newbalance; } else{ System.out.println("Your input is invalid!"); } } }arrow_forwardNote: It`s python codingarrow_forward
- 1st picture: make a complete programming code in the given picture. Use pre-defined for the stak. Picture 2: Test. The outcome of the program when it runs.arrow_forwardNote: The code is written you can just tell the explanation what is happening in the code Explain in English.Just explain the whole code. #include <iostream>using namespace std;class PrimeNumberGenerator{private:int counter;public://ConstructorPrimeNumberGenerator() : counter(0){}//Function to reset countervoid reset(){counter = 0;}int getCounter(){return counter;}//Function to return next prime number after currentPrimeint getNextPrime(){if(counter == 0){counter = 2;}else{for(int i = counter + 1; ; i++){if(isPrime(i)){counter = i;break;}}}return counter;} //Function to check if a number is prime or notbool isPrime(int num){for(int i = 2; i <= num/2; i++){if(num % i == 0)return false;}return true;}}; int main() {int option;PrimeNumberGenerator gen;cout << "Enter 1 if you want to reset\n";cout << "Enter 2 if you want to get next prime number\n";cout << "Enter -1 to quit: ";cin >> option;while(option != -1){if(option == 1){gen.reset();cout <<…arrow_forward2. Problem (Cylinder.java) (SEE ATTACHED PHOTO FOR CORRECTION)CREATE A Cylinder.java programa. Implement a class called Cylinder. A cylinder has a circle and one additional data member for representing the height (type float).b. Create appropriate constructors for your Cylinder class.c. Encapsulate it.d. Include methods for finding the volume and area of your Cylinder. area = 2 * (area of the circle in this cylinder) + 2 * pi * radius + height volume = (area of the circle in this cylinder) * heighte. Override the toString method of the Object class. Try to use the toString of the Circle class and then just concatenate the remaining values.f. Override the equals method of the Object class. Two Cylinder objects are equal if they have the same center and the same radius and the same height. g. Write a simple main method that creates Cylinder objects and tests each of the methods that you have defined.arrow_forward
- (iv) Write a public instance method addProgrammeItem() that takes a Music argument representing a musical work and returns no value. As long as the running time of the concert will not exceed MAX_LENGTH by adding the item to the programme, the Music object is added to the programme. If it would make the running time too long, the message "Running time exceeded" is printed insteaarrow_forwardproblem statement: Write a java classStringCheckto do the below given checks on accepted string or strings. Each function should be coded in separate methods of the class. Give appropriate instance variables to implement the method. The user should be able to enter the string through the main function in Main class. Use a constructor to initialize the String entered by the user. Use the Main class to test all the methods in StringCheckclass. The programs should have the below given checklist: 1)Define classStringCheck with required instance variables 2)The StringCheck class should have six methods to do the below functions: *Check if the user entered string is a simple sentence? (Starts with capital letter, Ends with period, space between words). *Check if the user entered string is a question? (Check if the string starts with ac apital letter ends with a question mark, space between words) *Check if the user entered string have numbers in it? *Check if string is a valid email *Check…arrow_forwardExplain how primitive types and reference types are passed to a methodarrow_forward
- Explainarrow_forwardNote: It`s python codingarrow_forwardIn C++ QUESTION 14 class rectangleType { public: void setLengthWidth(double x, double y); //Sets the length = x; width = y; void print() const; //Output length and width double area(); //Calculate and return the area of the rectangle (length*width) double perimeter(); //Calculate and return the perimeter (length of outside boundary of the rectangle) private: double length; double width; }; Write the function definition for the function perimeterarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education