ChocolateCupcakes
Member
Or, you know, Object#wait(long)...
I was assuming he's in a CompSci 1 class and they would want him to do it that way for learning purposes.
Or, you know, Object#wait(long)...
It seems every language has a bunch of poor design decisions. I'm not even sure what is considered the closest to a perfect language. Though java is nice to ease into OOP. I know we have enough language already, but I would like to see a new master race program come along that is developed by a whole bunch of universities and companies.
Part of the issue is that there are so many different philosophies and idioms that are represented by different languages that quite often it's impossible to objectively decide that one approach is better than another.
A lot of Lisp hackers would tell you that we already created the perfect programming language and we did it in 1958. Others would say that that many parentheses can't be the right way to do anything. Some people insist that C is all you need and all this other cruft is just jank on top of that pure imperative paradigm. Most of the rest of us recognise that sometimes you need more abstraction and god damn it nobody wants to implement their own stack every time they need one. A lot of programmers now only know OOP in the Java/C# vein, and all they recognise are classes and inheritance, which drastically limits how you can think and program at all. Still others swear by higher levels of abstraction again and you get your Python or Ruby fans claiming the one true way to do anything, but dynamic typing and flexible interpreters can have all kinds of downsides in terms of correctness and scale with larger projects. Then you get to the more functional paradigms (although yeah Lisp fits that as well ofc) and you get Haskell or ML or Erlang or whatever and everything is persistant data structures, referential transparency, lambda calculus out the whazoo. That model is so fundamentally different from the Turing machine approach that even implementing a stack in Haskell can actually a painful excercise, but expressing infinitely recursing lists of elaborate function mappings is a one liner.
Sorry bit of a rant there but I guess the point is that there's never going to be something like you described because people can't even agree on which model of computation to go with most of the time (I didn't even mention logic programming above), never mind specific language features. I just think it's really important for everyone to get as much exposure to as many languages as possible so that they can recognise when their language/approach of choice is suitable and when it isn't, so many people are straitjacketed by what they know well that they end up picking the wrong tool for the job over and over.
Spoiler, Lisp wins, you can define your own paradigm
I actually prefer Python most of the time.
level 1: PIZZA KEBAB HAMBURGER
you select PIZZA it opens the next level:
level 2: PINEAPPLE HAM CHEESE
you select cheese and you get level 3
LEVEL 3: CHEDDAR EDAM EMMENTAL
And on the grid you see all the Pizzas that contain Cheese.
Use types "CHEESE" and it will show all the Pizzas, Kebabs and Hamburgers that contain Cheese.
Of course you can now pick "PIZZA" and it will show you only the Pizzas that contain cheese which results in same products as in Case 1.
I was assuming he's in a CompSci 1 class and they would want him to do it that way for learning purposes.
Both are doable. Post some code.
If you need a start for number one I would look into the currentTimeMillis function and for number 2 this should put you in the right direction.
Learning to write fucking horrible code?
Yeah, sounds like most CompSci 1 classes, to be honest. When I taught Java, we taught it properly.![]()
int time = 0;
while (time < 20) {
out.println(3);
try {
Thread.sleep(3000)
} catch (Exception ex) {}
time += 3;
}
Be lazy and write something like
Code:int time = 0; while (time < 20) { out.println(3); try { Thread.sleep(3000) } catch (Exception ex) {} time += 3; }
And you'll probably be needing Integer#toBinaryString(int) for the other one, if I read that right.
That's exactly what I needed! Thank you so much. Is the (3000) in Thread.sleep the time in milliseconds or something like that?
That's exactly what I needed! Thank you so much. Is the (3000) in Thread.sleep the time in milliseconds or something like that?
try {
Thread.sleep(3000)
} catch (Exception ex) {}
try {
Thread.sleep(3000);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
Yes.
You know when I said "Fucking horrible code"? That's exactly what I meant.
Firstly it won't do what you want it to (won't shut down after 20 seconds, for reasons that should be obvious - you should be able to fix that, though). Secondly:
Code:try { Thread.sleep(3000) } catch (Exception ex) {}
is an abomination. This should be something more like:
Code:try { Thread.sleep(3000); } catch (InterruptedException ie) { ie.printStackTrace(); }
Never catch exceptions that are overly general. It's horrible, horrible practice. And never simply ignore an exception. Even if you are going to ignore an exception, at the very least have a comment in the code to explain why you are committing this crime against nature.
public class Uppgift1_76
{
public static void main(String [] args) throws InterruptedException
{
int time = 0; //int får värdet 0
while (time < 20)
{
if (time == 18)
{
Thread.sleep(2000);
}
else
{
Thread.sleep(3000);
}
System.out.println(3);
time += 3;
}
}
import java.io.*;
import java.util.Scanner;
public class Uppgift1_62 {
public static void main(String args[]) throws Exception {
Scanner scanner = new Scanner(System.in);
FileOutputStream FOS = new FileOutputStream("textfil.txt");
OutputStream outputStream = new FileOutputStream("textfil.txt");
Writer writer= new OutputStreamWriter(outputStream);
System.out.println("Skriv vad du vill! Huehuehuehue.");
char a = scanner.next().charAt(0);
outputStream.write(a);
FileInputStream input1 = new FileInputStream("textfil.txt");
Reader reader = new InputStreamReader(input1);
int data = reader.read();
System.out.println((char) data);
FOS.close();
writer.close();
reader.close();
scanner.close();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace ThreadedSort
{
public class QuickSort
{
public int[] MyArray = new int[10];
public int tempElements;
private int numThreads = 0;
private int maxThreads = 4;
private Object lockObject = new Object();
public void QuickSorter()
{
sort(0, tempElements - 1);
}
public void sort(int left, int right)
{
int pivot;
int leftSide;
int rightSide;
leftSide = left;
rightSide = right;
pivot = MyArray[left];
//The first loop through all this place number 1 and 2 in element 0 and 1.
while (left < right)
{
while ((MyArray[right] >= pivot) && (left < right))
{
right--;
}
if (left != right)
{
MyArray[left] = MyArray[right];
left++;
}
while ((MyArray[left] <= pivot) && (left < right))
{
left++;
}
if (left != right)
{
MyArray[right] = MyArray[left];
right--;
}
}
MyArray[left] = pivot;
pivot = left;
left = leftSide;
right = rightSide;
if (left < pivot)
{
if(numThreads < maxThreads)
{
lock (lockObject)
{
numThreads++;
//A new thread is started and is given startSort so it knows of the remaining elements to sort, iirc.
Thread myThread = new Thread(new ParameterizedThreadStart(startSort));
myThread.Start(new SortParameters(this, left, pivot - 1));
/*test1 is printed twice before the sorted list is even printed on the screen, I don't know why. Sometimes even in the middle of the sorted list!*/
Console.WriteLine("test1");
}
}
//else
//{
// sort(left, pivot - 1);
// Console.WriteLine("test2");
//}
}
/*For some reason, test3 below is printed four times after all the code in main() is finished O_o*/
if (right > pivot)
{
sort(pivot + 1, right);
Console.WriteLine("test3");
//Thread.Sleep(100);
}
}
static void startSort(Object obj)
{
SortParameters sortParam = (SortParameters)obj;
sortParam.instance.sort(sortParam.left, sortParam.right);
}
public class SortParameters
{
public QuickSort instance;
public int left;
public int right;
public SortParameters(QuickSort instance, int left, int right)
{
this.instance = instance;
this.left = left;
this.right = right;
}
}
}
}
I do C# and I love it. I think the libraries are great and the syntax is excellent. I have luckily managed to avoid doing anything relating to sharepoint, though; can't speak to it.Hi guys, just after an opinion if that's okay, I'm currently working as a PHP developer, but due to a huge restructure of the organisation the role my colleague and I do is being 'deleted'.
There's only one more 'suitable' role there we can go to, doing mostly C# .NET and Sharepoint. I have very little experience of either, working on just one project of each in the past, I really enjoyed C#, but found Sharepoint to be a bit of a nightmare though it was an odd project to work on, anyhow I'd be grateful for any advice regarding my options...
1) Take voluntary redundancy (£8k) and carry on in my job (can go until 31st March) in the hope I find a new job elsewhere, doing PHP
2) Hold out for the job doing the Windows stuff, cross my fingers and hope I get the job
3) Make life easier for everyone involved and go for a slightly lower paid job, doing more content type things and front end HTML/CSS rather than back end development
I'm much more worried about having a job I'll enjoy and find rewarding than I am money, so don't want to just grab the £8k redundancy and leave them. Would really, really appreciate any guidanceThanks GAF!
If you can, go for C#. I don't know anything about SharePoint, but it's a great opportunity to get some C# experience and you should use it. If SharePoint is indeed bad, down the road and with some experience you could look for another job in C#.Hi guys, just after an opinion if that's okay, I'm currently working as a PHP developer, but due to a huge restructure of the organisation the role my colleague and I do is being 'deleted'.
There's only one more 'suitable' role there we can go to, doing mostly C# .NET and Sharepoint. I have very little experience of either, working on just one project of each in the past, I really enjoyed C#, but found Sharepoint to be a bit of a nightmare though it was an odd project to work on, anyhow I'd be grateful for any advice regarding my options...
1) Take voluntary redundancy (£8k) and carry on in my job (can go until 31st March) in the hope I find a new job elsewhere, doing PHP
2) Hold out for the job doing the Windows stuff, cross my fingers and hope I get the job
3) Make life easier for everyone involved and go for a slightly lower paid job, doing more content type things and front end HTML/CSS rather than back end development
I'm much more worried about having a job I'll enjoy and find rewarding than I am money, so don't want to just grab the £8k redundancy and leave them. Would really, really appreciate any guidanceThanks GAF!
Learning to write fucking horrible code?
Yeah, sounds like most CompSci 1 classes, to be honest. When I taught Java, we taught it properly.![]()
Code:import java.io.*; import java.util.Scanner; public class Uppgift1_62 { public static void main(String args[]) throws Exception { Scanner scanner = new Scanner(System.in); FileOutputStream FOS = new FileOutputStream("textfil.txt"); OutputStream outputStream = new FileOutputStream("textfil.txt"); Writer writer= new OutputStreamWriter(outputStream); System.out.println("Skriv vad du vill! Huehuehuehue."); char a = scanner.next().charAt(0); outputStream.write(a); FileInputStream input1 = new FileInputStream("textfil.txt"); Reader reader = new InputStreamReader(input1); int data = reader.read(); System.out.println((char) data); FOS.close(); writer.close(); reader.close(); scanner.close(); } }
In this code I want the program to make a file which contains the input from the user. The problem is that "char a = scanner.next().charAt(0);" only saves the first letter in that is written. Is there another line I can use to make this shit work?
//Add a new passenger to the dataGridView
private void buttonAddPassenger_Click(object sender, EventArgs e)
{
int seatNum = Int32.Parse(this.textSeatNo.Text);
if (seatNum >= numberOfSeats) //validate the seatNo
{
MessageBox.Show("The seat number must be in the range of 1 to " + numberOfSeats);
}
else
{
int RowIndex=0;
//search for the array index of the seat with seatNo = seatNum
for (int i = 0; i < numberOfSeats; i++)
{
if (SeatArray[i].SeatNo == seatNum)
{
RowIndex = i;
break;
}
}
SeatArray[RowIndex].SeatAssign = this.checkBoxFirstClass.Checked;
frm2.EconPass1.Text = frm2.EconPass1.Text;
SeatArray[RowIndex].PassName = frm2.EconPass1.Text;
//If I add the following and try to get information from more than one form, I get the NullReferenceException was unhandled error
frm3.EconPass2.Text = frm3.EconPass2.Text;
SeatArray[RowIndex].PassName = frm3.EconPass2.Text;
frm3.EconPass3.Text = frm3.EconPass3.Text;
SeatArray[RowIndex + 1].PassName = frm3.EconPass3.Text;
frm4.EconPass4.Text = frm4.EconPass4.Text;
SeatArray[RowIndex].PassName = frm4.EconPass4.Text;
frm4.EconPass5.Text = frm4.EconPass5.Text;
SeatArray[RowIndex + 1].PassName = frm4.EconPass5.Text;
frm4.EconPass6.Text = frm4.EconPass6.Text;
SeatArray[RowIndex + 2].PassName = frm4.EconPass6.Text;
dataGridView1.Refresh();
}
I made a huge mistake in my career and moved from C# to PHP. I regret it every time I think about it.
So thanks to your feedback and some other help we finally solved the cases! Although now I am on a totally new case and I don't even know where to start.
They want us to create a program that uses the method min (no idea what this is) to recieve two integers and return the smaller of those two. Then they want us to make another method that takes the other method's place and recieves two floats and return the smaller of them. Then they want us to make the method main take two integers and decide which one of them is the smaller by calling the method min. Then they want us to repeat the same thing with two floats and show all the results.
Do you even know what I am saying because I sure as hell don't. :/
This in particular stood out for me - what makes you say this Roquentin? Sorry to hear that btw.I made a huge mistake in my career and moved from C# to PHP. I regret it every time I think about it.
Java documentation is your friend. The math objects min methods will make this easy. Just throw in a scanner to collect the integers and floats in the main call the min methods on them and output it.
Hi. Just started programming (learning C#). Doing my first Forms application. I want the application to populate the array using information from text boxes (using a different form each time) but I think the application is trying to take information from all forms at once and gives me a "NullReferenceException was unhandled" error.
This is probably really easy to rectify and I'm just being dumb. Can anyone help?
Code://Add a new passenger to the dataGridView private void buttonAddPassenger_Click(object sender, EventArgs e) { int seatNum = Int32.Parse(this.textSeatNo.Text); if (seatNum >= numberOfSeats) //validate the seatNo { MessageBox.Show("The seat number must be in the range of 1 to " + numberOfSeats); } else { int RowIndex=0; //search for the array index of the seat with seatNo = seatNum for (int i = 0; i < numberOfSeats; i++) { if (SeatArray[i].SeatNo == seatNum) { RowIndex = i; break; } } SeatArray[RowIndex].SeatAssign = this.checkBoxFirstClass.Checked; frm2.EconPass1.Text = frm2.EconPass1.Text; SeatArray[RowIndex].PassName = frm2.EconPass1.Text; //If I add the following and try to get information from more than one form, I get the NullReferenceException was unhandled error frm3.EconPass2.Text = frm3.EconPass2.Text; SeatArray[RowIndex].PassName = frm3.EconPass2.Text; frm3.EconPass3.Text = frm3.EconPass3.Text; SeatArray[RowIndex + 1].PassName = frm3.EconPass3.Text; frm4.EconPass4.Text = frm4.EconPass4.Text; SeatArray[RowIndex].PassName = frm4.EconPass4.Text; frm4.EconPass5.Text = frm4.EconPass5.Text; SeatArray[RowIndex + 1].PassName = frm4.EconPass5.Text; frm4.EconPass6.Text = frm4.EconPass6.Text; SeatArray[RowIndex + 2].PassName = frm4.EconPass6.Text; dataGridView1.Refresh(); }
SeatArray[RowIndex + 1].PassName = frm3.EconPass3.Text;
I don't have a lot of commercial experience in C# and the last one was almost 6 years ago. But the biggest problem is that I just haven't used C# and .Net in a long time, because PHP was more suitable for my personal projects. Getting back to C# would take a while, I might do it at some point, but currently I'm trying to get back to C++.This is confusing me. Do you mean that you now literally can't get anyone to consider you for an alternate job that involves a different language? How does working in PHP now impair you from working in whatever other language you would prefer or at least applying for positions that will let you?
C# is a better designed technology and you can make much more money in it than in PHP.This in particular stood out for me - what makes you say this Roquentin? Sorry to hear that btw.
The exception stack trace will say which line it occurs on, fwiw.
But it's probably this line:
Code:SeatArray[RowIndex + 1].PassName = frm3.EconPass3.Text;
Like mike23 said, SeatArray probably isn't filled with actual objects for some reason. Even if you fix the error though, something tells me the code won't be doing what you're trying to make it do. What did you mean by "I want the application to populate the array using information from text boxes (using a different form each time)"? What does 'each time' mean? Do you want the button to do something different each time you click it? Or do you want it to do multiple things on a single click? The latter is the way you have it coded right now.
frm2.EconPass1.Text = frm2.EconPass1.Text;
SeatArray[RowIndex].PassName = frm2.EconPass1.Text;
frm2.EconPass1.Text = frm2.EconPass1.Text;
SeatArray[RowIndex].PassName = frm2.EconPass1.Text;
//If I add the following, I get the NullReferenceException was unhandled error
frm3.EconPass2.Text = frm3.EconPass2.Text;
SeatArray[RowIndex].PassName = frm3.EconPass2.Text;
frm3.EconPass3.Text = frm3.EconPass3.Text;
SeatArray[RowIndex + 1].PassName = frm3.EconPass3.Text;
frm4.EconPass4.Text = frm4.EconPass4.Text;
SeatArray[RowIndex].PassName = frm4.EconPass4.Text;
frm4.EconPass5.Text = frm4.EconPass5.Text;
SeatArray[RowIndex + 1].PassName = frm4.EconPass5.Text;
frm4.EconPass6.Text = frm4.EconPass6.Text;
SeatArray[RowIndex + 2].PassName = frm4.EconPass6.Text;
namespace SeatApp1
{
public partial class Form1 : Form
{
//array to store all the Seat objects
static int numberOfSeats = 200;
Seat[] SeatArray = new Seat[numberOfSeats];
//algorithm to bind datagrid to an array
private CurrencyManager currencyManager = null;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < numberOfSeats; i++)
{
//initialize the array with numberOfSeats Seat object
SeatArray[i] = new Seat(i + 1);
}
//binding the datagrid to the array
currencyManager = (CurrencyManager)dataGridView1.BindingContext[SeatArray];
dataGridView1.DataSource = SeatArray;
}
mike23 said:You should have SeatArray[x] = new Seat(); somewhere in your code.
I don't have a lot of commercial experience in C# and the last one was almost 6 years ago. But the biggest problem is that I just haven't used C# and .Net in a long time, because PHP was more suitable for my personal projects. Getting back to C# would take a while, I might do it at some point, but currently I'm trying to get back to C++.
C# is a better designed technology and you can make much more money in it than in PHP.
So thanks to your feedback and some other help we finally solved the cases! Although now I am on a totally new case and I don't even know where to start.
They want us to create a program that uses the method min (no idea what this is) to recieve two integers and return the smaller of those two. Then they want us to make another method that takes the other method's place and recieves two floats and return the smaller of them. Then they want us to make the method main take two integers and decide which one of them is the smaller by calling the method min. Then they want us to repeat the same thing with two floats and show all the results.
Do you even know what I am saying because I sure as hell don't. :/
public int min(int a, int b)
{
...stuff...
return smallest;
}
public float min(float a, float b)
{
..stuff..
return smallest;
}
public static void main()
{
... get some int a and int b from the user
int smallestInt = min(a, b);
... get some float a and float b from the user
float smallestFloat = min(a,b);
... print out smallestInt and smallestFloat
}
from tkinter import *
import p2
recordList = [...]
root = Tk()
subroot = Toplevel(root)
x = p2.MainInterface(subroot)
for listItem in recordList:
x.addRecord(listItem)
root.mainloop()
Writing unit tests on a Saturday is heaven on earth, am I right or am I right?
Coffee in hand... Michael Jackson/Madonna blend playlist playing (worlds collide)... good times.
I'm personally just glad I don't work weekends.
Does anyone have a good source for learning Java for someone who already knows java syntax (via C) and other programming languages? I'm thinking specifically stuff like methods, object oriented programming, how to write "good" java programs, specific pitfalls, etc.
We used PCASM in a recent Assembly course: http://www.drpaulcarter.com/pcasm/
I found it decent enough to teach the basics.
I have 3 tables, `USER`, `ENTRY` (for entered products, not necessary to create a PRODUCT table), and `USER_COLLECTION`, which is a table inbetween `USER` and `ENTRY`, because an entry can have multiple users.
Basically:
User = `USERID | USER_NAME`
Entry = `ENTRYID | ENTRY_NAME | ENTRYPRICE | ENTRY_DATE`
Collection = `COLLECTIONID | ENTRYID | USERID`
I have a table with users that persist throughout the project. They can create entries (which is usually some kind of product with a price) and they can link multiple users to a certain entry (which can be selected from a list, hence the users persist throughout the project).
So for instance, my tables look like this:
User
--------------------------
user_id | user_name
--------------------------
1 | 'FOO'
2 | 'BAR'
3 | 'FOOBAR'
ENTRY
-----------------------------------------------------------------------
entryid | entry_name | entry_price | entry_date
-----------------------------------------------------------------------
0 | 'Banana' | 2.50 | 12/12/2012
COLLECTION
---------------------------------------
collectionid | entryid | userid
----------------------------------------
0 | 1 | 1
1 | 1 | 2
0 | 1 | 3
I have a Banana, with a price of 2.50 and 3 users linked to it, Foo, Bar and Foobar.
Now, I want to use this in my app and get the data; except I don't know where to start. I tried selecting the entry data, using that id to loop through the collection data, but that would mean I have two cursors open and it wouldn't work. Tried creating a join but I couldn't really make a good one, mainly because:
JOIN
---------------------------------------
collectionid | entryname | username
----------------------------------------
0 | Banana | FOO
1 | Banana | BAR
0 | Banana | FOOBAR
I can't iterate through this, because I would create multiple of the same entry objects in my Android code...
Hope I'm being clear on this.
Got a bit of a problem with sqlite in android
http://stackoverflow.com/questions/...-through-a-joined-table-with-multiple-results
Here's my question; a bit easier formatting than posting the text on gaf.
---------------------------------------
collectionid | entryid | entryname | username
----------------------------------------
0 | 1 | Banana | FOO
1 | 1 | Banana | BAR
0 | 1 | Banana | FOOBAR
I learned through trudging, but I'm sure there's good tutorials out there somewhere.i just started learning PERL (scripting i guess, not technically programming). Its becoming pretty valuable in my field (network engineering) and coming from a c++ background, good lord is it quick to write.
My nemesis though... regex. Any good documentation to help with regex knowledge or is just basically trudge through it and learn by pain?
I know nothing at all about Android development so there could well be an ORM based approach or something you should use instead but the obvious thing to do is fetch the entry_id as well as entry_name for the banana. Then you can use a dicitonary or something to map new objects into to make sure you only create one instance of the object for each instance in the DB.
So you would get:
Code:--------------------------------------- collectionid | entryid | entryname | username ---------------------------------------- 0 | 1 | Banana | FOO 1 | 1 | Banana | BAR 0 | 1 | Banana | FOOBAR
As you go to create new bananas, look up the id in the map to see if it exists. If it does just return that object rather than create a new one.