you could also divide by 10 in a loop until the number is less than 10 and count how many times the number was divided + 1
So I just started attempting to learn java and one of the programs this book I'm learning from is trying to get me to do is:
[QUOTE]Consider a class called Money. A Money object represents a monetary quantity measured in dollars and cents. The public interface to the Money class allows client programmers to
Create Money objects initialized to $0.00 with a default constructor
Create Money objects, specifying the total value in cents (e.g. 523  $5.23)
Create Money objects, specifying the value in dollars and cents (two numbers)
Retrieve and modify both the dollar and cents portion of a Money object
Retrieve a String object representing the value of a Money object (e.g. "$5.23")
Suppose we implement the public interface by storing two integers in each Money object. The following class diagram then summarizes the features of the Money class. (We have called the class "Money1" because we will create a second implementation called Money2 later on.)
Money1
- CENTS_PER_DOLLAR : int
- dollars : int
- cents : int
+ Money( )
+ Money(int)
+ Money(int, int)
+ getDollars( ) : int
+ setDollars(int) : void
+ getCents( ) : int
+ setCents(int) : void
+ toString( ) : String
Note: the data member CENTS_PER_DOLLAR is a class constant whose value is obviously 100. The int literal 100 must appear only once in your class definition.[/QUOTE]
and the code so far I have is (just a general skeleton);
[code]public class Money{
private int CENTS_PER_DOLLAR, dollars, cents;
public static void main(String[] args) {
}
public Money()
{
this.dollars = 0;
this.cents = 0;
}
public Money(int cents)
{
this.dollars = cents/100;
this.cents = cents%100;
}
public Money (int int)
{
//code
}
public int getDollars()
{
return dollars;
}
public void setDollars(int dollars)
{
//code
}
public int getCents()
{
return cents;
}
public void setCents(int cents)
{
//code
}
public String toString()
{
//code
}
}[/code]
I know I may seem super dumb, but I am still trying to grasp how everything works. For instance I'm still lost on how I'm supposed to create a "Money object"? Not sure what names to use if it matters.
[code]
int moneyObj = new account;
[/code]?
Also in the design document when it says "+Money(int, int)" how do I write that in the main method? Because it doesn't seem to like me going
[code]
public Money(int, int)
[/code]
Really any help is useful, I am just trying to learn this as I have been stuck with no idea how to do it no matter how many times I read the book.
Thanks.
Does anyone know of a good free facial recognition API?
Specifically one with good eye tracking features. I would like to be able to see when the person blinks or has their eyes closed.
I have found lists of APIs, but there's a lot to go through for testing each of them, and was hoping someone might have prior experience or recommendations for a good one.
[QUOTE=Ohfoohy;46432963]I know I may seem super dumb, but I am still trying to grasp how everything works. For instance I'm still lost on how I'm supposed to create a "Money object"? Not sure what names to use if it matters.
[code]
int moneyObj = new account;
[/code]?
[/quote]
To create a new object, you'll want to call its constructor; you do this with the [i]new[/i] keyword like you're already doing, but you pass the constructor you want to call. For example:
[code]
Money money = new Money();
[/code]
[QUOTE=Ohfoohy;46432963]
Also in the design document when it says "+Money(int, int)" how do I write that in the main method? Because it doesn't seem to like me going
[code]
public Money(int, int)
[/code]
[/QUOTE]
You're not providing the names for the arguments, only the types - which doesn't make much sense. You're probably wanting to do something along these lines.
[code]
public void Money(int dollars, int cents)
{
//constructor code
}
[/code]
For the rest, I suggest you read up on the [url=http://docs.oracle.com/javase/tutorial/java/nutsandbolts/index.html]Java language basics[/url] guide.
[QUOTE=Contron;46434081]To create a new object, you'll want to call its constructor; you do this with the [i]new[/i] keyword like you're already doing, but you pass the constructor you want to call. For example:
[code]
Money money = new Money();
[/code]
You're not providing the names for the arguments, only the types - which doesn't make much sense. You're probably wanting to do something along these lines.
[code]
public void Money(int dollars, int cents)
{
//constructor code
}
[/code]
For the rest, I suggest you read up on the [url=http://docs.oracle.com/javase/tutorial/java/nutsandbolts/index.html]Java language basics[/url] guide.[/QUOTE]
Does this seem decent?
[code]
public class Money{
private int dollars, cents;
private static int CENTS_PER_DOLLAR = 100;
public Money()
{
this.dollars = 0;
this.cents = 0;
}
public Money(int cents)
{
this.dollars = cents/100;
this.cents = cents%100;
}
public Money(int dollars, int cents)
{
this.dollars = dollars;
this.cents = cents;
}
public int getDollars()
{
return dollars;
}
public void setDollars(int dollars)
{
this.dollars = dollars;
}
public int getCents()
{
return cents;
}
public void setCents(int cents)
{
this.cents = cents;
}
public String toString(){
return "$" + dollars + "." + cents;
}
}
[/code]
[code]
public class MoneyTest {
public static void main(String [] args) {
Money moneyobj1 = new Money();
System.out.println(moneyobj1.toString()); // Should be $0.00
Money moneyobj2 = new Money(324);
System.out.println(moneyobj2.toString()); // Should be $3.24
Money moneyobj3 = new Money(3,47);
System.out.println(moneyobj3.toString()); // Should be $3.47
}
}
[/code]
[QUOTE=Dr. Evilcop;46411751][url]http://www.amazon.com/gp/aw/d/1435458869/ref=pd_aw_sims_2?pi=SL500_SY115&simLd=1[/url]
[url]http://www.amazon.com/gp/aw/d/1568817231/ref=pd_aw_sims_9?pi=SL500_SY115&simLd=1[/url]
[url]http://www.amazon.com/gp/aw/review/1584503300/RNSA11AKLL1Q5/ref=mw_dp_cr?cursor=2&sort=rd[/url]
etc[/QUOTE]
That's all geared towards 3d math/game programming specifically, don't discount Discrete Math, Theory of Computation, Algorithms, Automata theory, Artificial Intelligence, Graph Theory, etc.
[QUOTE=Ohfoohy;46434593]Does this seem decent?
[code]
public class Money{
private int dollars, cents;
private static int CENTS_PER_DOLLAR = 100;
public Money()
{
this.dollars = 0;
this.cents = 0;
}
public Money(int cents)
{
this.dollars = cents/100;
this.cents = cents%100;
}
public Money(int dollars, int cents)
{
this.dollars = dollars;
this.cents = cents;
}
public int getDollars()
{
return dollars;
}
public void setDollars(int dollars)
{
this.dollars = dollars;
}
public int getCents()
{
return cents;
}
public void setCents(int cents)
{
this.cents = cents;
}
public String toString(){
return "$" + dollars + "." + cents;
}
}
[/code]
[code]
public class MoneyTest {
public static void main(String [] args) {
Money moneyobj1 = new Money();
System.out.println(moneyobj1.toString()); // Should be $0.00
Money moneyobj2 = new Money(324);
System.out.println(moneyobj2.toString()); // Should be $3.24
Money moneyobj3 = new Money(3,47);
System.out.println(moneyobj3.toString()); // Should be $3.47
}
}
[/code][/QUOTE]
As long as you understand what it does, and it gives you the intended output, then I'd say it's fine!
[QUOTE=Ohfoohy;46434593]Does this seem decent?
[code]
public class Money{
private int dollars, cents;
private static int CENTS_PER_DOLLAR = 100;
public Money()
{
this.dollars = 0;
this.cents = 0;
}
public Money(int cents)
{
this.dollars = cents / CENTS_PER_DOLLAR;
this.cents = cents % CENTS_PER_DOLLAR ;
}
public Money(int dollars, int cents)
{
this.dollars = dollars;
this.cents = cents;
}
public int getDollars()
{
return dollars;
}
public void setDollars(int dollars)
{
this.dollars = dollars;
}
public int getCents()
{
return cents;
}
public void setCents(int cents)
{
this.cents = cents;
}
public String toString(){
return "$" + dollars + "." + cents;
}
}
[/code][/QUOTE]
One very small thing you might consider is to change the 100s in the constructor to your CENTS_PER_DOLLAR, like I did here.
Especially considering [QUOTE]Note: the data member CENTS_PER_DOLLAR is a class constant whose value is obviously 100. The int literal 100 must appear only once in your class definition.[/QUOTE]
[QUOTE=Ohfoohy]
[code]
public class MoneyTest {
public static void main(String [] args) {
Money moneyobj1 = new Money();
System.out.println(moneyobj1.toString()); // Should be $0.00
Money moneyobj2 = new Money(324);
System.out.println(moneyobj2.toString()); // Should be $3.24
Money moneyobj3 = new Money(3,47);
System.out.println(moneyobj3.toString()); // Should be $3.47
}
}
[/code][/QUOTE]
The first test will output $0.0, not $0.00
[QUOTE=I am a noob;46438154]One very small thing you might consider is to change the 100s in the constructor to your CENTS_PER_DOLLAR, like I did here.
Especially considering[/QUOTE]
Yeah I noticed that and changed it earlier.
As far as it showing $0.0, I'm thinking I can fix this by changing the toString method to
[code]
return String.format("$%d.%02d", dollars, cents);
[/code]
but it hasn't really talked about doing it that way in the book so I'm leaving it for now.
Anyone work with JSON in c#? I have a very basic parsing question:
If I want to read in an array of node objects (where a node is a name, an array of parent names, and an array of numbers)
[code][["Cloudy", [], [0.5]],
["Sprinkler", ["Cloudy"], [0.1, 0.5]],
["Rain", ["Cloudy"], [0.8, 0.2]],
["WetGrass", ["Sprinkler", "Rain"], [0.99, 0.9, 0.9, 0.0]]][/code]
I want to turn this into a List of Nodes, where Node is
[code]public class Node
{
public string Name;
public List<String> Parents;
public List<Double> CPT;
public Node(string name, List<string> parents, List<Double> cpt)
{
Name = name;
Parents = parents;
CPT = cpt;
}
}[/code]
EDIT: If you help me figure this out I'll gift you something worth $5 on steam.
How do I pass a non-dynamic array to a function as a reference in C++
[QUOTE=Fatfatfatty;46445848]How do I pass a non-dynamic array to a function as a reference in C++[/QUOTE]
Pass a pointer to the array, to the function?
[QUOTE=DoctorSalt;46443254]Anyone work with JSON in c#? I have a very basic parsing question:
If I want to read in an array of node objects (where a node is a name, an array of parent names, and an array of numbers)
[code][["Cloudy", [], [0.5]],
["Sprinkler", ["Cloudy"], [0.1, 0.5]],
["Rain", ["Cloudy"], [0.8, 0.2]],
["WetGrass", ["Sprinkler", "Rain"], [0.99, 0.9, 0.9, 0.0]]][/code]
I want to turn this into a List of Nodes, where Node is
[code]public class Node
{
public string Name;
public List<String> Parents;
public List<Double> CPT;
public Node(string name, List<string> parents, List<Double> cpt)
{
Name = name;
Parents = parents;
CPT = cpt;
}
}[/code]
EDIT: If you help me figure this out I'll gift you something worth $5 on steam.[/QUOTE]
It's really simple, you tokenize the source into a list of tokens, i suggest you use the [URL="https://github.com/TheBerkin/Stringes"]Stringes[/URL] library for that.
You get [ [ "Cloudy" , [ ] , [ 0.5 ] ] these tokens for example, then you just write an expression parser that loads them into your node, it would expect 2 [ tokens, then load the name, expect , and [ tokens, load strings split by , until ] and load into parents, and so on,
[editline]9th November 2014[/editline]
I can write an example if you want.
I am working on a ASP.NET web mvc application for Sharepoint at the moment. It is a weather widget, so not really something "tough". I figured to use simplewheater.js since it is dead easy, now the problem is I cannot get it run at all and I am getting really frustrated.
Well here some code:
_Layout.cshtml
[code]<head>
<meta charset="utf-8" />
<title>@ViewBag.Title - My ASP.NET MVC Application</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("/Scripts/jquery-1.8.2.js")
@Scripts.Render("/Scripts/jquery.simpleWeather.min.js")
@Scripts.Render("/Scripts/weather.js")
</head>[/code]
which translates to:
[code]<head>
<meta charset="utf-8" />
<title>Index - My ASP.NET MVC Application</title>
<link href="/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
<link href="/Content/site.css" rel="stylesheet"/>
<script src="/Scripts/modernizr-2.6.2.js"></script>
<script src="/Scripts/jquery-1.8.2.js"></script>
<script src="/Scripts/jquery.simpleWeather.min.js"></script>
<script src="/Scripts/weather.js"></script>
</head>[/code]
All of the scripts are found and I can view the sourcecode in Chrome just fine.
Now I want to call the simpleWeather plug in in my own javascript file named "weather.js":
[code]$(document).ready(function () {
$.simpleWeather({
location: getLocation(),
unit: 'c',
success: function (weather) {
updateWidget(weather);
},
error: function(error) {
error();
}
});
});[/code]
With this $.simpleWeather is throwing "Uncaught TypeError: undefined is not a function". Now I am kinda stumped and have no idea why it isn't working.
[B]EDIT:[/B]
Fixed it, moved all the script calls in the html into the very end of the body tag.
-snip- solved
This is probably the correct thread, right?
For a couple weeks I have been attempting to decompile some compiled modified lua. The modifications to said lua are the addition of c-like operators and possibly syntax. The file in question is a sort of word list (but i do not know the structure). I first attempted to run it through unluac.jar with ELUAD.bat , which threw an error:
[code]
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at unluac.parse.LFunctionType.parse(LFunctionType.java:27)
at unluac.Main.file_to_function(Main.java:56)
at unluac.Main.main(Main.java:34)
[/code]
I then used a hex editor to change part of the header to match a normal compiled lua header (i have no idea what i'm doing :v:), which threw this error:
[code]
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at java.util.ArrayList.elementData(Unknown Source)
at java.util.ArrayList.remove(Unknown Source)
at unluac.decompile.block.OuterBlock.print(OuterBlock.java:51)
at unluac.decompile.Decompiler.decompile(Decompiler.java:156)
at unluac.Main.main(Main.java:42)
[/code]
I believe this implies I've made progress, but I'm pretty lost on what I can do.
I have also tried using ChunkSpy (0.9.7 for lua 5.1). When using the original, ChunkSpy gave the error it "couldn't read version 56 chunks". When using the modified, after a short amount of time the program crashed.
I'm really not sure what I can do from here.
Links:
[url=https://dl.dropboxusercontent.com/u/55311295/ShareX/2014/11/bone_original.luc]Original[/url]
[url=https://dl.dropboxusercontent.com/u/55311295/ShareX/2014/11/bone_modified.luc]Edited[/url]
What are some solutions to good command line / lightweight debugging, compiling, etc on Windows? (C/C++).
Ideally I'd use whatever suits the above with something like atom.io, sublime, vim, or emacs.
edit: i came up with a solution myself.
So, this isn't really a programming problem per se, but it [b]is[/b] related to homework.
I have the actual project itself done and working perfectly fine, but our professor also wants us to gather some metrics on the performance of the program.
The project is building a CPU scheduling simulator and running a few different scheduling techniques on it. We were provided an existing simulator, and an interface we have to adhere to in order to implement said scheduling techniques. The interface yields the following five functions:
[b]NewProcess(int pid)[/b] - [i]Called when the simulator creates a new process.[/i]
[b]Dispatch(int *pid)[/b] - [i]Called when the simulator is dispatching a process for simulated process. Pid needs to be set to the process ID to dispatch.[/i]
[b]Ready(int pid,int cpuTimeUsed)[/b] - [i]Called when a simulated process is ready to be placed into the ready queue. cpuTimeUsed is how many milliseconds the process was simulated to process, or 0 if it came out of Waiting or NewProcess.[/i]
[b]Waiting(int pid)[/b] - [i]Called when a simulated process calls an IO function, and is suspended until that returns. Calls Ready when the Waiting finishes.[/i]
[b]Terminating(int pid)[/b] - [i]Called when the simulator is terminating a simulated process[/i]
As I said, I have all of this done and working fine. My issue is implementing the metrics.
The metrics my professor wants are, taken from the write-up:
[quote]The items to be measured are:
1. The average, minimum and maximum time that processes spend in the ready queue.
2. The average, minimum and maximum time that processes take to respond to an I/O operation. This is the time between the completion of an I/O operation and the time that the process is next dispatched to the CPU.
3. The proportion of time spent on scheduler overheads. This is the total run time minus the total time processes spend executing on the CPU.
[/quote]
This is in straight C99 (not C++, so no objects). The metrics system I devised uses structures defined as such:
[code]typedef struct SIM_METRIC_ELEMENT_STRUCT {
clock_t lastUpdate;
long totalElapsed;
int isMeasuring;
} SIM_METRIC_ELEMENT;[/code]
Each process has three of such metric elements, stored in a structure defined like so:
[code]typedef struct SIM_METRIC_STRUCT {
int procId;
SIM_METRIC_ELEMENT* readyQueueMetric;
SIM_METRIC_ELEMENT* ioResponseMetric;
SIM_METRIC_ELEMENT* cpuExecutionMetric;
} SIM_METRIC;[/code]
And I have these two metric-related functions:
[code]void metricStartMeasure(SIM_METRIC_ELEMENT* metric) {
if (metric->isMeasuring == 0) {
metric->isMeasuring = 1;
metric->lastUpdate = clock();
}
}
void metricStopMeasure(SIM_METRIC_ELEMENT* metric) {
if (metric->isMeasuring == 1) {
metric->isMeasuring = 0;
if (metric->lastUpdate > 0) {
metric->totalElapsed = clock() - metric->lastUpdate;
}
}
}[/code]
For one, I am not entirely convinced that this metric system is correct, but more importantly, I don't know when exactly to start and stop each of the metrics. The write-up confuses me a bit on how to integrate them within the five functions we are implementing.
I've talked to a few people in my class about it, but everyone I have talked to is in the same boat as I am: the project itself is finished, but they're still trying to get the metrics implemented properly.
The implementation I currently have is as such:
- NewProcess - No action
- Dispatch - Start cpuExecutionMetric, stop ioResponseMetric, stop readyQueueMetric
- Ready - Stop cpuExecutionMetric, stop ioResponseMetric, start readyQueueMetric
- Waiting - Stop cpuExecutionMetric, start ioResponseMetric, stop readyQueueMetric
- Terminating - Stop all metrics
However, the sum times this technique yields exceed the total running time, which I measure separately with a simple "long start = clock(); <do simulation code> endtime = clock() - start" technique. On average, the simulation runs about 6500 ms, but the sum ready metric will be things like 3000, wait 4000, and ready 1500, which obviously does not add up to 6500. This makes me fairly confident I am doing something wrong.
I am hoping, and I know this is a long shot, since it [b]is[/b] a homework assignment, that some of you guys would be willing to, at the very least, provide your own interpretations of where I should be starting and stopping my timers, and perhaps point out if there are any flaws in my timer.
I don't code in C99 very often, so yeah. :v:
Thanks in advance, guys.
So it should never be possible to for more then 1 metric to be running at once, according to the stuff you wrote, you should go and assure that's the case.
There is nothing wrong with the code you posted.
One thing to note is that clock in C is not a high precision timer, if the difference between 2 moments in time is smaller then CLOCKS_PER_SEC/2, clock will return the same value twice and no totalElapsed will be added to the metric.
Urgh! XNA is stupid sometimes, I am trying to load a WAV file, everything is correct, I have the file in the root Content folder, I have changed the properties to copy to output folder, the wav is a signed 16 bit pcm, 2 channel, 44100 Hz file. I am stuck, google won't help, I can load jpg's fine, but not wav, even converted it to a mp3 and tried using the Song class.
So fucking annoying.
[code]
SoundEffect IFuckingHateThisShit = Content.Load<SoundEffect>("fuckyou");
[/code]
That is in the LoadContent method.
file name is fuckyou.wav, I can open it through VS, it plays fine. What the fuck is happening.
AFAIK you need to use that proprietary sound converter thing to load sounds into XNA
[editline]10th November 2014[/editline]
XACT it was called I think
[QUOTE=FalconKrunch;46453313]AFAIK you need to use that proprietary sound converter thing to load sounds into XNA
[editline]10th November 2014[/editline]
XACT it was called I think[/QUOTE]
I love you.
Everytime I copy paste something from Word to Powerpoint it needs atleast 10 seconds.
Enough to blow off my patience and focus.
-snip XNA is trolling me-
I wish I could help you further, it's been 3 years since I've done something with XNA. I gave up hope ever using it again after microsoft dropped support.
[QUOTE=FalconKrunch;46453473]I wish I could help you further, it's been 3 years since I've done something with XNA. I gave up hope ever using it again after microsoft dropped support.[/QUOTE]
Don't worry, XNA was trolling me, sometimes it works, sometimes it doesn't.
I can't have multiple tracks on a cue. -.-
[QUOTE=Fourier;46453448]Everytime I copy paste something from [b]Word to Office[/b] it needs atleast 10 seconds.
Enough to blow off my patience and focus.[/QUOTE]
????
[QUOTE=mastersrp;46453487]????[/QUOTE]
*Powerpoint*
This mistakes just proves how shitty multithreading is.
[QUOTE=Fourier;46453610]*Powerpoint*
This mistakes just proves how shitty [b]multithreading[/b] is.[/QUOTE]
????
Sorry, you need to Log In to post a reply to this thread.