Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,151,305 members, 7,811,902 topics. Date: Sunday, 28 April 2024 at 10:58 PM

Help On Java - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Help On Java (9566 Views)

Pls Help Me With Ebooks On Java,d Price For The Book Is High And Am Still A Teen / Anyone With Help On Java App Creation? / [Help Request] Help On Java download and Installation Oo! (2) (3) (4)

(1) (2) (3) (4) (5) (Reply) (Go Down)

Help On Java by lolade123: 10:17am On Mar 30, 2011
Hello guys ,i want anyone to help me with the clue to this java problem.
i want to print five digit input from a user to diplay as "1 2 3 4 5" meaning three spaces between the digits.and also alert if the input is less or more than 5 digits.
Thank
Re: Help On Java by Otuabaroku: 3:45pm On Mar 30, 2011
okay, let me try:

class Datamanuplate{ // the class to execute your task

public static void printspace(int number) // method to print empty space
{
for(int i=0;i<number;i++)
{
System.out.print(" "wink;
}
}

public static void main(String args[]) // main method
{
if(args.length!=5)
{
System.out.println("The input data must be 5"wink; //if the user entered less than 5 inputs, prompt him to enter 5 inputs
}
else
{
System.out.print("'"wink; // execute the task
for(int i=0;i<args.length;i++)
{
System.out.print(args[i]);
printspace(3);
}
System.out.print("'"wink;
}
}
}
Re: Help On Java by segsalerty(m): 7:42am On Mar 31, 2011
import java.util.Scanner;
public class Lolade123{
public static void main(String []args){
Scanner s = new Scanner(System.in);
System.out.println("i want to print five digit input from a user to diplay meaning three spaces between the digits.and also alert if the input is less or more than 5 digits"wink;
System.out.println("Chikenna : Oya, Enter am !"wink;
try{
int digits = s.nextInt();
String val = String.valueOf(digits);
if(val.length() > 5 || val.length() < 5){
System.out.println("Digit of numbers u provided not valid ooo !"wink;
}
else{
System.out.printf("%s %s %s %s %s", val.charAt(0), val.charAt(1), val.charAt(2), val.charAt(3), val.charAt(4));
}
}
catch(Exception e){
System.err.println("Exception in imput happen ooo ! Cause ? : " + e.getMessage());
}
}
}


sorry say i no put comment, want to test if u go understand am without comment ! wink
Note: there are 1 thousand and 1 ways of writing a program to solve a problem , my code isnt the solution coz u can write a beta one!
Re: Help On Java by Otuabaroku: 9:28am On Mar 31, 2011
segsalerty:

import java.util.Scanner;
public class Lolade123{
public static void main(String []args){
Scanner s = new Scanner(System.in);
System.out.println("i want to print five digit input from a user to diplay meaning three spaces between the digits.and also alert if the input is less or more than 5 digits"wink;
System.out.println("Chikenna : Oya, Enter am !"wink;
try{
int digits = s.nextInt();
String val = String.valueOf(digits);
if(val.length() > 5 || val.length() < 5){
System.out.println("Digit of numbers u provided not valid ooo !"wink;
}
else{
System.out.printf("%s %s %s %s %s", val.charAt(0), val.charAt(1), val.charAt(2), val.charAt(3), val.charAt(4));
}
}
catch(Exception e){
System.err.println("Exception in imput happen ooo ! Cause ? : " + e.getMessage());
}
}
}


sorry say i no put comment, want to test if u go understand am without comment ! wink
Note: there are 1 thousand and 1 ways of writing a program to solve a problem , my code isnt the solution coz u can write a beta one!
When I saw your code I checked the program requirement again, I actually got it run as I provided solution for five input data ie five numbers and print them out by spacing them into 3 equal space. Your solution is right, welldone and keep it up.
Re: Help On Java by segsalerty(m): 10:57am On Mar 31, 2011
Oh, Okay, thanks. I appreciate! Hope the poster finds it useful.
Re: Help On Java by lolade123: 11:24pm On Mar 31, 2011
I swear by God Almighty,i love this site,i appreciate every contributions,it really helpful,i tried the google and alot of java docs but nairaland helped me .I love you guys so much.Sincerely have improved in my class cos am on top presently,i was d guy who had probs on javascript but now am cool with it.
I just hope my classmate dont get to know Nairaland grin,we are the best
Thanks Seun and all others wink.
Re: Help On Java by csharpjava(m): 3:29pm On Apr 01, 2011
I just hope my classmate dont get to know Nairaland

I will recommend that you tell all your classmates about Nairaland, the more people are knowledgeable the better it will be for our society.
Re: Help On Java by segsalerty(m): 9:33pm On Apr 01, 2011
csharpjava:

I will recommend that you tell all your classmates about Nairaland, the more people are knowledgeable the better it will be for our society.

true Talk ! smiley
Re: Help On Java by Dolemite(f): 3:32am On Apr 02, 2011
Seg you're pretty good with Java, maybe you and I could work together on this program I'm thinking of. . .not now though, watch this space.
Re: Help On Java by segsalerty(m): 4:35am On Apr 02, 2011
Dolemite:

Seg you're pretty good with Java, maybe you and I could work together on this program I'm thinking of. . .not now though, watch this space.

cheesy Ha, am just a baby newbie, u re making my head swell already! anywayz, anytime !
Re: Help On Java by Otuabaroku: 10:12am On Apr 02, 2011
Hi segsalerty , please i have a question for you. Do you know how to package an application developed in java that has Mysql as backend database so that it can be easily distributable? Thank you in anticipation of your response.
Re: Help On Java by segsalerty(m): 10:12pm On Apr 02, 2011
Yah Yah Yah !
Read about "MySQL-MXJ" --- with this library by MySQL, u can package ur java application and at launch u can tell ur app to create a MySQL database 'PROCESS' and u can create new database, config / create and access tables data and so on both on LOCALHOST and REMOTELY grin
The remote accessibility of this library implementation makes java db programming so freeking sweet smiley

Another one is "MySQL-je" --- is an open source library that a programmer developed with the dynamic library ".dll" of MySQL engine to embed MySQL db with ur app and then do same as real "MySQL" but it currently doesnt allow REMOTE ACCESS sad

if u cant use any of these two, Better u use java db that is default db library that comes with ur jdk

Hope u find what u need? wink wink wink wink
Re: Help On Java by Otuabaroku: 11:31am On Apr 03, 2011
segsalerty:

Yah Yah Yah !
Read about "MySQL-MXJ" --- with this library by MySQL, u can package your java application and at launch u can tell your app to create a MySQL database 'PROCESS' and u can create new database, config / create and access tables data and so on both on LOCALHOST and REMOTELY grin
The remote accessibility of this library implementation makes java db programming so freeking sweet smiley

Another one is "MySQL-je" --- is an open source library that a programmer developed with the dynamic library ".dll" of MySQL engine to embed MySQL db with your app and then do same as real "MySQL" but it currently doesnt allow REMOTE ACCESS sad

if u cant use any of these two, Better u use java db that is default db library that comes with your jdk

Hope u find what u need? wink wink wink wink
Thanks ,but it was not helpful enough. The stage I am with what I want to achieve is that I tried creating a jar file of the application I developed with Mysql as the database by copying both the table and mysql-connector-java-5.1.12-bin.jar into library according what I read on line on how to go about it. After creating the jar file of the entire application, I found out that it was not connecting to the table of database when the application is run;that is the challenge I am facing currently.Based on the info I have provided now, could you advise me on how to go about it to get it working.Thank you for your response.
Re: Help On Java by segsalerty(m): 2:56pm On Apr 03, 2011
smiley smiley what i explainded earlier answered ur question.
In summary , the best solution for this ur problem is using Microsoft-Access DB or JavaDB or probably make use of a text file !
Here are my reasons ****************
MySQL is a program, it needs to be launched/executed before u can access its Resources/Tables by providing its "Host Address"
there is no how u can extract tables from this MYSQL without SQL query wink wink wink

Abi, how was ur URL string that u specified in ur java code when u were using ur MySQL driver? what was ur host name ?

my previous post are the only 2 ways of using MySQL database packed with ur application setup, else, the person will install MySQL separateley.

best bet for u now is using Microsoft Access or JavaDB

hope this helps
Re: Help On Java by Otuabaroku: 6:09pm On Apr 03, 2011
segsalerty thank you.
Re: Help On Java by segsalerty(m): 10:54pm On Apr 03, 2011
grin u are so much welcome ,
Hope problem solved?  wink wink

If u want to see how an Embedded MySQL works, u can download this 93MB file
Its a E-Super Market Generic Solutions that i developed implementing the MySQL-mxj Library.
see how it works and how its driven, if u have any question, free to ask

download link is :

http://www.sendspace.com/file/qppvdi
Re: Help On Java by Otuabaroku: 9:57am On Apr 04, 2011
Hi Segsalerty,I have downloaded the software but could not run it because of the admin password. How does it work and what is the default password? I must commend you for your good works. Keep it up.
Re: Help On Java by segsalerty(m): 12:08pm On Apr 04, 2011
Sorry,, I forgot to drop the default password.

admin

its case sensitive,
U see how the software created and configured MySql when u launched it? Eachtime the program is running. The app MySql is turned on and when the app exit, The MySql is killed !

Login, register the software, setup ur supermaket to ur taste, add items enough items and add remote users. And wait till tonight when am gonna send the link to the client UI
Re: Help On Java by codejava: 5:57pm On Apr 04, 2011
can somebody help me to fine tone this code, i set it as string but i want to cast string to double, when storing those string:

String txt = null; String line = null;
ApplicationData app = new ApplicationData();
String[] splits = txt.split("\t"wink;
String amt = "0";
if (length > 3 && !splits[3].equals(""wink) {
amt = splits[3].trim();
amt = splits[3].replace('-',',').replace('"',',').replace('(',',').replace(')',',');
String actSplit[] = amt.split(","wink;
for(int z = 0; z < actSplit.length; z++){
      amount += actSplit[z];
    }
}
app.setAmount(amount);


my main concern is that, I want the values which i uploaded to return back in double. I think i can cast using Double.valueOf(amt); but is not working.
Kindly help pls
Re: Help On Java by Otuabaroku: 7:46pm On Apr 04, 2011
codejava:

can somebody help me to fine tone this code, i set it as string but i want to cast string to double, when storing those string:


my main concern is that, I want the values which i uploaded to return back in double. I think i can cast using Double.valueOf(amt); but is not working.
Kindly help pls

You can use the method: Double.parseDouble(amt) to convert the string to double.
Re: Help On Java by segsalerty(m): 12:00am On Apr 05, 2011
codejava:

can somebody help me to fine tone this code, i set it as string but i want to cast string to double, when storing those string:

String txt = null; String line = null;
ApplicationData app = new ApplicationData();
String[] splits = txt.split("\t"wink;
String amt = "0";
if (length > 3 && !splits[3].equals(""wink) {
amt = splits[3].trim();
amt = splits[3].replace('-',',').replace('"',',').replace('(',',').replace(')',',');
String actSplit[] = amt.split(","wink;
for(int z = 0; z < actSplit.length; z++){
      amount += actSplit[z];
    }
}
app.setAmount(amount);


my main concern is that, I want the values which i uploaded to return back in double. I think i can cast using Double.valueOf(amt); but is not working.
Kindly help pls

Sorry bro, ur code is so much freaking difficult for me to understand , but, i guess u are trying to convert a Text(String) to an amount value rep as double val (i.e 300.00 and 450.89) right ? if thats it, this is something i cooked up sometimes ago i needed smth like this solution, i just modified it for ur own case wink, hope it will help u by modify what i did then to what u want to do

///////////////////////code starts here, just copy past the class and compile and run like this "java Test 780" or whatever value u put as first arg
import java.text.DecimalFormat;

public class Test{

public static void main(String []args){
System.out.println("This is the Decimal Value of the input String (GOOD AS IT RETURNS STRING COZ double rounds any .0) is : " + formatValueTo_twoDecimalPlaceString(args[0]));
System.out.println("This is kinda useless but for u to see why the method up is preferred : " + formatValueTo_twoDecimalPlaceDouble(args[0]));
}

public static String formatValueTo_twoDecimalPlaceString(String s){
String val = "";
DecimalFormat df = new DecimalFormat("##############0.00"wink;
try{
val = df.format(Double.valueOf(s));
return val;
}
catch(Exception Ne){
return "";
}
}

public static Double formatValueTo_twoDecimalPlaceDouble(String s){
double result = 0.0;
DecimalFormat df = new DecimalFormat("##############0.00"wink;
try{
result = Double.valueOf(df.format(Double.valueOf(s)));
return result;
}
catch(Exception Ne){
return 0.0;
}
}
}
///////////////////////////////////////
sorry that i dont like putting comments inside small java code wink wink wink
i believe u will grab the concept and helps u solve ur problem
Wish u Happy Coding ! cheesy
Re: Help On Java by codejava: 7:08am On Apr 05, 2011
Thanks segsalerty, I looked at your code is ok but i still have a challenge, 'am populating MySql db from text file. I quite can upload the data using buffer, but I made the amount column to be string, so i just want the module of the amount to be converted back to double rather than doing it manually b4 uploading. I still find it difficult to modified or apply your code.
Re: Help On Java by Dolemite(f): 7:16am On Apr 05, 2011
I have a simple problem, I have a code that requires the user to input Y/N at regular intervals

public static void main(String[] args){
. , , . . . . . . . . . . .
System.out.println("continue? Y/N"wink;
response=input.next().charAt(0);
//does a calc
System.out.println("continue? Y/N"wink;
response=input.next().charAt(0);
//does a calc
}
For now the response is useless because even if the user enters n it doesn't quit, its currently in a do while loop. . .
Re: Help On Java by segsalerty(m): 7:24am On Apr 05, 2011
sorry guyz, let me sharply post the link to the Client UI for Otuabaroku

http://www.sendspace.com/file/uk4bs0

Pls, download the client of the Suermarket server from here , Launch the one that has suffic '_localhost' if ur computer isnt connected to the LAN, else , Launch '_LAN' if ur sys is connected to a WLAN or LAN ,
Launch Server before the client , Create remote server before launching Client
Send Critics to my email segsalerty@yahoo.com, it will be highly appreciated wink

I just woke up, got Class by 10am , i wan sharply go do some necessary stuffs and come and attend to the questions on wall.
Please hold grin grin grin grin grin
Re: Help On Java by segsalerty(m): 7:41am On Apr 05, 2011
@CodeJava
This function :
public static String formatValueTo_twoDecimalPlaceString(String s){
String val = "";
DecimalFormat df = new DecimalFormat("##############0.00"wink;
try{
val = df.format(Double.valueOf(s));
return val;
}
catch(Exception Ne){
return "";
}
}

just add it to ur class and use it wherever, the above code isnt add to implement and its okay to put String rep of a double value into ur Ammount Colum(VARCHAR datatype)
and if u want to turn it back to double for arithmetic calculations ,
just say double.parseDouble(****data from database ***);
hope this helps
Re: Help On Java by Dolemite(f): 7:45am On Apr 05, 2011
What about my code baby?
Re: Help On Java by segsalerty(m): 7:49am On Apr 05, 2011
@dolemite
I will like to see ur code , but, anyways, i can guess what the problem might be,
*******
after assigning 'response' variable from user , just try tune this into ur code

do{
///ur do

response = input.next().charAt(0);
//say
if(response == $$$your NO value$$$){
break;
}
}//end of do
while(blah blah blah);

hope this works
your break can exit from the loop as soon as respose = n
Re: Help On Java by lolade123: 10:45pm On Apr 05, 2011
Hello guys,am so happy am advancing in Java with help from everyone,but am having probs with this simple one.
am writing a program to input five digits from user,diplays the number of negative,positive and zero interger values.Thanks men
Re: Help On Java by segsalerty(m): 10:58pm On Apr 05, 2011
wink wink wink wink wink wink u should have tried putting sample inputs and sample outsputs coz my ENGLISH is bad tongue tongue tongue
That grammer is tough for me,
u mean input like
3. -4. 0. 5, 0
output should then be
1 negative value
2 positive value
2 zero value

abi ?

or output be :
Negative Values : -4
Positive Values : 3, 5
Zero Value : 0, 0

abi ? wink wink
Re: Help On Java by lolade123: 11:09pm On Apr 05, 2011
segsalerty:

wink wink wink wink wink wink u should have tried putting sample inputs and sample outsputs coz my ENGLISH is bad tongue tongue tongue
That grammer is tough for me,
u mean input like
3. -4. 0. 5, 0
output should then be
1 negative value
2 positive value
2 zero value

abi ?

or output be :
Negative Values : -4
Positive Values : 3, 5
Zero Value : 0, 0

abi ? wink wink
yeah the second one is prefered and it should count the numbers like 2 +numbers,3 -numbers and 1zero,thanks man.
Re: Help On Java by segsalerty(m): 11:41pm On Apr 05, 2011
lolade123:

Hello guys,am so happy am advancing in Java with help from everyone
wink wink wink wink
are u sure about that ?
here is ur solution

****************************************
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;

public class Test{
private List<Integer> listOfNumbers;
private Scanner scan;
private int negativeCount = 0;
private int positiveCount = 0;
private int zeroCount = 0;

private String negativeString = "Negative Numbers are : ";
private String positiveString = "Positive Numbers are : ";
private String zeroString = "Zero Numbers are : ";

public Test(){
listOfNumbers = new ArrayList<Integer>();
scan = new Scanner(System.in);
collectTheInputs();
process_printOutPut();
}

private void collectTheInputs(){
System.out.println("Enter each Digits u want to key in and press Enter after each : \t GoodLuck lolade123 !"wink;
for(int i = 0; i < 5; i++){
try{
listOfNumbers.add(scan.nextInt());
}
catch(Exception e){
listOfNumbers.add(0); //since the value entered cannot be classified as an integer, so, make it 0 as default
}
}
}

private void process_printOutPut(){
for(int x : listOfNumbers){
if(x > 0){
positiveString += String.valueOf(x) + ", ";
positiveCount++;
}
else if(x < 0){
negativeString += String.valueOf(x) + ", ";
negativeCount++;
}
else{
zeroString += String.valueOf(x) + ", ";
zeroCount++;
}
}
//after the loop
System.out.println(positiveString + "\t and COUNTS to : " + positiveCount);
System.out.println(negativeString + "\t and COUNTS to : " + negativeCount);
System.out.println(zeroString + "\t and COUNTS to : " + zeroCount);
}

public static void main(String []args){
new Test();
}

}
**************
hope it solves ur problem
Re: Help On Java by Dolemite(f): 7:47am On Apr 06, 2011
lolade123:

yeah the second one is prefered and it should count the numbers like 2 +numbers,3 -numbers and 1zero,thanks man.
You know you're not really advancing if he keeps spoon feeding you code like this. . .

(1) (2) (3) (4) (5) (Reply)

Programmers, How Do You Cope With Generator Noise In Your Area? / Female Programmers Stand Up And Be Counted / What Is Xvideoservicethief?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 68
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.