class

Rank of Cards in a Game

旧城冷巷雨未停 提交于 2019-12-30 22:59:44
问题 I'm a beginner Java student. So any help will be much appreciated! I've designed a class Cards and class Deck that I will use in a game that I've created. So far, my game seems to be working very well, but the problem I have lies in my Cards class. I'd like to utilize my getRank() method as a way to accumulate points for the cards a player has (regardless of suit). For example, if they draw a 2 of Diamonds, it will be worth 2 points, 3 of hearts 3 points...ect. I've created a String[] called

What is “member initializer” in C++11?

好久不见. 提交于 2019-12-30 17:06:30
问题 I run across a weird concept named "member initializer". Here says: C++11 added member initializers, expressions to be applied to members at class scope if a constructor did not initialize the member itself. What is its definition? Are there some examples to illustrate its usage? 回答1: It probably refers to in-class member initializers. This allows you to initialize non-static data members at the point of declaration: struct Foo { explicit Foo(int i) : i(i) {} // x is initialized to 3.1416 int

Is there a way to make a class recursive?

两盒软妹~` 提交于 2019-12-30 14:54:30
问题 So I would like to create a class that can have an object which type is itself. Something like this: class foo { foo Avalue = foo(); foo Bvalue = foo(); foo(int a, int b) { Avalue = goo(a); Bvalue = goo(b); } foo(foo a, int b) { Avalue = foo(a); Bvalue = goo(b); } foo(foo a, foo b) { Avalue = foo(a); Bvalue = foo(b); } } class goo : foo { int value; } so that I can have a recursive object that always terminates at "goo" objects. Is there a way to make it? 回答1: No. That is fundamentally

Convert deserialized json class to datatable

♀尐吖头ヾ 提交于 2019-12-30 14:42:17
问题 I am trying to convert json that I deserialized to a class to a datatable by using the code below ,however the code below fails at the last line. using (var webClient = new System.Net.WebClient()) { var downloadTable = webClient.DownloadString(url); var myTable = JsonConvert.DeserializeObject<leagueTable>(downloadTable); DataTable dt = myTable; } I know that I could deserialized directly to a datatable but I want to deserialized it to a class first so that I can manipulate the data and let

Log4J loggers for different classes

故事扮演 提交于 2019-12-30 12:39:24
问题 I want to use Log4J for logging my java projects. I created a log4j.properties file in the src directory with the following content: # Root logger option log4j.rootLogger=INFO, file, stdout log4j.logger.DEFAULT_LOGGER=INFO,file2 # Direct log messages to a log file log4j.appender.file=org.apache.log4j.FileAppender log4j.appender.file.File=file.log log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d [%t] %-5p %c - %m%n # Direct log messages

Why outer classes are not static in java? [duplicate]

随声附和 提交于 2019-12-30 11:34:12
问题 This question already has answers here : Why are you not able to declare a class as static in Java? (14 answers) Closed 6 years ago . In java, An outer class may be public, final, default or abstract. Why not Static like public static class MyClass{} 回答1: An outer class is already implicitly static. Non-static nested class (= inner class) means thats the inner class implicitly has a reference to its parent class. That's why, for nested class, you can distinguish between static and non-static.

How to create a C# class whose attributes are rows in a database table with ADO.NET?

家住魔仙堡 提交于 2019-12-30 11:20:17
问题 Is it possible? Please note I am not using LINQ nor Entity Framework. 回答1: You could also check out Dapper-Dot-Net - a very lightweight and very capable "micro ORM" which - incidentally - is used to run this site here. It's quite fast, a single *.cs file, works with your usual T-SQL commands and returns objects - works like a charm, it's very fast, very easy to understand, no big overhead - just use it and enjoy! 回答2: My personal favorite is done using the dynamic object featured in .NET4 via

What is this macro for at the beginning of a class definition?

非 Y 不嫁゛ 提交于 2019-12-30 10:37:10
问题 I'm looking through the source of a library and many classes are defined using the following form class THING_API ClassName { ... Jumping to the macro definition . . . #ifndef THING_API #define THING_API /**< This macro is added to all public class declarations. */ #endif What could this be for, and is it a common technique? 回答1: It looks to me very much like export macro, which is required when building a shared library (.dll) on Windows. When compiling with MSVC, You have to put __declspec

Java Scanner class reading strings [duplicate]

佐手、 提交于 2019-12-30 10:23:26
问题 This question already has answers here : Java Scanner class reading strings (5 answers) Closed 5 years ago . I got the following code: int nnames; String names[]; System.out.print("How many names are you going to save: "); Scanner in = new Scanner(System.in); nnames = in.nextInt(); names = new String[nnames]; for (int i = 0; i < names.length; i++){ System.out.print("Type a name: "); names[i] = in.next(); } System.out.println(names[0]); When I run this code, the scanner will only pick up the

Java Scanner class reading strings [duplicate]

微笑、不失礼 提交于 2019-12-30 10:22:59
问题 This question already has answers here : Java Scanner class reading strings (5 answers) Closed 5 years ago . I got the following code: int nnames; String names[]; System.out.print("How many names are you going to save: "); Scanner in = new Scanner(System.in); nnames = in.nextInt(); names = new String[nnames]; for (int i = 0; i < names.length; i++){ System.out.print("Type a name: "); names[i] = in.next(); } System.out.println(names[0]); When I run this code, the scanner will only pick up the