摘要:1. What is immutable object? Can you write immutable object?for example : String.For an object to be immutable, there has to be no way to change fields, mutable or not, and to access fields that are mutable.Here is an example of a mutable object.import java.util.ArrayList;import java.util.LinkedList
阅读全文
摘要:Design Clothing store using OOP concepts. based on your design tell how you'll find if the store has XXL size of a particular shirt.package OOP.clothstore;import java.util.ArrayList;import java.util.Hashtable;class cloth{String brand;String barCode;Type type;Size size;enum Size{xs,s,m,l,xl,xxl};
阅读全文
摘要:import java.util.ArrayList;import java.util.Hashtable;class station{String stationID;}class Train{String trainID;int numOfCars;int maxCapacity;int NumOfPassenger;float price;Hashtable schedule;//time, station}public class trainReservation {//id, trainHashtable trains = new Hashtable ();float reserv.
阅读全文
摘要:abstract class material{ int weight;}class wood extends material{}class plastic extends material{}class metal extends material{}interface furniture { material getMaterial(); void setMaterial(material m);}class table implements furniture{ material mat; public material getMaterial(){ ...
阅读全文
摘要:public class person { BloodType bloodtype; enum BloodType{A,B,O}; String FirstName, LastName; String BirthDay; Body body;}abstract class part{ float weight; void setWeight(float w){ weight = w;} float getWeight(){ return weight;}}class Body{ Arm[] arms; Head head; L...
阅读全文
摘要:给个猜词小游戏的app,显示一个合法string的anagram,要求用户一分钟内给答案,返回对错,time out之后返回所有的正确答案。dictionary作为list,已知。 (预处理dictionary,用hashtable存,key是string排序后的结果,每个slot用bst存,时间为logk)eg:给atme,正确答案包括team, mate, meat, tame
阅读全文
摘要:String * ptr_str = static_cast(3*malloc(sizeof(String)));only Allocates the memory ;String * ptr_str2 = new String[3];calls the constructure of string class;delete[]ptr;if delete ptr only delte string[0]
阅读全文
摘要:Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest...
阅读全文
摘要:Given a binary tree, find the lowest common ancestor of two given nodes in the tree. _______3______ / \ ___5__ _...
阅读全文
摘要:class Link { public int data1; public double data2; public Link nextLink; //Link constructor public Link(int d1, double d2) { data1 = d1; data2 = d2; } //Print Link data public void printLink() { System.out.print("{" + data1 + ", " + data2 + "} "); }}c...
阅读全文
摘要:This article provides a brief description about the various Object Oriented Programming concepts.Object Oriented ProgrammingIt is a type of programming in which programmers define not only the data type of a data structure, but also the types of operations (functions) that can be applied to the data
阅读全文
摘要:staticvariables are shared by the entire class, not a specific instance (unlike normal member variables)staticmethods are also shared by the entire classstaticclasses are inner classes that aren’t tied to their enclosing classesstaticcan be used around a block of code in a class to specify code that
阅读全文
摘要:函数指针是指向函数的指针,指针函数还是指一个函数的返回值是一个指针(1) float(**def)[10] def是什么?(2) double*(*gh)[10] gh是什么?(3) double(*f[10])() f是什么?(4) int*((*b)[10]) b是什么?(1) def是一个指针, 指向的对象也是一个指针, 指向的指针最终指向的是10个float构成的数组.(2) gh是指针, 指向的是10个元素构成的数组, 数组的元素是double*类型的指针.(3) f是10个元素构成的数组, 每个元素是指针, 指针指向的是函数, 函数类型为无参数且返回值为double. 下面要讲的窍
阅读全文
摘要:https://www.youtube.com/watch?v=_8-ht2AKyH4
阅读全文
摘要:// Please do the following.// 1. void push(Object o);-- add element to the top// 2. Object pop(); -- remove element from the top// 3. boolean isEmpty(); -- true/false if stack is empty// Queue q;// void enqueue(Object o); -- add to the end of the queue// Object dequeue(); -- remove from the...
阅读全文
摘要:import java.util.ArrayList;import java.util.Scanner;public class game { private ArrayList ship = new ArrayList(); int numGuess = 0; public static void main(String[] args){ Game game = new Game(); game.setup(); } private void setup(){ ship.add(new S...
阅读全文
摘要:Similarities and DifferencesThis list of similarities and differences is based heavily onThe Java Language Environment, A White Paperby James Gosling and Henry McGilton http://java.sun.com/doc/language_environment/ and the soon-to-be published book,Thinking in Javaby Bruce Eckel, http://www.EckelObj
阅读全文
摘要:public class Queue { private Stack s1 = new Stack(); private Stack s2 = new Stack(); public void enqueue(Element e){ s1.push(e); return; } public Element dequeue() { if(s2.isEmpty()) { while(!s1.isEmpty()) { Element e = s1.pop();...
阅读全文