Write a class called Chunker that satisfies the following specification: Class Chunker A Chunker object is...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a class called Chunker that satisfies the following specification: Class Chunker A Chunker object is used to store string data and retrieve it in substrings (i.e. 'chunks') of length N. Instance variables String data; N; // The string data stored in the Chunker. // The chunk size, N. Constructors Chunker(int chunkSize) // Create an empty Chunker ie. set N to chunkSize and set data to the empty string. Methods public void add(String string) // Append the given string to the end of the existing data string. public boolean hasNexChunkt() // Returns true if a sub string length N can be removed from the front of the stored string data. public String nextChunk() // Remove a sub string length N from the front of the stored string data. 15:08 Tests & Quizzes public void add(String string) // Append the given string to the end of the existing data string. public boolean hasNexChunkt() // Returns true if a sub string length N can be removed from the front of the stored string data. public String nextChunk() // Remove a sub string length N from the front of the stored string data. public boolean isEmpty() // Returns true if the Chunker is empty. Consider the following code snippet: // ... Chunker chunker = new Chunker (3); chunker.add("Go"); chunker.add("Then!"); System.out.printf("%s, %s\n", chunker.nextChunk (), chunker.next Chunk () ); System.out.printf("%b, %b\n", chunker.hasNext Chunk (), chunker.isEmpty()); // ... The output will be "Got, hen" then "false, false". HINT: "Town".substring (1, 3) is "ow". You may consult your paper notes and textbook, but no electronic resources. You may NOT use a search engine or consult any Web resources (including Vula) or files on your flash disk, hard drive, etc. Write a class called Calendar that satisfies the following specification: Class Calendar A Calendar object is used to represent time, expressed as day, month and year. Instance variables int day, month, year; // The current day, month and year. int[] daysInMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); // A 12-element array giving days per month where the value for January is at index 0. Constructors Calendar(int d, int m, int y) // Create a calendar object set to the given day, month and year. Methods public String current() // Returns the current date expressed as a String in the form <day>/<month>/<year> e.g. 3/4/2019. public void advance() // Advance the current date by one day Consider the following code snippet: // ... Calendar calendar = 2000); System.out.println(calendar.current()); calendar.advance(); new Calendar (28, 2, System.out.println(calendar.current()); calendar.advance(); System.out.println(calendar.current()); //... The output will be "28/2/2000", then "29/2/2000", and then "1/3/2000". HINT: • With reference to the specification, daysInMonth is an array. so for example, daysInMonth [0] is 31, and daysInMonth [1] is 28. ● A year, y, is a leap year if y%4= = 0 &&y%100!=0|1y%400 == 0 Write a class called Chunker that satisfies the following specification: Class Chunker A Chunker object is used to store string data and retrieve it in substrings (i.e. 'chunks') of length N. Instance variables String data; N; // The string data stored in the Chunker. // The chunk size, N. Constructors Chunker(int chunkSize) // Create an empty Chunker ie. set N to chunkSize and set data to the empty string. Methods public void add(String string) // Append the given string to the end of the existing data string. public boolean hasNexChunkt() // Returns true if a sub string length N can be removed from the front of the stored string data. public String nextChunk() // Remove a sub string length N from the front of the stored string data. 15:08 Tests & Quizzes public void add(String string) // Append the given string to the end of the existing data string. public boolean hasNexChunkt() // Returns true if a sub string length N can be removed from the front of the stored string data. public String nextChunk() // Remove a sub string length N from the front of the stored string data. public boolean isEmpty() // Returns true if the Chunker is empty. Consider the following code snippet: // ... Chunker chunker = new Chunker (3); chunker.add("Go"); chunker.add("Then!"); System.out.printf("%s, %s\n", chunker.nextChunk (), chunker.next Chunk () ); System.out.printf("%b, %b\n", chunker.hasNext Chunk (), chunker.isEmpty()); // ... The output will be "Got, hen" then "false, false". HINT: "Town".substring (1, 3) is "ow". You may consult your paper notes and textbook, but no electronic resources. You may NOT use a search engine or consult any Web resources (including Vula) or files on your flash disk, hard drive, etc. Write a class called Calendar that satisfies the following specification: Class Calendar A Calendar object is used to represent time, expressed as day, month and year. Instance variables int day, month, year; // The current day, month and year. int[] daysInMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); // A 12-element array giving days per month where the value for January is at index 0. Constructors Calendar(int d, int m, int y) // Create a calendar object set to the given day, month and year. Methods public String current() // Returns the current date expressed as a String in the form <day>/<month>/<year> e.g. 3/4/2019. public void advance() // Advance the current date by one day Consider the following code snippet: // ... Calendar calendar = 2000); System.out.println(calendar.current()); calendar.advance(); new Calendar (28, 2, System.out.println(calendar.current()); calendar.advance(); System.out.println(calendar.current()); //... The output will be "28/2/2000", then "29/2/2000", and then "1/3/2000". HINT: • With reference to the specification, daysInMonth is an array. so for example, daysInMonth [0] is 31, and daysInMonth [1] is 28. ● A year, y, is a leap year if y%4= = 0 &&y%100!=0|1y%400 == 0
Expert Answer:
Related Book For
Starting Out With Java From Control Structures Through Data Structures
ISBN: 9780133957051
6th Edition
Authors: Tony Gaddis
Posted Date:
Students also viewed these programming questions
-
Discuss the legal remedies that are available to an employee who is bullied or harassed in the workplace.
-
Demand function for a firm is given as P-100e, if the firm's average cost (AC) is AC 5+50, determine the firm's maximum profit. (5marks).
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
A reaction for which H = + 98.8 kJ and S = + 141.5 J/K is ________ (spontaneous or nonspontaneous) at low temperatures and ________ (spontaneous or nonspontaneous) at high temperatures.
-
Saturated steam at 110C is condensed in a shell-and-tube heat exchanger (1 shell pass; 2, 4,... tube passes) with a UA value of 2.5 kW/K. Cooling water enters at 40C. (a) Calculate the cooling water...
-
Assume that Department A has a higher contribution margin ratio but a lower responsibility mar gin ratio than Department B. If $10,000 in advertising is expected to increase the sales of either...
-
The results of the knockout rule may seem unsatisfactory because potentially, neither party is getting what he wants. What could an offeror do to prevent the knockout rule from knocking out any of...
-
Zan Azlett and Angela Zesiger have joined forces to start A&Z Lettuce Products, a processor of packaged shredded lettuce for institutional use. Zan has years of food processing experience, and Angela...
-
The amount of realized gain to be recognized in a tax year is equal to the gross profit multiplied by the ratio of payments received in the current year divided by the total contract price. ...
-
Jack Tasker opened his Auto Repair Shop in November 2023. The balance sheet at November 30, 2023, prepared by an inexperienced part-time bookkeeper, is shown below. Required Prepare a correct balance...
-
Average and standard deviation of linear combination. Let r1,.., be n-vectors, and a1...., ak be mumbers, and consider the linear combination z = a11 + ..+akak. (a) Show that avg(z) = a1 avg(21)+ +...
-
Describe the possible barriers to entry and exit for (a) a group of nurse practitioners who specialize in primary care wanting to establish their own independent office to care for patients with...
-
Repeat Exercise Graphics P25.10, using a DTD for validation. Data from Exercise P25.10 Write a program that can read an XML document of the form: 5 10 20 30 5 10 25 40 Hello, World! 20 30 and show...
-
Implement a stack as a linked list in which the push, pop, and isEmpty methods can be safely accessed from multiple threads.
-
At a local hospital, a decision was made to downsize the nursing staff. The local television station sent a reporter and camera crew to interview the administra- tor regarding the impact of this...
-
The static getAvailableCurrencies method of the java.util.Currency class yields a set of Currency objects. Turn it into a stream and transform it into a stream of the currency display names. Print...
-
The Centers for Disease Control (CDC) uses the BMI values toindicate one of four stages, underweight (15-18), normal (19-25),overweight (25-30), and obese (31 or greater). In later labs, youwill...
-
Calculate the Lagrange polynomial P 2 (x) for the values (1.00) = 1.0000, (1.02) = 0.9888, (1.04) = 0.9784 of the gamma function [(24) in App. A3.1] and from it approximations of (1.01) and (1.03).
-
Write a method that searches a numeric array for a specified value. The method should return the subscript of the element containing the value if it is found in the array. If the value is not found,...
-
This is a class member that holds data. a. Method b. Instance c. Field d. Constructor
-
What tag marks the beginning and end of an HTML document?
-
Describe the role of a paralegal in a family law practice.
-
Define family law and identify the kinds of issues that are addressed in a family law practice.
-
Identify the kinds of resources included in a basic family law library.
Study smarter with the SolutionInn App