Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 26th, 2009, 4:25 PM   #1
joshka89
Programmer
 
Join Date: Feb 2009
Posts: 50
Rep Power: 9 joshka89 is on a distinguished road
Exclamation Making java split up a code

ok i tried this program and it was just... FAIL lol

java should read from a code with 12 digits and take certain parts of the code and turn them into legible text depending on their values


E.G.

MMMCCCCRRRFI

where each group of digits is defined as follows:
MMM - Manufacturer Group Code
CCCC - Capacity in gigabytes
RRR - Rotational speed in RPM/100
F - Form factor code
I - Interface Code


the user inputs the long code and the java program should put out the code
then the manufacturer based on the code
(100-199 would be Seagate or something)
then it puts out the capacity
then the speed (the two digit part times 100)
F part 1-5 where 1 is 5.25 inch and 7 is something else
I code 1 - 7 where 1 is PATA and 7 is IEEE 1394 Fire Wire


So basically the program reads the sections of code, deciphers them and put out a string based on them.

I tried an array and head it associate each part of the code with part of the array

it was so plagued with errors i restarted but don't know what to do now
joshka89 is offline   Reply With Quote
Old Feb 26th, 2009, 4:26 PM   #2
Arla
Expert Programmer
 
Arla's Avatar
 
Join Date: Mar 2005
Posts: 777
Rep Power: 13 Arla is on a distinguished road
Re: Making java split up a code

Substring?
__________________
I can remember, back in '22
They changed the law - came knocking on the door
In that same moment, the broadband seemed to go..
Phones all dead. Gone dizzy in the head..
Arla is offline   Reply With Quote
Old Feb 27th, 2009, 12:18 AM   #3
silent1mezzo
Hobbyist Programmer
 
Join Date: Aug 2007
Location: Mississauga ON
Posts: 125
Rep Power: 11 silent1mezzo is on a distinguished road
Re: Making java split up a code

Ya, if its going to be that exact number of characters each time you could substring

manuf = mainstring.substring(0, 2);
capacity = mainstring.substring(3, 6);
...

That would work if the main string is always a given number of characters for each category
silent1mezzo is offline   Reply With Quote
Old Feb 27th, 2009, 1:49 PM   #4
exception
Software & Web Developer
 
exception's Avatar
 
Join Date: Oct 2008
Location: Philippines
Posts: 173
Rep Power: 10 exception is on a distinguished road
Send a message via Yahoo to exception
Re: Making java split up a code

manufacturer = input.substring(input.indexOf("M"), input.LastIndexOf("M")+1)
__________________
|Knowledge alone is not POWER, Applied knowledge is POWER.
exception is offline   Reply With Quote
Old Feb 28th, 2009, 4:25 AM   #5
joshka89
Programmer
 
Join Date: Feb 2009
Posts: 50
Rep Power: 9 joshka89 is on a distinguished road
Re: Making java split up a code

ok so that should work in theory but i'm not certain what i would declare manuf, capacity, speed, etc as.
They should be strings of course but how should i declare them?
joshka89 is offline   Reply With Quote
Old Feb 28th, 2009, 10:36 AM   #6
Arla
Expert Programmer
 
Arla's Avatar
 
Join Date: Mar 2005
Posts: 777
Rep Power: 13 Arla is on a distinguished road
Re: Making java split up a code

As strings like you said?

I guess I would be thinking something like

String manuf = input.substring(0,2); //Substring takes begin and end index
String capacity = input.substring(3,6);
etc etc

Then you need to do some sort of comparison, not sure what the codes can contains, so I'm not sure if it's a switch statement, if you need to just examine the first character, do > or <, really depends what those codes contain.
__________________
I can remember, back in '22
They changed the law - came knocking on the door
In that same moment, the broadband seemed to go..
Phones all dead. Gone dizzy in the head..
Arla is offline   Reply With Quote
Old Feb 28th, 2009, 11:10 AM   #7
silent1mezzo
Hobbyist Programmer
 
Join Date: Aug 2007
Location: Mississauga ON
Posts: 125
Rep Power: 11 silent1mezzo is on a distinguished road
Re: Making java split up a code

Quote:
Originally Posted by Arla View Post
As strings like you said?

I guess I would be thinking something like

String manuf = input.substring(0,2); //Substring takes begin and end index
String capacity = input.substring(3,6);
etc etc

Then you need to do some sort of comparison, not sure what the codes can contains, so I'm not sure if it's a switch statement, if you need to just examine the first character, do > or <, really depends what those codes contain.
Lol...isn't that what I said?
silent1mezzo is offline   Reply With Quote
Old Mar 1st, 2009, 12:03 AM   #8
Arla
Expert Programmer
 
Arla's Avatar
 
Join Date: Mar 2005
Posts: 777
Rep Power: 13 Arla is on a distinguished road
Re: Making java split up a code

Quote:
Originally Posted by silent1mezzo View Post
Lol...isn't that what I said?
Yes, but apparently the OP isn't getting it so figured I'd post it again... of course somehow I missed reading your post so hadn't noticed it.
__________________
I can remember, back in '22
They changed the law - came knocking on the door
In that same moment, the broadband seemed to go..
Phones all dead. Gone dizzy in the head..
Arla is offline   Reply With Quote
Old Mar 4th, 2009, 9:08 AM   #9
joshka89
Programmer
 
Join Date: Feb 2009
Posts: 50
Rep Power: 9 joshka89 is on a distinguished road
Re: Making java split up a code

Here's my code
import java.util.Scanner;

public class Project1 {

	public static void main( String[] args) {
	
	Scanner input = new Scanner(System.in);
	
	System.out.print( "Enter the part number: ");
	String mainstring = input.next();
	
   String manuf = mainstring.substring(0, 2);
   String capacity = mainstring.substring(3, 6);
	String speed = mainstring.substring(7, 9);
	String form = mainstring.substring(10);
	String interf = mainstring.substring(11);
	
	System.out.print(manuf + " " + capacity + " " + speed + " " + form + " " + interf);

	
	
	
	
	
	
	
	}
	}

For some reason when i run it, it isnt asking me for an input. why not?

Last edited by Ancient Dragon; Mar 4th, 2009 at 9:10 AM. Reason: replaced ICODE tags with CODE tags
joshka89 is offline   Reply With Quote
Old Mar 4th, 2009, 3:36 PM   #10
Arla
Expert Programmer
 
Arla's Avatar
 
Join Date: Mar 2005
Posts: 777
Rep Power: 13 Arla is on a distinguished road
Re: Making java split up a code

What do you mean isn't asking you for an input? I ran it, and it gave a prompt (the "Enter the part number:" one, I typed a string, and then it displayed some results, not quite what I'd expected so you'd need to play with your substring commands, but results none the less.
__________________
I can remember, back in '22
They changed the law - came knocking on the door
In that same moment, the broadband seemed to go..
Phones all dead. Gone dizzy in the head..
Arla is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Programming Tutorial : Part I to GUI Programming Raikiriu Java 3 Sep 30th, 2010 11:46 PM
Java Decompiler.. Eric the Red Java 18 Nov 29th, 2007 5:51 AM
Help. I got a problem in making Java games .. bratsercom Java 11 Oct 1st, 2007 3:31 PM
Making a GUI in Java VigilanteP@comcast.net Java 10 Jun 19th, 2005 3:26 PM
Different IDE's Different code 357mag Java 1 Mar 26th, 2005 4:42 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:28 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC