Text formatter interface

Report a typo

Mary is playing around with Go interfaces. She wants to create a very simple Formatter interface for the Text type that implements three methods:

  • The TabFormat() method — it should return a tab character "\t" + the string(t)

  • The DoubleQuoteFormat() method — it should return string(t) wrapped within double quotes "

  • The SingleQuoteFormat() method — it should return string(t) wrapped within single quotes '

Your task is to help Mary write the additional required code to create the three above methods and the Formatter interface that implements these methods.

This problem uses the bufio package to scan whitespace-separated strings from the standard input and save them into the someText variable. However, don't be scared! you don't need to know how the bufio package works to solve this task.

Sample Input 1:

The quick brown fox jumps over the lazy dog

Sample Output 1:

'The quick brown fox jumps over the lazy dog'
"The quick brown fox jumps over the lazy dog"
	The quick brown fox jumps over the lazy dog
Write a program in Go
package main

import (
"bufio"
"fmt"
"os"
)

type Text string

// Create the `TabFormat()` method below:
func (t Text) TabFormat() string {
return "\t" + string(t)
}

// Create the `DoubleQuoteFormat()` method below:
func (t Text) DoubleQuoteFormat() string {
return ? + string(t) + ?
}

// Create the `SingleQuoteFormat()` method below:
func (t Text) SingleQuoteFormat() string {
return ? + ? + ?
}

// Create the `Formatter` interface that implements the
// `TabFormat()`, `DoubleQuoteFormat()` and `SingleQuoteFormat()` methods below:
type ? interface {
?
?
?
}

// DO NOT delete or modify the contents of the main() function!
func main() {
scanner := bufio.NewScanner(os.Stdin)
___

Create a free account to access the full topic