Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Help with creating a class

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.
    Last edited by helloworld922; November 1st, 2010 at 09:33 AM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,462
    My Mood
    Hungover
    Thanks
    144
    Thanked 639 Times in 547 Posts

    Default Re: Help with creating a class

    Write out how you'd do this "by hand". Come up with very specific directions that you could give to somebody who doesn't know anything about roman numerals. When you have that, converting it to code should be pretty simple.

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,462
    My Mood
    Hungover
    Thanks
    144
    Thanked 639 Times in 547 Posts

    Default Re: Help with creating a class

    Oh, and don't crosspost: Help with creating a class - Java Forums

  4. #4
    Junior Member
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with creating a class

    ok ill try that...but im actually looking for help with creating a loop for the statement here so i think that falls under loop and control statements

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,462
    My Mood
    Hungover
    Thanks
    144
    Thanked 639 Times in 547 Posts

    Default Re: Help with creating a class

    Quote Originally Posted by cdawg_2010 View Post
    ok ill try that...but im actually looking for help with creating a loop for the statement here so i think that falls under loop and control statements
    Okay. And what would you like the loop to do? We can't really answer general "how do I do this" type questions except to point you to google and the basic tutorials.

Similar Threads

  1. Replies: 0
    Last Post: April 11th, 2010, 08:56 AM
  2. problem with data access when a class call another class
    By ea09530 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 4th, 2010, 05:20 PM
  3. Creating a class for points in three dimensions.
    By joachim89 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 8th, 2010, 06:13 PM
  4. how to load a class and type cast to that class?
    By chinni in forum Object Oriented Programming
    Replies: 2
    Last Post: November 9th, 2009, 09:18 AM
  5. Creating a class file
    By ipatch in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 8th, 2009, 06:19 PM