java tagmaker程序(清除扫描器和测试器类)。

问题描述 投票:0回答:1

说明:写一个名为TagMaker的类来打印标签。提供方法来(a)设置名称(b)设置组织(c)打印带有名称和组织的标签(d)清除名称和组织(e)打印一个空白标签。然后写一个TagTester类来测试TagMaker类。

所以我得到了接受用户输入并打印出标签的代码......但我没有使用测试器类(我很害怕这些,而且当我尝试使用一个时,它没有工作。

这是我目前所拥有的。

import java.util.Scanner;
//import java.util.Locale;
//import java.io.*;

public class TagMaker {

 public static void main (String[] args)
{
 Scanner scannerObject = new Scanner( System.in );


 System.out.print("This program will print out a name tag");
 System.out.println("for each delegate.");
 System.out.println("Please enter first name:");
 String first = scannerObject.next();
 System.out.println("Please enter last name:");
 String last = scannerObject.next();
 System.out.println("Please enter organization or affilation:");
 String org = scannerObject.next();


System.out.println("###### " + "Annual Conference" + " ######");
    System.out.println("### NAME: " + first + " " + last + " ###");
    System.out.println("################################");
    System.out.println("### ORGANIZATION:" + org + "###");
    System.out.println("###############################");


    String junk = scannerObject.next();
}
} 
java java.util.scanner
1个回答
0
投票
public class TagMaker {
private String tagName;
private String organization;

public void setTagName(String tagName){
    this.tagName = tagName;
}

public void setOrganization(String organization){
    this.organization = organization;
}

public void clearTagName(){
    this.tagName = "";
}

public void clearOrganization(){
    this.organization = "";
}

@Override
public String toString() {
    return "Tag [Name=" + tagName + "\n Organization="
            + organization + "]";
}


}

class TagTester{

    public static void main(String args[]){
    TagMaker customTag = new TagMaker();                //Creates a new tag
    customTag.setTagName("Custom Name");                //Sets tag name to Custom Name
    customTag.setOrganization("Custom Organization");   //Sets tag organization to Custom organization
    customTag.clearTagName();                           //Clears tag name
    customTag.clearOrganization();                      //Clears organization
    System.out.println(customTag);                      //Prints tag name and organization
}
}
© www.soinside.com 2019 - 2024. All rights reserved.