0
我想知道,如果你可以將圖像添加到一個決定,所以當用戶到達最後一個問題這樣,它顯示匹配什麼用戶已經輸入如何添加或決策執行圖像樹
<import java.util.Scanner;
/**
* Decision Tree implemented for people choosing a car brand based on specific qualifications
* or characteristics.
* @author Bart
*
*/
public class CarBrandExpert {
private LinkedBinaryTree<String> tree;
//-----------------------------------------------------------------
// Sets up the diagnosis question tree.
//-----------------------------------------------------------------
public CarBrandExpert()
{
String e1 = "Do you like american cars?";
String e2 = "Do you like fast cars? ";
String e3 = "Do you like sports cars?";
String e4 = "Do you like car durability? ";
String e5 = "Do you like sleek designs?";
String e6 = "Do you like off road driving?";
String e7 = "You like heavy duty?";
String e8 = "Do you like easy car handles while driving?";
String e9 = "Does size matter??";
String e10 = "Do nice interiors catch your eye?";
String e11 = "Love to drive in style?";
String e12 = "Does gas milage matter? ";
String e13 = "Do you have an expensive taste?";
String e14 = "Toyota is your brand! ";
String e15 = " Nissan is your Brand! ";
String e16 = "An Audi is what you need!";
String e17 = "BMW suits you best!";
String e18 = "Fords are for your basic needs based upon your data";
String e19 = "Chevy is the BOMB! Definitely worth a try!";
String e20 = "Try Chrysler";
String e21 = "Dodges should quinch your thrist and relieve your worries";
//Creates the nodes in order to match the outcomes with the right questions as well predict the different outcome of users answer
LinkedBinaryTree<String> n2, n3, n4, n5, n6, n7, n8, n9,
n10, n11, n12, n13, n14, n15, n16, n17, n18, n19, n20, n21;
n14 = new LinkedBinaryTree<String>(e14);
n15 = new LinkedBinaryTree<String>(e15);
n12 = new LinkedBinaryTree<String>(e12, n14, n15);
n16 = new LinkedBinaryTree<String>(e16);
n17 = new LinkedBinaryTree<String>(e17);
n13 = new LinkedBinaryTree<String>(e13, n16, n17);
n18 = new LinkedBinaryTree<String>(e18);
n19 = new LinkedBinaryTree<String>(e19);
n11 = new LinkedBinaryTree<String>(e11, n18, n19);
n20 = new LinkedBinaryTree<String>(e20);
n21 = new LinkedBinaryTree<String>(e21);
n7 = new LinkedBinaryTree<String>(e7, n20, n21);
n2 = new LinkedBinaryTree<String>(e2, n12, n13);
n3 = new LinkedBinaryTree<String>(e3, n11, n7);
tree = new LinkedBinaryTree<String>(e1, n2, n3);
}
/*
* Prints out the decision based on the answer of yes or no
* Also helps to check which side of the tree the program should go on in order to find predicted answer
*/
public void Matchup()
{
Scanner scan = new Scanner(System.in);
BinaryTree<String> current = tree;
System.out.println ("So,you're looking to find the right car brand?");
while (current.size() > 1)
{
System.out.println (current.getRootElement());
if (scan.nextLine().equalsIgnoreCase("N"))
current = current.getLeft();
else
current = current.getRight();
}
System.out.println (current.getRootElement());
}
}>
<public class CarBrandMatchUp {
public static void main(String[] args) {
CarBrandExpert car = new CarBrandExpert();
car.Matchup();
}
}>
圖像
我一直在想每一個結果,用戶將與特定的汽車品牌匹配,它會顯示一個隨機的汽車品牌的任何想法,我怎麼能做到這一點?
好吧,我試過這種方式,它沒有工作,但我發現了另一種方式來顯示圖像,但如何實現方法或類進入決策樹\ –