1

Java Thread (Help,discussion,tips+pointers, code sharing)

DusteroftheCentury's Avatar DusteroftheCentury12/26/11 1:01 am
1 emeralds 200 7
12/26/2011 10:40 pm
DusteroftheCentury's Avatar DusteroftheCentury
Hello I think we need a thread for discussion about Java. Here we can share code, talk about projects, ask questions, answer questions, and discuss Java in general.
I am not particularly knowlegable in Java myself but I hope we can get some experts
like SourC00kie to contribute. Begin discussion!
Posted by DusteroftheCentury's Avatar
DusteroftheCentury
Level 16 : Journeyman Skinner
25

Create an account or sign in to comment.

7

1
12/26/2011 10:40 pm
Level 16 : Journeyman Skinner
DusteroftheCentury
DusteroftheCentury's Avatar
If anyone where to help you we would need the code the error is from.
1
12/26/2011 9:41 pm
Level 7 : Apprentice Crafter
Jackanation
Jackanation's Avatar
10:09 PM [SEVERE] java.net.SocketException: Socket closed
10:09 PM [INFO] Connection reset
10:09 PM [SEVERE] at java.net.SocketOutputStream.socketWrite(Unknown Source)
10:09 PM [SEVERE] at java.net.SocketOutputStream.write(Unknown Source)
10:09 PM [SEVERE] at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
10:09 PM [SEVERE] at java.io.BufferedOutputStream.flush(Unknown Source)
10:09 PM [SEVERE] at java.io.DataOutputStream.flush(Unknown Source)
10:09 PM [SEVERE] at net.minecraft.server.NetworkWriterThread.run(Sourc eFile:104)

HOW DO I FIX THIS RRRRBLRBLRLLBRLBLLLRBLBLRBL.
1
12/26/2011 9:36 pm
Level 40 : Master Droid
number1_Master
number1_Master's Avatar
not a java wizard, but i know some
i like this thread
1
12/26/2011 9:16 pm
Level 16 : Journeyman Skinner
DusteroftheCentury
DusteroftheCentury's Avatar
Are there any Java wizards who can help?
1
12/26/2011 2:22 pm
Level 16 : Journeyman Skinner
DusteroftheCentury
DusteroftheCentury's Avatar
Could you explain this some more? Does this go in a new class? Do I keep the code in AccountDemo.java? For the [...] parts do I put the same code every time? Which code?
1
12/26/2011 2:00 am
Level 7 : Apprentice Pixel Puncher
SvedCo
SvedCo's Avatar
DusteroftheCenturybump!

Here ill start us off with something:
//AccountDemo.java//
public class AccountDemo
{
public static void main(String args[])

{
//Creates a blank account
Account my_account = new Account();

//Sets starting Account balance
my_account.deposit(1000.00);

//Tells it to display the starting balance
System.out.println ("Credits: " +
my_account.getbalance());

//Tells it to take away money
my_account.withdraw(344.00);

//Tells it to display the end balance
System.out.println ("Remaining Credits " +
my_account.getbalance());
}
}


Where it says "my_account.withdraw(Numbers)" How do I change that value while in the program without changing the code?


You have to make it accept a string from your keyboard:

java.io*
[...]
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
[...]
System.out.println ("Current balance: " + my_account.getbalance());
my_account.withdraw = console.readLine("How much would you like to withdraw?");
System.out.println ("You are withdrawing " + my_account.withdraw() + ".");
System.out.println ("Updated balance: " + my_account.getbalance());
[...]

My Java is a little rusty, but that's the basics. Where "[...]" is would be the rest of your code.

*waits for someone to correct my code*
1
12/26/2011 1:21 am
Level 16 : Journeyman Skinner
DusteroftheCentury
DusteroftheCentury's Avatar
bump!

Here ill start us off with something:
//AccountDemo.java//
public class AccountDemo
{
public static void main(String args[])

{
//Creates a blank account
Account my_account = new Account();

//Sets starting Account balance
my_account.deposit(1000.00);

//Tells it to display the starting balance
System.out.println ("Credits: " +
my_account.getbalance());

//Tells it to take away money
my_account.withdraw(344.00);

//Tells it to display the end balance
System.out.println ("Remaining Credits " +
my_account.getbalance());
}
}


//Account.java//
public class Account
{
protected double balance;

public Account( double amount )
{
balance = amount;
}
public Account()
{
balance = 0.0;
}

public void deposit( double amount )
{
balance += amount;
}

public double withdraw( double amount )
{

if (balance >= amount)
{
balance -= amount;
return amount;
}
else
return 0.0;

}

public double getbalance()
{
return balance;
}
}


Where it says "my_account.withdraw(Numbers)" How do I change that value while in the program without changing the code?
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome