Question

Tokenizer: I dont understand how to make a single String parameter, as well as where the...

Tokenizer:

I dont understand how to make a single String parameter, as well as where the toString is coming from in the Overrid Method.

Program question:

  • A class called: Token
  • Token should have a private String variable that holds the value associated with a particular token
    • For example, if the string “The cat in the hat” gets tokenized then the value of one Token object might be: “The” , or might be “cat” etc..
  • Create getters and setters for the private String variable called:
    • getValue, and setValue
  • Token should have a constructor that has one String parameter, this parameter should be used to set the value of private string variable
  • Override the toString method inherited from the Object class, and have it return the value of the private String variable.

My Code:

package com.company;

public class Token {

    private String getValue;
    private String setValue;

    public Token(String setVal, getVal){
        setValue = setVal;
        getValue = getVal;

    }

    @Override
0 0
Add a comment Improve this question Transcribed image text
Answer #1

/**
* @author teegu
*
*/
public class Token {
   private String value;

   /**
   * @param aValue
   */
   public Token(String aValue) {
       super();
       value = aValue;
   }

   /**
   * @return
   */
   public String getValue() {
       return value;
   }

   /**
   * @param aValue
   */
   public void setValue(String aValue) {
       value = aValue;
   }

   @Override
   public String toString() {
       return value;
   }
  
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
Tokenizer: I dont understand how to make a single String parameter, as well as where the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The Tokenizer.java file should contain: A class called: Tokenizer Tokenizer should have a private variable that...

    The Tokenizer.java file should contain: A class called: Tokenizer Tokenizer should have a private variable that is an ArrayList of Token objects. Tokenizer should have a private variable that is an int, and keeps track of the number of keywords encountered when parsing through a files content. In this case there will only be one keyword: public. Tokenizer should have a default constructor that initializes the ArrayList of Token objects Tokenizer should have a public method called: tokenizeFile tokenizeFile should...

  • Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram)

    Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram) Author -name:String -email:String -gender:char +Author(name:String, email:String, gender:char) +getName():String +getEmail):String +setEmail (email:String):void +getGender():char +tostring ):String . Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f'): One constructor to initialize the name, email and gender with the given values . Getters and setters: get Name (), getEmail() and getGender (). There are no setters for name and...

  • The current code I have is the following: package uml; public class uml {        public...

    The current code I have is the following: package uml; public class uml {        public static void main(String[] args) {              // TODO Auto-generated method stub        } } class Account { private String accountID; public Account(String accountID) { this.accountID = accountID; } public String getAccountID() { return accountID; } public void setAccountID(String accountID) { this.accountID = accountID; } @Override public String toString() { return "Account [accountID=" + accountID + "]"; } } class SuppliesAccount extends Account { private...

  • Comment your code. At the top of the program include your name, a brief description of...

    Comment your code. At the top of the program include your name, a brief description of the program and what it does and the due date. The program must be written in Java and submitted via D2L. The code matches the class diagram given above. The code uses Inheritance. In the following, you are given code for two classes: Coin and TestCoin. You study these classes first and try to understand the meaning of every line. You can cut and...

  • pls help java ASAP!!!!!!! Topic String Tokenizer Static Methods Static Variables Primitive Arrays Description Enhance the...

    pls help java ASAP!!!!!!! Topic String Tokenizer Static Methods Static Variables Primitive Arrays Description Enhance the last assignment by providing the following additional features: (The additional features are listed in bold below) Class Statistics In the class Statistics, create the following static methods (in addition to the instance methods already provided). • A public static method for computing sorted data. • A public static method for computing min value. • A public static method for computing max value. • A...

  • Update your Assignment 4 as follows (Assignment 4 codes will be on the bottom) Create a...

    Update your Assignment 4 as follows (Assignment 4 codes will be on the bottom) Create a new method called displayAll, that takes an ArrayList (of your base class) as a parameter, and doesn't return anything [25 pts] The displayAll method will loop through the ArrayList, and call the display (or toString) method on each object   [25 pts] In the main method, create an ArrayList containing objects of both your base class and subclass. (You should have at least 4 objects)  [25...

  • Book: - title: String - price: double +Book() +Book(String, double) +getTitle(): String +setTitle(String): void +getPrice(): double...

    Book: - title: String - price: double +Book() +Book(String, double) +getTitle(): String +setTitle(String): void +getPrice(): double +setPrice(double): void +toString(): String The class has two attributes, title and price, and get/set methods for the two attributes. The first constructor doesn’t have a parameter. It assigns “” to title and 0.0 to price; The second constructor uses passed-in parameters to initialize the two attributes. The toString() method returns values for the two attributes. Notation: - means private, and + means public. 1....

  • Consider the class public elass Box·xtenda 0bJeetE private String stuff』 Write two constructors for the class....

    Consider the class public elass Box·xtenda 0bJeetE private String stuff』 Write two constructors for the class. The first constructor will take zero input arguments and set the stuff attibute to null. The second will take a String as input and set the shul atbute to input string Getter and Setter Write a public getter method called getsauff that returns the string stored by the sthuff attribute If stulf is null, it should return the string "no stuff in here Write...

  • Deliverable A zipped NetBeans project with 2 classes app ZipCode Address Classes Suggestion: Use Netbeans to...

    Deliverable A zipped NetBeans project with 2 classes app ZipCode Address Classes Suggestion: Use Netbeans to copy your last lab (Lab 03) to a new project called Lab04. Close Lab03. Work on the new Lab04 project then. The Address Class Attributes int number String name String type ZipCode zip String state Constructors one constructor with no input parameters since it doesn't receive any input values, you need to use the default values below: number - 0 name - "N/A" type...

  • public class CylindricalTank {    private String idTag;           // Unique String identifying the tank...

    public class CylindricalTank {    private String idTag;           // Unique String identifying the tank    private double radius;           // The non-negative radius of the base of the tank in meters    private double height;           // The non-negative height of the tank in meters    private double liquidLevel;       // The current height of the liquid in the tank in meters    /**    * CylindricalTank General Constructor    */    public CylindricalTank(String tag, double...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT