Page 1 of 2 12 LastLast
Results 1 to 20 of 23
  1. #1
    cdawg_2010 is offline Member
    Join Date
    Oct 2010
    Posts
    11
    Rep Power
    0

    Default Help with creating a class

    I need to create a class to use with another program that will take regular numbers and convert them to roman numerals. So far I have this:

    public class Roman {
    public Roman(String r){

    char c = r.charAt(0);
    int value;

    if(c=='I') value=1;
    else if(c=='V') value=5;
    else if(c=='X') value=10;
    else if(c=='L') value=50;
    else if(c=='C') value=100;
    else if(c=='D') value=500;
    else if(c=='M') value=1000;

    }
    public void printRoman(){

    System.out.println();
    }
    public void printInt(){

    System.out.println();
    }
    }


    I know i need a loop for the if else if part, but I'm not too sure on what that loop is. Also, i need code after the printRoman part, but I don't know that either. If someone could point me in the right direction, that'd be great.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,889
    Rep Power
    8

  3. #3
    socboy6579 is offline Member
    Join Date
    Oct 2010
    Posts
    81
    Rep Power
    0

    Default

    im just wondering.. but why is crossposting such a big issue?

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default

    From a different forum, but the principles remain much the same everywhere:
    Be Forthright When Cross Posting To Other Sites at JavaRanch

    Cross posting per se isn't an issue. The issue is cross posting and not informing forum members that the question may be answered elsewhere.

    db

  5. #5
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,889
    Rep Power
    8

    Default

    Many people will not help a crossposter because there is no way to know where else the question has been posted. That means there's no way to know what kind of help the person has already received, or even whether the problem has already been solved somewhere else. Posting to such a question would be wasting time that could be better spent on people who haven't crossposted and that still need help.

  6. #6
    cdawg_2010 is offline Member
    Join Date
    Oct 2010
    Posts
    11
    Rep Power
    0

    Default

    im just trying to get help from different people alright does it really matter? its 2 different forums. no one has even answered anything on here relating to the question

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by cdawg_2010 View Post
    im just trying to get help from different people alright does it really matter? its 2 different forums. no one has even answered anything on here relating to the question
    Please read the link that Darryl has provided and you'll see why it matters. We all understand that you're new here and are not yet familiar with our culture. In this light, I can almost guarantee you that if you respond positively to this, you'll get lots of help.

    Good luck.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    ... or you can ignore my suggestion. Up to you.

  9. #9
    cdawg_2010 is offline Member
    Join Date
    Oct 2010
    Posts
    11
    Rep Power
    0

    Default

    ok i wasnt aware that the two sites were linked, so it was my fault. i was just looking for an answer so i posted on different sites. but anyways, any suggestons?

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    The forums are not linked, and so it's not an issue about that. Instead it's about volunteers not performing wasted effort. Anyway, I'm not sure what algorithm you plan to use to convert your int to a roman numeral, and so if you could explain this in English, I'm sure we could help you with the code. Also, it might help you to search the forum for the term roman numeral as this sort of thing has been discussed many times here. In fact I sort of like my example that uses enums which was posted in November, 2008: Convert roman numerals

    Luck.
    Last edited by Fubarable; 11-01-2010 at 03:44 AM.

  11. #11
    cdawg_2010 is offline Member
    Join Date
    Oct 2010
    Posts
    11
    Rep Power
    0

    Default

    well first i'm just trying to create the class roman and then use it in a different program i have to create. I'm trying to figure out what goes here "public void printRoman(){

    System.out.println();
    }" for the code in between the 2 lines.
    also, i'm trying to figure out the loop i need for the values. sorry if i sound too vague maybe, but i am hopelessly lost with this program.

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by cdawg_2010 View Post
    well first i'm just trying to create the class roman and then use it in a different program i have to create. I'm trying to figure out what goes here "public void printRoman(){

    System.out.println();
    }" for the code in between the 2 lines.
    also, i'm trying to figure out the loop i need for the values. sorry if i sound too vague maybe, but i am hopelessly lost with this program.
    I'm not asking what Java code you're planning to use, but rather logically, how are you planning to translate from a number to a roman numeral, as if you were going to do this with pen and paper. You have to know how to do this first before you can do any coding here. Write down the steps you'd use and post them here.

  13. #13
    cdawg_2010 is offline Member
    Join Date
    Oct 2010
    Posts
    11
    Rep Power
    0

    Default

    Well first I would get the number.
    Then I would find the value for each character in the number.
    If it was 12 for example, the 10 part would get the "X" and then the 2 would get "II"

    Are you meaning something like this?

  14. #14
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Something like that. So you would be doing both division to see how many 10's there are and also calculating the remainder, to see that 2 is left. What would you do if the number were larger, say 1986? Also, what are the precise requirements for this class in your assignment?

  15. #15
    cdawg_2010 is offline Member
    Join Date
    Oct 2010
    Posts
    11
    Rep Power
    0

    Default

    Here are the requirements:

    "Write a program that converts a number entered in Roman numerals to decimal. Your program should consist of a class, for example Roman. An object of the type Roman should do the following:"

    1. Store the number as a Roman Numeral.

    2. Convert and store the number into decimal.

    3. Print the number as a Roman numeral or decimal numeral as requested by user.

    As for your question, I know that 1986 would be MDCCCLXXXVI i think, but I don't know how to do that in the program yet.

  16. #16
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  17. #17
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You would want to loop through your string using either charAt or subString, and start at the left going right. You might want to first grab two adjacent characters to see if they match any of the pairs, such as CM for 900, CD for 400, XC for 90, XL for 40, IX for 9, and IV for 4. If so, add the corresponding number to the int. If no match, then grab the one letter and which letter it matches and add the corresponding number to your int. Then iterate to the next pair of letters vs single letter.

  18. #18
    cdawg_2010 is offline Member
    Join Date
    Oct 2010
    Posts
    11
    Rep Power
    0

    Default

    I have the charAt in there but i dont know what kind of loop to use. A while loop maybe?

  19. #19
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,889
    Rep Power
    8

    Default

    Quote Originally Posted by cdawg_2010 View Post
    I have the charAt in there but i dont know what kind of loop to use. A while loop maybe?
    What happened when you tried?

  20. #20
    cdawg_2010 is offline Member
    Join Date
    Oct 2010
    Posts
    11
    Rep Power
    0

    Default

    Quote Originally Posted by KevinWorkman View Post
    What happened when you tried?
    Im still working on in. I'm new and really slow at this lol

Page 1 of 2 12 LastLast

Similar Threads

  1. problem in creating a class that should always run in the server
    By harsha.udupa2008 in forum New To Java
    Replies: 1
    Last Post: 07-14-2010, 02:56 PM
  2. Help creating a Date class
    By Meta in forum New To Java
    Replies: 17
    Last Post: 04-30-2010, 09:28 AM
  3. Replies: 2
    Last Post: 03-08-2010, 10:29 AM
  4. Creating a Defined Class with Member Functions
    By New2Java in forum New To Java
    Replies: 6
    Last Post: 08-05-2009, 09:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •