Java 我的Tester类不完整,我正在尝试决定是否需要从其他类中提取方法

Java 我的Tester类不完整,我正在尝试决定是否需要从其他类中提取方法,java,testing,methods,arraylist,compile-time,Java,Testing,Methods,Arraylist,Compile Time,我在决定应该从VendingMachine类中提取哪些方法并将其放入TesterClass以测试我的程序时遇到问题。我试图通过在ArrayList中构造Candy对象来测试VendingMachine和Candy类,但我不确定如何最好地实现这一点。糖果对象的ArrayList包含糖果条字符串和双倍价格。我希望我的测试人员运行自动售货机方法,该方法提示用户输入println方法中列出的问题 测试级 public class Tester { private static O

我在决定应该从VendingMachine类中提取哪些方法并将其放入TesterClass以测试我的程序时遇到问题。我试图通过在ArrayList中构造Candy对象来测试VendingMachine和Candy类,但我不确定如何最好地实现这一点。糖果对象的ArrayList包含糖果条字符串和双倍价格。我希望我的测试人员运行自动售货机方法,该方法提示用户输入println方法中列出的问题

测试级

    public class Tester {
        private static Object candyBarList;

        public static void main(String args[])
    { 
             WHAT METHODS SHOULD I PLACE HERE
    }        
糖果班

    public class Candy{
    private double price;
    private String candyBarName;    

    Candy()
    {
    price = 1.50;
    candyBarName = "Pluto Bar";
    //default constructor
    }
    Candy(double price1, String str){
    price = price1;
    candyBarName = str;
    //constructor with parameters
    }
    public double getPrice(){
    return price;
    }
    public void setPrice(double price){
    this.price = price;
    }
    public String getCandyBarName(){
    return candyBarName;
    }
    public void setCandyBarName(String candyBarName){
    this.candyBarName = candyBarName;
    } 
自动售货机类

    }

    import java.util.ArrayList;
    import java.util.Scanner;
    import vendingmachine.Candy;
    package vendingmachine;

    /**
    *
    * @author admin
    */
    public class VendingMachine {

    double money = 0.0;
    Candy candyBar = new Candy();
    ArrayList<Candy> candyBarList = new ArrayList<>();
    double cashBox = 0.0;

    public VendingMachine(){

    candyBarList.add(candyBar);
    candyBarList.add(new Candy(2.00, "Snickers Bar"));
    candyBarList.add(new Candy(2.00, "Snickers Bar")); 
    candyBarList.add(new Candy(2.00, "Snickers Bar")); 
    candyBarList.add(new Candy(2.00, "Snickers Bar")); 
    candyBarList.add(new Candy(2.00, "Snickers Bar"));     
    }

    /**
    * @return 
    */ 

    public double paymentIn(){

    Scanner input = new Scanner(System.in);
    //double payAmount=0.0;

    System.out.println("Insert Money: ");
    double payAmount = input.nextDouble();

    return payAmount;
    }

    public static boolean isPaymentEnough(double depositMoney, double price){

    if (depositMoney >= price)
    {
        return true;
    }
    else{
        return false;
    }

    }

    public  void dispenseCandy (double depositMoney, Candy selectedCandy){
        cashBox+= depositMoney - selectedCandy.getPrice();
        candyBarList.remove(selectedCandy);                     

    }

    public String candySelector(){    
        for (int i=0; candyBarList.size() >= i; i++){

        System.out.println(candyBarList.get(i));

    }

    Scanner input = new Scanner(System.in);
    String candyBarSelected = input.next();

    System.out.println("Please type in the Candy Bar you would like");
    candyBarSelected = input.next();

    return candyBarSelected;

    }

    public Candy findCandy(){
    String candyName = candySelector();

    for (int i=0; candyBarList.size() >= i; i++){

        if (candyBarList.get(i).getCandyBarName().equals(candyName)){
        return candyBarList.get(i);
        }           

    }
    System.out.println("Your selection is invalid");
    return null;
    }

您的Tester类获得VendingMachine的一个实例,该实例允许它访问该类的所有公共方法。为什么你觉得有必要复制任何东西?我不确定我是否需要复制它本身。我想知道是否可以从自动售货机类中提取这些方法,并将它们放在测试仪中。