[QUOTE=ZeekyHBomb;42775982]I'm not sure why the last line appears twice, but the missing first line can be fixed simply by removing line 48.
You can more easily write the whole contents using dout << din.rdbuf();, but I'm guessing you did this just to debug something.
A few other things:
Usage of system("pause") and system("cls") is discouraged. You should easily find stuff on the internet about that.
The general consensus is, that you should declare/define variables as late as it makes sense. There's usually little reason to declare them all at the top.
I personally find the names "fName" and "lName" rather unhelpful. What's wrong with "firstName" and "lastName"? Readability gets increased a lot and you only need to type a little more.
"userWght" also.
When in doubt, prefer double over float.
You have constants for the welcome message, which seem to allow easy changes to the message, but the alignment in the console seems to depend on a fixed length of the messages.
And further more, it seems to require a certain terminal size.
There are ways to obtain the dimensions of the console buffer on Windows through the WinAPI if you want to go through the trouble of making sure it always looks well.
You don't need to manually close the files; they will close themselves when the variable goes out of scope. This is a pattern called RAII.
And the spacing looks weird in some places, like all but the first the cout-lines being alinged and ... what is this even in the commented CalcBAC line? Though I'm guessing this might be due to some pastebin or edit-after-paste error.[/QUOTE]
I'm taking an introductory C++ course and as so the curriculum is being taught at a very introductory level so a few points to clear things up. (I know a lot of this is silly but if you don't follow the guidelines exactly as he has them outlined you lose points)
1. The usage of pause and cls are required for the project I am doing.
2. Declaring all variables at the top, fName and lName are also required. We are required to comment all variables.
3. We are expected to use floats for this program
4. We are required to manually close the files
The spacing is only weird looking because of pastebin, it's more organized in visual studio.
Yeah, this is just for error checking, the loop syntax looks correct though the output is not.
What would be the easiest way in java to make a string have X with?
So the java equivalent of C++:
[cpp]std::cout << std::setw( mTagWidth ) << str << std::endl;[/cpp]
Need help figuring out an algorithm. By posting it here I'll also define it properly in my head to try to tackle it more seriously...
I have a list of objects like this:
[IMG]http://i.imgur.com/RoV3Gp9.png[/IMG]
The first table contains the categories of an object, the second its masks. The object will ignore physical collision with objects that are of any of the categories contained in its mask list. So, for instance, EnemyWall ignores 1, 2, 3, which means that EnemyWall ignores Solids, the Player, but doesn't ignore Blaster and Roller (which are enemies). And that's exactly right because an EnemyWall is an invisible wall that only enemies should be able to collide with.
The problem is, I want to add a new object (Boulder) and I need it to ignore Ladder, EnemyWall and Spikes, this means that I'd have to change a few numbers around and spend some time thinking about it, since I only have 16 available numbers for categories!
The algorithm I'm trying to come up with is: how to automatically create this table in terms of defining what object types one object should ignore?
For instance:
[code]
Boulder.ignores = {'Ladder', 'Spikes', 'EnemyWall'}
EnemyWall.ignores = {'Player', 'Solid', 'BreakableSolid'}
Player.ignores = {'Ladder', 'EnemyWall', 'MeleeArea'}
...
[/code]
should return the appropriate table (with the categories and masks) for each object type. How to do that? Is it even possible? I can't even start thinking about a way to do this automatically... ;_;
[QUOTE=Rofl my Waff;42776959]Yeah, this is just for error checking, the loop syntax looks correct though the output is not.[/QUOTE]
Is it correct with line 48 removed?
[QUOTE=Richy19;42777508]What would be the easiest way in java to make a string have X with?
So the java equivalent of C++:
[cpp]std::cout << std::setw( mTagWidth ) << str << std::endl;[/cpp][/QUOTE]
There's [url=http://docs.oracle.com/javase/6/docs/api/java/io/PrintStream.html#printf(java.lang.String,%20java.lang.Object...)]PrintStream.printf[/url], just specify a width.
Why the fuck is Swing so fucking difficult to work with?
The API designers tried to make it easy and convenient, and they just made it possibly the most difficult API ever devised by man. It is fucking impossible to work with. Want to make a text-area with a constant size? You're gonna have to write a few hundred lines of code and make a few dozen objects to fucking work around the fuck that [b]we won't just fucking let you![/b]
God damn Swing pisses me off.
Can someone please build this UI for me? I fucking give up. This is all I want:
[t]https://dl.dropboxusercontent.com/u/8416055/DeleteMe/FuckSwing.png[/t]
It's an arbitrarily simple construct, but Swing just refuses to let me build it.
I would really appreciate it if someone would be willing to build this for me.
[QUOTE=adnzzzzZ;42777552]The algorithm I'm trying to come up with is: how to automatically create this table in terms of defining what object types one object should ignore?
For instance:
[code]
Boulder.ignores = {'Ladder', 'Spikes', 'EnemyWall'}
EnemyWall.ignores = {'Player', 'Solid', 'BreakableSolid'}
Player.ignores = {'Ladder', 'EnemyWall', 'MeleeArea'}
...
[/code]
should return the appropriate table (with the categories and masks) for each object type. How to do that? Is it even possible? I can't even start thinking about a way to do this automatically... ;_;[/QUOTE]
I was thinking something like this:
[code]local collision_mask_name_to_index = setmetatable({}, {__index = function(table, key)
local index = table.getn(table) + 1
rawset(table, name, index)
return index
end})
local collision_masks = {}
local function create_collision_mask(name, categories, ignored)
local indexed_categories = {}
tabke.setn(indexed_categories, #categories)
for i, category in ipairs(categories) do
indexed_categories[i] = collision_mask_name_to_index[category]
end
local indexed_ignored = {}
table.setn(indexed_ignored, #ignored}
for i, ignore in ipairs(ignored) do
indexed_ignored[i] = collision_mask_name_to_index[ignore]
end
collision_masks[name] = { categories = indexed_categories, masks = indexed_ignored }
end[/code]
But I don't get it to work. Lua is not my strength though, maybe you can pick it up from here.
And I hope I understood your problem correctly.
What I intended is lazily creating an index for the category names through getmetatable(collision_mask_name_to_index).__index. Then you can pass string-arrays to create_collision_mask for the category and masks and it does a lookup to map the name to a number, which get stored in the collision_masks[name] fields.
[editline]6th November 2013[/editline]
[QUOTE=Gmod4ever;42779317]Why the fuck is Swing so fucking difficult to work with?
The API designers tried to make it easy and convenient, and they just made it possibly the most difficult API ever devised by man. It is fucking impossible to work with. Want to make a text-area with a constant size? You're gonna have to write a few hundred lines of code and make a few dozen objects to fucking work around the fuck that [b]we won't just fucking let you![/b]
God damn Swing pisses me off.[/QUOTE]
Have you read [url=http://docs.oracle.com/javase/tutorial/uiswing/layout/none.html]this[/url]?
[QUOTE=ZeekyHBomb;42779395]I was thinking something like this:
[code]local collision_mask_name_to_index = setmetatable({}, {__index = function(table, key)
local index = table.getn(table) + 1
rawset(table, name, index)
return index
end})
local collision_masks = {}
local function create_collision_mask(name, categories, ignored)
local indexed_categories = {}
tabke.setn(indexed_categories, #categories)
for i, category in ipairs(categories) do
indexed_categories[i] = collision_mask_name_to_index[category]
end
local indexed_ignored = {}
table.setn(indexed_ignored, #ignored}
for i, ignore in ipairs(ignored) do
indexed_ignored[i] = collision_mask_name_to_index[ignore]
end
collision_masks[name] = { categories = indexed_categories, masks = indexed_ignored }
end[/code]
But I don't get it to work. Lua is not my strength though, maybe you can pick it up from here.
And I hope I understood your problem correctly.
What I intended is lazily creating an index for the category names through getmetatable(collision_mask_name_to_index).__index. Then you can pass string-arrays to create_collision_mask for the category and masks and it does a lookup to map the name to a number, which get stored in the collision_masks[name] fields.
[/QUOTE]
I want to solve the part that automatically gets the numbers categories and ignored automatically, not what you solved.
From:
[code]
A.ignores = {'A', 'B', 'C', 'D'}
B.ignores = {'C'}
C.ignores = {'B'}
D.ignores = {'A', 'C', 'D'}
[/code]
to:
[code]
collision_masks['A'] = ({1}, {1, 2, 3, 4})
collision_masks['B'] = ({2}, {3})
collision_masks['C'] = ({3}, {2})
collision_masks['D'] = ({4}, {1, 3, 4})
[/code]
but taking into account that I only have 16 numbers (so I have to minimize the usage of new numbers when possible) AND that it has to be done automatically. So using my game as a more complicated example:
[IMG]http://i.imgur.com/C8u94B8.png[/IMG]
[code]
Player.ignores = {}
Solid.ignores = {}
BreakableSolid.ignores = {}
EnemyWall.ignores = {'Player', 'Solid', 'BreakableSolid', 'FaderParticle', 'TNT', 'EnemyWall', 'Boulder'}
MeleeArea.ignores = {everything... too much to type}
local group_a = {'Player', 'MeleeArea', 'PhysicsParticle', 'BreakableParticle', 'Blaster', 'Roller', 'item', 'SpikedBall', 'Spikes', 'Ladder', 'JumpingPad', 'ChainedSpikedBallBall'}
PhysicsParticle.ignores = group_a
FaderParticle.ignores = group_a
BreakableParticle.ignores = table.join(group_a, {'EnemyWall', 'BreakableSolid', 'FaderParticle', 'TNT'})
Blaster.ignores = table.join(group_a, {'Boulder'})
Roller.ignores = table.join(group_a, {'Boulder'})
Item.ignores = group_a
SpikedBall.ignores = group_a
Spikes.ignores = group_a
Ladder.ignores = group_a
JumpingPad.ignores = {}
ChainedSpikedBall.ignores = {}
ChainedSpikedBallBall.ignores = {everything except Boulder}
TNT.ignores = {}
Boulder.ignores = {}
[/code]
all that (the .ignores) should be converted to a logical combination of categories and masks that corresponds to the things that should be ignored or not.
[editline]6th November 2013[/editline]
[QUOTE=adnzzzzZ;42779911]I want to solve the part that automatically gets the numbers categories and ignored automatically, not what you solved.
From:
[code]
A.ignores = {'A', 'B', 'C', 'D'}
B.ignores = {'C'}
C.ignores = {'B'}
D.ignores = {'A', 'C', 'D'}
[/code]
to:
[code]
collision_masks['A'] = ({1}, {1, 2, 3, 4})
collision_masks['B'] = ({2}, {3})
collision_masks['C'] = ({3}, {2})
collision_masks['D'] = ({4}, {1, 3, 4})
[/code]
but taking into account that I only have 16 numbers (so I have to minimize the usage of new numbers when possible) AND that it has to be done automatically. So using my game as a more complicated example:
[IMG]http://i.imgur.com/C8u94B8.png[/IMG]
[code]
Player.ignores = {}
Solid.ignores = {}
BreakableSolid.ignores = {}
EnemyWall.ignores = {'Player', 'Solid', 'BreakableSolid', 'FaderParticle', 'TNT', 'EnemyWall', 'Boulder'}
MeleeArea.ignores = {everything... too much to type}
local group_a = {'Player', 'MeleeArea', 'PhysicsParticle', 'BreakableParticle', 'Blaster', 'Roller', 'item', 'SpikedBall', 'Spikes', 'Ladder', 'JumpingPad', 'ChainedSpikedBallBall'}
PhysicsParticle.ignores = group_a
FaderParticle.ignores = group_a
BreakableParticle.ignores = table.join(group_a, {'EnemyWall', 'BreakableSolid', 'FaderParticle', 'TNT'})
Blaster.ignores = table.join(group_a, {'Boulder'})
Roller.ignores = table.join(group_a, {'Boulder'})
Item.ignores = group_a
SpikedBall.ignores = group_a
Spikes.ignores = group_a
Ladder.ignores = group_a
JumpingPad.ignores = {}
ChainedSpikedBall.ignores = {}
ChainedSpikedBallBall.ignores = {everything except Boulder}
TNT.ignores = {}
Boulder.ignores = {}
[/code]
all that (the .ignores) should be converted to a logical combination of categories and masks that corresponds to the things that should be ignored or not.[/QUOTE]
I'm getting convinced that this can't be solved normally without some kind of logic programming or some shit like that.
It's my first time posting here, so I apologize if it's a stupid question. I'm learning Java, so I'm still very new to it.
[code]
public void playSound(){
try{
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(JWindow.class.getResource("resources/music/bgm.wav"));
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
clip.start();
}catch(Exception ex){
System.out.println("Error with playing sound.");
ex.printStackTrace();
}
}
[/code]
When I try this, and call upon playSound() on the main I get these errors.
[t]https://dl-web.dropbox.com/get/Untitled.png?w=AAAp7lipJpxctxCYWfz-mpQG-Njvj6wx03FBu4mkWTQRrQ[/t]
I know that it's returning null due to something with my getResource perhaps, but I can't figure out why. Again, apologies if it's an incredibly stupid question.
What errors? My guess is getResource is returning null because the file can't be found, but that's without seeing the errors or taking a look at the API
[QUOTE=Banana Lord.;42781457]What errors? My guess is getResource is returning null because the file can't be found, but that's without seeing the errors or taking a look at the API[/QUOTE]
Errors are at the bottom on the debug. I'll copy paste here.
[code]
java.lang.NullPointerException
at com.sun.media.sound.StandardMidiFileReader.getSequence(StandardMidiFileReader.java:226)
at javax.sound.midi.MidiSystem.getSequence(MidiSystem.java:836)
at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(SoftMidiAudioFileReader.java:174)
at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1145)
at javagame1.JWindow.playSound(JWindow.java:100)
at javagame1.JWindow.<init>(JWindow.java:39)
at javagame1.JWindow$1.<init>(JWindow.java:51)
at javagame1.JWindow.main(JWindow.java:51)
[/code]
The file is there, that much I know.
I call images from roughly the same directory, albeit instead of music I use images for it. So I know it's able to access it.
[editline]6th November 2013[/editline]
Oh my god... I fucking... I removed resources from it, so music/bgm.wav worked.... I hate my life..
"music/bgm.wav" worked, instead of "resources/music/bgm.wav" so it was ignoring resources... I'm gonna go cry now. Four hours... At least I know now... Thanks Banana anyway.
- snip -
Considering that it's just maths, easy.
Since you said that you want the [i]compiled program[/i] and [i]include portable librarlies[/i], I'm guessing that you should either target the JVM or a popular scripting language, such as Perl or Python. If you just want the source to be cross-platform, then you have more choice.
Have to make an app for a Windows 8 tablet.
Basically I call an API that gives me a JSON object as a reply.
For example, If I call Cities, I want to get a list of Cities.
This list can be very large, so we have to implement a circular array sort of buffered thing.
So I display like a ListView of 10 Citys, and when I scroll down in makes another call, and removes the components off screen.
Any good tutorials on how to do this cause I don't have a clue
[QUOTE=Gmod4ever;42779317]Why the fuck is Swing so fucking difficult to work with?
The API designers tried to make it easy and convenient, and they just made it possibly the most difficult API ever devised by man. It is fucking impossible to work with. Want to make a text-area with a constant size? You're gonna have to write a few hundred lines of code and make a few dozen objects to fucking work around the fuck that [b]we won't just fucking let you![/b]
God damn Swing pisses me off.
Can someone please build this UI for me? I fucking give up. This is all I want:
[t]https://dl.dropboxusercontent.com/u/8416055/DeleteMe/FuckSwing.png[/t]
It's an arbitrarily simple construct, but Swing just refuses to let me build it.
I would really appreciate it if someone would be willing to build this for me.[/QUOTE]
[cpp]
package view;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Main {
private JFrame frame;
private JPanel contentPane;
private JPanel panelPane;
private JButton addPanelButton;
private TextAreaPanel textAreaPanel;
public Main() {
frame = new JFrame();
frame.setLocationRelativeTo(null);
frame.setResizable(false);
contentPane = new JPanel(new BorderLayout());
frame.add(contentPane);
addPanelButton = new JButton("Add panel");
addPanelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
panelPane.add(new TextAreaPanel());
frame.pack();
frame.revalidate();
}
});
contentPane.add(addPanelButton, BorderLayout.PAGE_START);
panelPane = new JPanel(new FlowLayout());
contentPane.add(panelPane, BorderLayout.CENTER);
textAreaPanel = new TextAreaPanel();
panelPane.add(textAreaPanel);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
[/cpp]
[cpp]
package view;
import javax.swing.*;
public class TextAreaPanel extends JPanel {
private JTextArea jTextArea;
public TextAreaPanel() {
jTextArea = new JTextArea(5,15);
jTextArea.setEditable(true);
add(jTextArea);
}
}
[/cpp]
To not allow any more lines and characters to the JTextArea you'll have to use a
[url]http://docs.oracle.com/javase/7/docs/api/javax/swing/text/DocumentFilter.html[/url] , didn't particularly feel like writing one as I feel your pain, Swing is a bitch.
[QUOTE=adnzzzzZ;42779911]
I'm getting convinced that this can't be solved normally without some kind of logic programming or some shit like that.[/QUOTE]
This is a delicious comp sci problem. It can be solved using a [URL="http://en.wikipedia.org/wiki/Disjoint-set_data_structure"]disjoint-set[/URL] data structure. I don't know Lua so I'll just tell you the basic algorithm.
1. Create a set for each object. The goal is to union sets until there are 16 or fewer.
2. For each pair of objects x,y iterate over all ignore lists and check "Does it ignore x and y or does it ignore neither?"
3. If this conditions holds for all ignore lists, union x's set and y's set.
4. Now all remaining disjoint sets are your collision groups.
This is pretty inefficient (something like O(N^3)) but since it's a one-time job I don't think it's that bad.
How the algorithm works:
For each pair of objects, the conditions checks "Is x ignored if and only if y is ignored?" The nice thing about this relationship is that it is transitive e.g. if we know that "x is ignored if and only if y is ignored and y is ignored if and only if z is ignored" then we also know "x is ignored if and only if z is ignored". If we group ignored objects together using this relation, then just by making sure the collision groups works with all [I]pairs[/I] of elements, we are guaranteed that they will work with all [I]subsets[/I] of elements. The disjoint-set data structure is perfect for representing transitive relationships because you can just say "union x's set and y's set" and it will automatically bring along all of the elements that x and y are transitively related to.
:eng101:
So, for my CS course, I have to create a game with the Playstation Mobile SDK. Everyone is doing a schmup, but I decided to do a platformer. I'm trying to get a spritesheet working for it, but there's so little documentation out there that I have no fucking idea what I'm doing.
There's a tutorial on the PSM docs that show a broad way of doing it with their custom libraries, but I'm still just completely overwhelmed.
Here are the docs:
[url]https://psm.playstation.net/static/general/dev/en/sdk_docs/efficient_rendering_en.html[/url]
Can anyone make sense of this? Or is there an easier way to do it?
I have been learning C and was wondering if there was a better way to write this?
[cpp]// subtract all characters of string b from string a
// todo: maybe make it return third string with members a - b?
void strsub( char a[], char b[] ) {
int ia, ib, ic, has;
ic = 0;
for ( ia = 0; a[ia] != '\0'; ++ia ) {
has = 0;
for ( ib = 0; b[ib] != '\0'; ++ib ) {
if ( a[ia] == b[ib] ) {
has = 1;
break;
}
}
if ( has == 0 )
a[ic++] = a[ia];
}
a[ic] = '\0';
}
[/cpp]
[editline]7th November 2013[/editline]
also is it a good idea to use enumerations for has?
[editline]7th November 2013[/editline]
nevermind, using stdbool.h
[QUOTE=raccoon2112;42791211]I have been learning C and was wondering if there was a better way to write this?
[cpp]// subtract all characters of string b from string a
// todo: maybe make it return third string with members a - b?
void strsub( char a[], char b[] ) {
int ia, ib, ic, has;
ic = 0;
for ( ia = 0; a[ia] != '\0'; ++ia ) {
has = 0;
for ( ib = 0; b[ib] != '\0'; ++ib ) {
if ( a[ia] == b[ib] ) {
has = 1;
break;
}
}
if ( has == 0 )
a[ic++] = a[ia];
}
a[ic] = '\0';
}
[/cpp]
[editline]7th November 2013[/editline]
also is it a good idea to use enumerations for has?
[editline]7th November 2013[/editline]
nevermind, using stdbool.h[/QUOTE]
[url]http://stackoverflow.com/questions/1921539/using-boolean-values-in-c[/url]
According to this using an enum is a good way to do it, but using the 'C99' compiler is better as that has built in boolean support.
I have no experience with C at all, but looks to me like you should be able to use booleans if you're using the latest or at least newer than 'C99', if that exists, compiler.
So I am taking an entry level Java class at my uni and I am having some issues with this project. Basically I got the project to work how the professors wants it, but I only have one class and he wants two, one for user input and output, and one for logic. I don't understand how to do the two classes things, can anyone point out some reference material, or try and explain it to me? I have a book and everything but its still pretty confusing. Here's my code so far (I am sure it is terrible)
[code]
package grades.com;
import java.util.Scanner;
public class Input {
@SuppressWarnings("resource")
public static void main(String[] args) {
while(true) {
System.out.println("Select a Menu Item");
System.out.println("[1]Enter Percentage");
System.out.println("[2]Enter Letter Grade");
System.out.println("[3]Exit");
Scanner scan1 = new Scanner(System.in);
System.out.print("Selection:");
int menuchoice = scan1.nextInt();
if (menuchoice == 3) {
break;
}
switch (menuchoice) {
case 1:
//Scanner scan2 = new Scanner (System.in);
System.out.print("Enter Percentage Grade:");
int P = scan1.nextInt();
int max = 100;
int min = -1;
if (P<=100 && 90<P) {
System.out.println("A");
} else if (P<=89 && 80<=P) {
System.out.println("B");
} else if (P<=79 && 70<=P) {
System.out.println("C");
} else if (P<=69 && 60<=P) {
System.out.println("D");
} else if (P<=59 && 1==P && 0==P) {
System.out.println("F");
} else if (P>max || P<=min){
System.out.println("Invalid Entry");
}
//x = 1;
break;
case 2:
Scanner scan3 = new Scanner (System.in);
System.out.print("Enter Letter Grade:");
String grade = scan3.next();
if (grade.equals("A") || grade.equals("a")) {
System.out.println("100% - 90%");
} if (grade.equals("B") || grade.equals("b")) {
System.out.println("89% - 80%");
} if (grade.equals("C") || grade.equals("c")) {
System.out.println("79% - 70%");
} if (grade.equals("D") || grade.equals("d")) {
System.out.println("69% - 60%");
} if (grade.equals("F") || grade.equals("f")) {
System.out.println("59% - 0%");
} //else {
// System.out.println("Invalid Entry");
//}
//x = 1;
break;
default:
System.out.println("Invalid Choice");
}
}
}
}
[/code]
[editline]7th November 2013[/editline]
Also I know I have a bunch of commented code that I didn't use and its dumb but I was trying different things.
[code]
package grades.com;
import java.util.Scanner;
public class Input{
@SuppressWarnings("resource")
public static void main(String[] args) {
while(true) {
System.out.println("Select a Menu Item");
System.out.println("[1]Enter Percentage");
System.out.println("[2]Enter Letter Grade");
System.out.println("[3]Exit");
Scanner scan1 = new Scanner(System.in);
System.out.print("Selection:");
int menuchoice = scan1.nextInt();
Output.Choice(menuchoice);
}
}
}
package grades.com
import java.util.Scanner;
public class Output {
public static void Choice(int choice){
switch (choice) {
case 1:
Scanner scan2 = new Scanner (System.in);
System.out.print("Enter Percentage Grade:");
int P = scan2.nextInt();
int max = 100;
int min = -1;
if (P<=100 && 90<P) {
System.out.println("A");
} else if (P<=89 && 80<=P) {
System.out.println("B");
} else if (P<=79 && 70<=P) {
System.out.println("C");
} else if (P<=69 && 60<=P) {
System.out.println("D");
} else if (P<=59 && 1==P && 0==P) {
System.out.println("F");
} else if (P>max || P<=min){
System.out.println("Invalid Entry");
}
//x = 1;
break;
case 2:
Scanner scan3 = new Scanner (System.in);
System.out.print("Enter Letter Grade:");
String grade = scan3.next();
if (grade.equals("A") || grade.equals("a")) {
System.out.println("100% - 90%");
} if (grade.equals("B") || grade.equals("b")) {
System.out.println("89% - 80%");
} if (grade.equals("C") || grade.equals("c")) {
System.out.println("79% - 70%");
} if (grade.equals("D") || grade.equals("d")) {
System.out.println("69% - 60%");
} if (grade.equals("F") || grade.equals("f")) {
System.out.println("59% - 0%");
} //else {
// System.out.println("Invalid Entry");
//}
//x = 1;
break;
case 3:
break;
default:
System.out.println("Invalid Choice");
}
}
}
[/code]
These are two separate class files. One named Input and one named Output. Input takes input from the user and Output uses it, duh... You can create methods in Output that can be used in Input by using Output.method(); I'm not too sure if your professor wanted the main method inside the input or output class, but this is the easiest way I could think of for now. Maybe someone else could elaborate and make it better.
I've normally just used all of my code once, because it sucks too much to want to keep it around, and because I don't actually know how to compile libraries (static or dynamic) to reuse them for further projects.
Where is the best way to go about learning how to create and reuse my own libraries?
I've tried looking on MSDN which gave the best explanation, but it is still somewhat confusing to me, mostly because I don't understand why it states that my projects need to be in the same solution.
Doesn't that defeat the purpose of having libraries to contain easily reusable code?
Maybe I'm just thinking about this the wrong way.
[QUOTE=mobrockers;42786683]-code-
To not allow any more lines and characters to the JTextArea you'll have to use a
[url]http://docs.oracle.com/javase/7/docs/api/javax/swing/text/DocumentFilter.html[/url] , didn't particularly feel like writing one as I feel your pain, Swing is a bitch.[/QUOTE]
Thanks a lot, though unfortunately it's not quite what I want. For one, I want to set things as pixel-width. I don't give a damn about the rows / columns - they should be whatever the hell will fit the pixel window.
Here is what I have. Ignore the attributes and classes that aren't defined - they are all correct and ultimately irrelevant to the issue at hand. The DDTextArea simply extends JTextArea and then adds some additional functionality, like the flush and writeLine.
[code] public StreamWatcher(StreamWatcherMaster parent,String name) {
this.parent = parent;
this.name = name;
container = new JPanel();
container.setPreferredSize(new Dimension(250,275));
container.setVisible(true);
container.setBorder(new BevelBorder(BevelBorder.LOWERED));
container.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
JLabel label = new JLabel(name);
c.gridx = 0;
c.gridy = 0;
container.add(label, c);
textArea = new DDTextArea();
textArea.setRows(12);
textArea.setSize(550,50); // No idea what determines the pixel size here versus the container size...
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textArea.setEditable(false);
textArea.setVisible(true);
c.gridx = 0;
c.gridy = 1;
c.fill = GridBagConstraints.VERTICAL;
textArea.flush();
textArea.writeLine("This is a test.");
textArea.writeLine("As is this.");
textArea.flush();
textArea.writeLine("This is post-flush.");
//subcontainer.add(textArea);
container.add(textArea,c);
}[/code]
For one, I have absolutely no idea how the hell the size is determined, but a size of 550 when the panel is 250 gets the ideal length, shown below:
[t]https://dl.dropboxusercontent.com/u/8416055/DeleteMe/Correct.png[/t]
However, as I add more of these objects - all with the exact same dimensions for everything, mind you - the sizes become... well... arbitrary. As seen below.
[t]https://dl.dropboxusercontent.com/u/8416055/DeleteMe/StaticTextAreaSizes.png[/t]
Here is the code that my master frame uses:
[code] public StreamWatcherMaster() {
// Create the master
JFrame master = new JFrame("Dungeon Depths - Watcher");
master.setLayout(new GridLayout(1,0));
master.setPreferredSize(new Dimension(25,275));
master.setVisible(true);
master.setResizable(false);
master.pack();
window = master;
// And then create its children
StreamWatcher watcher = new StreamWatcher(this,"Inventory");
addWatcher(watcher);
watcher = new StreamWatcher(this,"Equipment");
addWatcher(watcher);
watcher = new StreamWatcher(this,"Equipment");
addWatcher(watcher);
watcher = new StreamWatcher(this,"Equipment");
addWatcher(watcher);
watcher = new StreamWatcher(this,"Equipment");
addWatcher(watcher);
}
public void addWatcher(StreamWatcher watcher) {
window.add(watcher.getComponent());
children.add(watcher);
Dimension wsize = watcher.getComponent().getPreferredSize();
Dimension size = window.getPreferredSize();
size.setSize(size.getWidth() + wsize.getWidth(),window.getHeight());
System.out.println(size.getWidth());
window.setPreferredSize(size);
window.setVisible(true);
window.revalidate();
window.pack();
}[/code]
If I use a set-size of columns & rows, then the only way I can get it to be fully-expanded is if I go through and literally fill it all with spaces. However, because characters are of varied width, as soon as I add actual text to these boxes, they expand beyond the size I want them to be.
The goal is to make the boxes be the width and height shown in the first image [b]at all times[/b]. Columns, rows, text-wrap, or text clipping be damned. I do [b]not[/b] want the boxes to [b]ever[/b] be any bigger or any smaller than what I define them to be.
I don't understand why Swing has such an issue with this concept.
[QUOTE=raccoon2112;42791211]I have been learning C and was wondering if there was a better way to write this?
[cpp]// subtract all characters of string b from string a
// todo: maybe make it return third string with members a - b?
void strsub( char a[], char b[] ) {
int ia, ib, ic, has;
ic = 0;
for ( ia = 0; a[ia] != '\0'; ++ia ) {
has = 0;
for ( ib = 0; b[ib] != '\0'; ++ib ) {
if ( a[ia] == b[ib] ) {
has = 1;
break;
}
}
if ( has == 0 )
a[ic++] = a[ia];
}
a[ic] = '\0';
}
[/cpp][/QUOTE]
I would prefer pointers ("iterators" if you're familiar with C++-terminology) instead of keeping indices.
And then I would use strpbrk to look for occourences of characters in the souce-string.
You should also be able to take a const b, since you don't modify it.
[editline]8th November 2013[/editline]
[QUOTE=Dragonflare;42795942]I've normally just used all of my code once, because it sucks too much to want to keep it around, and because I don't actually know how to compile libraries (static or dynamic) to reuse them for further projects.
Where is the best way to go about learning how to create and reuse my own libraries?
I've tried looking on MSDN which gave the best explanation, but it is still somewhat confusing to me, mostly because I don't understand why it states that my projects need to be in the same solution.
Doesn't that defeat the purpose of having libraries to contain easily reusable code?
Maybe I'm just thinking about this the wrong way.[/QUOTE]
I'll be guessing that you're using Visual Studio in some sentences.
If it's just a few files, especially if you just want to keep the functionality for your own projects, I think making a library just complicates things.
I think multiple projects in a solution are not necessarily for libraries accompanying an executable, but more for projects having a close relationship.
For example you might provide multiple interfaces for some program (CLI-based and a Qt-GUI for example), then you would keep those projects in the same solution. Or for a game, you might have separate Client- and Server-projects, but also keep them in the same solution.
You probably want a statically linked library (.lib in Windows) and not a dynamically linked library (.dll in Windows).
You link against the statically linked library when building the project and that's it. For a dynamically linked library you only link a stub when building and when starting the application, it searches for the .dll in various places (like system32 and the CWD) and links it when starting up. This has the advantage of being able to exchange the library for something ABI compatible, but you can imagine this has again more complexity to it.
You don't really need to do much in order to write code for a statically linked library. You just don't include the source-files in the project and the library won't have a main-function. You only point to the include-files via a build-setting (iirc "Additional include directories" in the C/C++-section of the project properties somewhere) and link against the libraries ("Additional libraries" or something in the Linker-section).
The Project-creation wizard probably has a selection to create a statically linked library.
[QUOTE=Larikang;42787223]This is a delicious comp sci problem. It can be solved using a [URL="http://en.wikipedia.org/wiki/Disjoint-set_data_structure"]disjoint-set[/URL] data structure. I don't know Lua so I'll just tell you the basic algorithm.
1. Create a set for each object. The goal is to union sets until there are 16 or fewer.
2. For each pair of objects x,y iterate over all ignore lists and check "Does it ignore x and y or does it ignore neither?"
3. If this conditions holds for all ignore lists, union x's set and y's set.
4. Now all remaining disjoint sets are your collision groups.
This is pretty inefficient (something like O(N^3)) but since it's a one-time job I don't think it's that bad.
How the algorithm works:
For each pair of objects, the conditions checks "Is x ignored if and only if y is ignored?" The nice thing about this relationship is that it is transitive e.g. if we know that "x is ignored if and only if y is ignored and y is ignored if and only if z is ignored" then we also know "x is ignored if and only if z is ignored". If we group ignored objects together using this relation, then just by making sure the collision groups works with all [I]pairs[/I] of elements, we are guaranteed that they will work with all [I]subsets[/I] of elements. The disjoint-set data structure is perfect for representing transitive relationships because you can just say "union x's set and y's set" and it will automatically bring along all of the elements that x and y are transitively related to.
:eng101:[/QUOTE]
Someone else arrived at the same algorithm (I think, I haven't actually tested yours with all my test cases to see if it works, but it looks pretty similar, with a few representational differences) with me yesterday, but thanks for helping too. It was quite an interesting problem to think about! [URL]http://facepunch.com/showthread.php?t=1260790&p=42797210&viewfull=1#post42797210[/URL]
[QUOTE=Dragonflare;42795942]I've normally just used all of my code once, because it sucks too much to want to keep it around, and because I don't actually know how to compile libraries (static or dynamic) to reuse them for further projects.
Where is the best way to go about learning how to create and reuse my own libraries?
I've tried looking on MSDN which gave the best explanation, but it is still somewhat confusing to me, mostly because I don't understand why it states that my projects need to be in the same solution.
Doesn't that defeat the purpose of having libraries to contain easily reusable code?
Maybe I'm just thinking about this the wrong way.[/QUOTE]
If you want to keep the projects around as source (for easy modifications), you can copy the project directories around.
It's also possible to add the same project to more than one solution but I wouldn't recommend that unless the solutions are really one project.
The best way to do it is probably with DVCS subrepositories. You can then copy your projects to different solutions but still keep them in sync relatively easily.
If you use relative paths to a flat remote (like Github or Bitbucket), you can pull/update normally to clone your solution with all subrepos, pushing the main repo should push them too.
If you don't want to modify the source just copying the library somewhere into the VCS and adding it as reference should be enough. With C++ you need the header files too, afaik.
[QUOTE=Gmod4ever;42796180]Thanks a lot, though unfortunately it's not quite what I want. For one, I want to set things as pixel-width. I don't give a damn about the rows / columns - they should be whatever the hell will fit the pixel window.
Here is what I have. Ignore the attributes and classes that aren't defined - they are all correct and ultimately irrelevant to the issue at hand. The DDTextArea simply extends JTextArea and then adds some additional functionality, like the flush and writeLine.
If I use a set-size of columns & rows, then the only way I can get it to be fully-expanded is if I go through and literally fill it all with spaces. However, because characters are of varied width, as soon as I add actual text to these boxes, they expand beyond the size I want them to be.
The goal is to make the boxes be the width and height shown in the first image [b]at all times[/b]. Columns, rows, text-wrap, or text clipping be damned. I do [b]not[/b] want the boxes to [b]ever[/b] be any bigger or any smaller than what I define them to be.
I don't understand why Swing has such an issue with this concept.[/QUOTE]
JTextArea sizes are defined by the amount of rows and characters it can contain, that's it. setSize shouldn't and usually doesn't do anything, it's probably inherited from a superclass but shouldn't be used. I couldn't tell you why, it's just how it's designed, no good way around it. You could theoretically get around all this by setting the minimum, maximum and preferred size to the exact same thing, it should then be unable to be re-sized at all, this is however heavily discouraged as it's simply hideous and wrong.
I see you're setting the TextArea's to not be editable, I assume this means you control what gets put into them. If you look at my example you'll see all boxes are the exact same height and width, using this and the fact that you yourself determine the text that gets displayed, it should be fairly simple to get identical boxes that don't have weird spacing issues (as you control what gets put into them, and can ensure this is never more than can fit). I also suggest you look into the DocumentFilter like I said, you can use it to ensure no more characters or lines can be added to the TextArea than fit in the initial size. What you want, pixel-set width and height simply isn't how TextArea's work, it's best to get over this right away and start working with the DocumentFilter and rows / characters.
[editline]8th November 2013[/editline]
[QUOTE=Gubbygub;42794312]So I am taking an entry level Java class at my uni and I am having some issues with this project. Basically I got the project to work how the professors wants it, but I only have one class and he wants two, one for user input and output, and one for logic. I don't understand how to do the two classes things, can anyone point out some reference material, or try and explain it to me? I have a book and everything but its still pretty confusing. Here's my code so far (I am sure it is terrible)
[/QUOTE]
Your professor probably wants you to get started on using Objects. An Object is a representation of a real world thing. For example for this assignment you would have a Class called Grade, from which you can make a Grade Object. In the Grade class you would have two methods called for example "getGradeLetter()" and "getPercentageLetter()", and a variable called "grade. In these methods you would have your business logic for calculating either the Grade letter or Grade percentage, so this part of your code, but instead of printing the result, you would set the corresponding variable to the result:
[cpp]
public String getGradeLetter() {
if (percentageGrade <= 100 && 90< percentageGrade ) {
return "A";
}
// And so on
}
[/cpp]
[cpp]
public String getGradePercentage() {
if (letterGrade.equals("A") || letterGrade.equals("a")) {
return "100% - 90%";
}
// And so on
}
[/cpp]
If this isn't enough to get you started, let us know.
[QUOTE=mobrockers;42798871]JTextArea sizes are defined by the amount of rows and characters it can contain, that's it. setSize shouldn't and usually doesn't do anything, it's probably inherited from a superclass but shouldn't be used. I couldn't tell you why, it's just how it's designed, no good way around it. You could theoretically get around all this by setting the minimum, maximum and preferred size to the exact same thing, it should then be unable to be re-sized at all, this is however heavily discouraged as it's simply hideous and wrong.
I see you're setting the TextArea's to not be editable, I assume this means you control what gets put into them. If you look at my example you'll see all boxes are the exact same height and width, using this and the fact that you yourself determine the text that gets displayed, it should be fairly simple to get identical boxes that don't have weird spacing issues (as you control what gets put into them, and can ensure this is never more than can fit). I also suggest you look into the DocumentFilter like I said, you can use it to ensure no more characters or lines can be added to the TextArea than fit in the initial size. What you want, pixel-set width and height simply isn't how TextArea's work, it's best to get over this right away and start working with the DocumentFilter and rows / characters.
[editline]8th November 2013[/editline]
Your professor probably wants you to get started on using Objects. An Object is a representation of a real world thing. For example for this assignment you would have a Class called Grade, from which you can make a Grade Object. In the Grade class you would have two methods called for example "getGradeLetter()" and "getPercentageLetter()", and a variable called "grade. In these methods you would have your business logic for calculating either the Grade letter or Grade percentage, so this part of your code, but instead of printing the result, you would set the corresponding variable to the result:
[cpp]
public String getGradeLetter() {
if (percentageGrade <= 100 && 90< percentageGrade ) {
return "A";
}
// And so on
}
[/cpp]
[cpp]
public String getGradePercentage() {
if (letterGrade.equals("A") || letterGrade.equals("a")) {
return "100% - 90%";
}
// And so on
}
[/cpp]
If this isn't enough to get you started, let us know.[/QUOTE]
Alright, thank you for confirming my suspicions.
And while I control what text goes into the boxes, that text is variable.
I guess I'll just built my own damn UI element to do what I need, using a bunch of JLabels and a JPanel. At least JPanels I can control the size of, and JLabels I can control the justification and such.
[QUOTE=Gmod4ever;42799132]Alright, thank you for confirming my suspicions.
And while I control what text goes into the boxes, that text is variable.
I guess I'll just built my own damn UI element to do what I need, using a bunch of JLabels and a JPanel. At least JPanels I can control the size of, and JLabels I can control the justification and such.[/QUOTE]
You can check the input before adding it to the textarea (which you should do anyways, because otherwise how would you handle text that's too large for your textarea area?).
Using Labels is probably a better idea anyways as TextArea's aren't exactly ideal for anything but text input.
So I've been trying out some stuff in SDL2.0. But one thing i cannot seem to find out is how to use matrices to transform textures/surfaces.
I know it's possible to just move, rotate and scale separately. But that's impractical once you start using view matrices or parent/child objects. Multiplying matrices is just much easier.
Is it even possible with SDL alone or do i have to use OpenGL for that? Though, i'd prefer a way without it since i don't know any OpenGL.
I'm pretty stumped here. I'm using JOGL and trying to use GLSL + VBOs.
Here's what the code does without VBOs (using triangle strips and calls to glNormal3f and glVertex3f, light is at (0,0,1)):
[IMG]https://dl.dropboxusercontent.com/u/11517902/render1.png[/IMG]
Everything looks fine and dandy...
Then I switch over to using VBOs and my toon shader
[IMG]https://dl.dropboxusercontent.com/u/11517902/render2.png[/IMG]
Sooo I can't for the life of me figure out why the lighting is off by what looks to be exactly 90 degrees (note the sphere on the bottom still has the right lighting because it doesn't use the shader). Any ideas? I can post more pictures or some source snippets if need be
Sorry, you need to Log In to post a reply to this thread.