Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a class called Chunker that satisfies the following specification: Class Chunker A Chunker object is used to store string data and retrieve it

Write a class called Chunker that satisfies the following specification: Class Chunker A Chunker object is15:08 Tests & Quizzes public void add(String string) // Append the given string to the end of the existingWrite a class called Calendar that satisfies the following specification: Class Calendar A Calendar object ispublic void advance() // Advance the current date by one day Consider the following code snippet: // ...

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 ", chunker.nextChunk (), chunker.next Chunk () ); System.out.printf("%b, %b ", 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 / / 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

Step by Step Solution

3.46 Rating (153 Votes )

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Starting Out With Java From Control Structures Through Data Structures

Authors: Tony Gaddis

6th Edition

0133957055, 978-0133957051

More Books

Students also viewed these Programming questions

Question

What tag marks the beginning and end of an HTML document?

Answered: 1 week ago

Question

Briefly describe each of the seven basic quality' tools.

Answered: 1 week ago