Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(a) Write a Java program that consists of a definition for a public class called Token. There should be two instance variables. One should be

(a) Write a Java program that consists of a definition for a public class called Token. There should be two instance variables. One should be of type char, and be named root. The other should be a one-dimensional array of Token, and be named multi. The class should have one constructor with a formal parameter of type char named root. This constructor should use the this keyword to assign its actual parameter to the instance variable of the same name. The other constructor should take a String. This should create and assign to multi an array of Token, each element of which is constructed on a distinct char from the specified String. (Remember that s.charAt(i) will return the ith char from String s.) [20 marks]

(b) Add a method to the class named getRandom(), which returns a Token. This should behave as follows. If the object on which the method is called has a null value for its multi variable, it should return a Token constructed on the char z. If the multi variable is not null, the method should return one of the Token objects from the multi array selected at random. (Remember that Math.random() produces a random double value in the range 0.0..1.0.) [15 marks]

(c) Write an additional method for the class defined above, named nMultis. This should take a char and return an int. The behavior of the method should be as follows. If the objects multi array is null, the method should return 0. Otherwise, it should go through the array to discover how many of the Token objects have a value of the root variable identical to the methods argument. This int value should then be returned. [15 marks]

Step by Step Solution

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_2

Step: 3

blur-text-image_3

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

3319712721, 978-3319712727

More Books

Students also viewed these Databases questions

Question

Write a program to check an input year is leap or not.

Answered: 1 week ago

Question

Write short notes on departmentation.

Answered: 1 week ago

Question

What are the factors affecting organisation structure?

Answered: 1 week ago

Question

What are the features of Management?

Answered: 1 week ago

Question

Briefly explain the advantages of 'Management by Objectives'

Answered: 1 week ago