OneCompiler

Iterator_Decision_404

117

a) menu.java

package samruddhi.dagade;

import java.util.Iterator;

public interface menu {

public Iterator createIterator();

}

b) menuitem.java

package samruddhi.dagade;

public class menuitem {

String name;

String description;

boolean vegetarian;

double price;

public menuitem(String name, String description, boolean vegetarian, double price) {

super();

this.name = name;

this.description = description;

this.vegetarian = vegetarian;

this.price = price;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getDescription() {

return description;

}

public void setDescription(String description) {

this.description = description;

}

public boolean isVegetarian() {

return vegetarian;

}

public void setVegetarian(boolean vegetarian) {

this.vegetarian = vegetarian;

}

public double getPrice() {

return price;

}

public void setPrice(double price) {

this.price = price;

}

}

c) waitress.java

package samruddhi.dagade;

import java.util.ArrayList;

import java.util.Iterator;

public class waitress {

ArrayList menus;

public waitress(ArrayList menus) {

super();

this.menus = menus;

}

public void printMenu() {

Iterator menuIterator = menus.iterator();

while(menuIterator.hasNext()) {

menu menu = (menu)menuIterator.next();

printMenu(menu.createIterator());

}

}

void printMenu(Iterator iterator) {

while (iterator.hasNext()) {

menuitem menuItem = (menuitem)iterator.next();

System.out.print(menuItem.getName() + ", ");

System.out.print(menuItem.getPrice() + " -- ");

System.out.print(menuItem.isVegetarian()+ " ");

System.out.println(menuItem.getDescription());

}

}

}

d) DemoMain.java

package samruddhi.dagade;

import java.util.ArrayList;

import java.util.Iterator;

public class DemoMain

{

public static void main(String args[])

{

menuitem m1 = new menuitem("Panner","veg",true,123);

menuitem m2 = new menuitem("Chicken","nonveg",false,563);

menuitem m3 = new menuitem("Veg biryani","veg",true,321);

ArrayList<menuitem> list = new ArrayList<menuitem>();

list.add(m1);

list.add(m2);

list.add(m3);

waitress w = new waitress(list);

Iterator itr = list.iterator();

w.printMenu(itr);

}

}

#8 Write a python program to Implement Decision Tree whether or not to play tennis.
import numpy as np
import pandas as pd
from sklearn import metrics
df=pd.read_csv('weather.csv')
df
from sklearn import preprocessing
string_to_int= preprocessing.LabelEncoder() #transform categorical data into numerical form
df=df.apply(string_to_int.fit_transform)
df
X = df[['outlook','temperature','humidity','windy'] ]
y= df['play']
from sklearn import tree
clf = tree.DecisionTreeClassifier(criterion = 'entropy')
clf = clf.fit(X, y)
tree.plot_tree(clf)

var express = require("express");
const bodyParser = require("body-parser");
var fs = require("fs");
var buf = new Buffer(1024);
var app = express();
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.get("/", function(request, response){
response.writeHead(200,{'content-type':'text/html'});
response.write('<form name="file_input" method="post">');
response.write('<h1> Select file to view contents of it </h1>');
response.write('<input type="file" name="fname"><br>');
response.write('<input type="submit"><br>');
response.write('</form>');
response.end();
});

app.post('/', function(req, res){

const fn = req.body.fname;	
fs.open(fn, 'r+', function(err, fd) { 
if (err)
	return res.status(400).send({message: "File not found error"});
fs.read(fd, buf, 0, buf.length, 0, function(err, bytes){ 
if (err)
	console.log(err); 
var data =buf.toString();  
res.writeHead(200,{'content-type':'text/html'});	
res.write(data);
});
});

});
app.listen(8080);
console.log("Server is running at http://localhost:8080");