Roman Numeral Conversion To Decimals

Jul 29, 2014

I have made a program that is supposed to convert roman numerals to decimals. It is NOT supposed to convert decimals to roman numerals. The only problem it seems there is with the program is that it only adds and does NOT subtract. This causes some roman numeral conversions to be flawed. What can I try to fix this. Keep in mind that the reason some methods exist is because the directions for the code say that I have to make it this way.

Instructions:

Write a program that converts a number entered in Roman numerals to decimal. Your program should consist of a class called Roman. An object of type Roman should be able to 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 number as requested by the user. (Be sure to over-ride the toString function).
4) Your class must contain the method romanToDecimal to convert a Roman numeral into its equivalent decimal number.
5) Test your program using the following Roman numerals: MCXIV, CCCLIX, and MDCLXVI.

This is what I have so far. It compiles and there are no errors, but it does not subtract I from X, or I from V and so on. For example,CMXLVII should be 947, but the program outputs 1067.

import javax.swing.*;
import java.util.*;
public class Roman{
private String roman;
private int decimal;
public int romanToDecimal(String s)

[Code] .....

View Replies


ADVERTISEMENT

Arabic To Roman Numeral Converter

Sep 12, 2014

I got part of this converter built and running fine but now it's getting weird. Specifically I am getting to the part where I have to count above ten which means things like attaching Vs to Is and Xs and suchlike.

I know I have to use an .append someplace, I am just not certain how to go about it. I've been playing with it some, but this is honestly the biggest thing I've built so far that actually *ran* so I'm afraid to poke too many holes in it... where do I start? It's not like I can invent another return string and concatenate them. R is what I've got.

package hello;
public class RomansatHomans {
public static void main(String[] args) {
// input fed on this line loops through toRo and comes back as a String
// R
String R = toRo(23);
// int D = froRo("x");

[Code] ......

View Replies View Related

Ask User To Enter Number From 1 To 10 And Program Will Display Roman Numeral

Feb 6, 2014

I am trying to write a program that asks the user to enter a number from 1 through 10 and then the program will display the roman numeral for that number.

I am also adding a error message in which i haven't yet because im still trying to figure out how to the program will do the roman numeral.'

I have used the if and else if. but when i input a number it just repeats the number back to me.

The program cimpiles but it doesn't do what i want. here is what i have so far. how can i get the program to display the roman numeral after the number is entered.

import javax.swing.JOptionPane;
public class Romannumeral
{
public static void main(String[] args)
{
double number;
 
[Code] .....

View Replies View Related

Allow User To Enter Roman Numeral And Then Outputs Integer Number Value - While Loop

Feb 7, 2015

Write a program called RomanNumeralHelper that allows a user to enter a roman numeral and then outputs the integer number value. Use a Scanner to accept command line input from the user and continually ask for a roman numeral until the user enters Q (or q) to stop. Your solution should NOT use a switch statement.

Here is sample input / output:

Enter a roman numeral [Q | q to quit]: III
>> 3
Enter a roman numeral [Q | q to quit]: IV
>> 4
Enter a roman numeral [Q | q to quit]: V
>> 5
Enter a roman numeral [Q | q to quit]: Q
Good Bye!

This is what I have so far in my code, but I cant get what the user inputs when I want it to output the number.

import java.util.Scanner;
public class RomanNumber4
{
public static void main(String[] args) {
// obtain input from command window
Scanner input = new Scanner(System.in);
 
[Code] ....

View Replies View Related

Convert Roman To Ordinary Conversion Without Using Any Predefined Methods

Feb 25, 2015

convert roman to ordinary conversion without using any predefine methods,where we are giving input thru command prompt

View Replies View Related

How To Write Conversion Method From Roman Numerals To Arabic

Nov 8, 2014

I am a student taking a Java programming class. My assignment is to write a program that converts a roman numeral input as entered by a user and converting it to it's integer value (arabic number). These are the methods that I must have in it:

1. Write a method that takes input from the user and passes it to a conversion method.
2. Write a method that yields the numeric value of each of the letters (conversion method).
3. Write a method that outputs the number the user entered and the converted number.
4. Write a main method to test the 3 methods.

I have written the first method, at least I think. Here is what I did there:

public static String romanInput(String number) {
Scanner numberInput = new Scanner (System.in);
System.out.print("Enter a roman numeral: ");
String userInput = numberInput.next();
return userInput;
}

I returned the userInput and I think that is passing it to the conversion method? Now I am working on this conversion method and to be honest I don't know where to begin. I am told how to convert a string in my assignment by the professor. I am told:

- Look at the first two characters. If the first has a larger value than the second, then simply convert the first.
- Call the conversion method again for the substring starting with the second character.
-Add both values. If the first one has a smaller value than the second, compute the difference and add to it the conversion of the tail.

I am also told to use a single-dimensional array. But, I don't know what I am to use a single dimensional array for? So this is what I wrote so far for this method:

public static int numberConversion(int number) {

int romanConv = 0;
char[] romanNum = {'I', 'V', 'X', 'L', 'C', 'D', 'M'};
char[] arabicNum = {1, 5, 10, 50, 100, 500, 1000};
romanNum = arabicNum;
}

I have written a character array for the roman numerals, and then one for arabic numerals, then I set them equal to each other. I also declared an integer variable set to 0 because I think that is what I will be returning at the end of the method. Now I don't know where to start for the conversion algorithm here. I know this is what I have to do, but I don't know how to do it:

1. Add the numbers together if they are in decreasing value or are equal in value. For example: VI is read as 5 + 1 = 6 XVI is read as 10 + 5 + 1 = 16 XXXVIII is 10 + 10 + 10 + 5 + 1 + 1 + 1 = 38
2. Use subtraction if a number is less than the number that follows it. For example, I is less than V, so when I is in front of V, you subtract its value.
3. For example: IV is 5 1 = 4 IX is 10 1 = 9 XL is 50 10 = 40 MCM is 1,000 + (1,000 - 100) = 1,900

I can't use hashtables or enums because I haven't learned about that yet. I have a feeling I need to use a for loop. I know I haven't done any of the actual programming work but I don't know how to begin writing this conversion method.

View Replies View Related

Get Answer To Only Show Two Decimals

May 25, 2014

I have tried as much as I can to place code to give me only two decimals in answers but cannot get it to work not sure if placement or syntax.This is code so far and it works but gives answers to 8 decimals.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

[code]...

View Replies View Related

Program Is Supposed To Operate On Decimals

Mar 31, 2015

My program is supposed to operate on decimals because it concerns volume of packagings. I learnt that what normally is simple arithmetic (100 cm × 75 cm × 60 cm = 0.45 m³) in Java gives only approximate value (something like 0.44(9) m³ in this case). That's close enough so I probably shouldn't worry, but the thing is that although for one packaging the difference is barely visible—if at all—for thousands of packagings it'll make a difference. It'll be worse when I get to counting money.

I found two solutions:
1) Using integers and so-called decorative decimal point on display. I have a bad feeling about this, though.
2) Using BigDecimal.

Now, BigDecimal seems like a nice solution. I tried it and so far it looks okay. But just look at an excerpt from my program that I had to re-write (previously it looked perfectly fine as a single line):

volume = dimensions
.get("Length").multiply(dimensions.get("Width")
.multiply(dimensions.get("Height")))
.divide(new BigDecimal("1000000"));

I'm using a HashMap to store dimensions. I figured it'd make it easy for me to manage and display data later on.

View Replies View Related

Formatting Decimals (Two Temperature Values)

Jan 30, 2015

I'm trying to format two temperature values using String.format.

return String.format("% 5.1f", temperature) + 'u2109' + " / " + String.format("% 5.1f", temperature2) + 'u2109';

I need all of that to be combined into a single String.format and include the / and unicode symbols for degree fahrenheit. How String.format works so that I can figure out how to achieve that? I've tried a few websites but none of them explain it to the extent that I need to use it.

View Replies View Related

Loan Calculator - How To Round Decimals

May 20, 2014

I'm currently working on a loan calculator... The only problem I'm having is occasional values that have very long decimals... How do I round the decimals?

View Replies View Related

Converting Meters To Feet - How To Print Decimals

Oct 1, 2014

I am making a small program that converts meters to feet. I want my answer to be printed with 2 decimals, but I am struggle. This is my current code, any takes on what needs to be changed and why?

import java.util.Scanner;
import java.text.DecimalFormat;
public class Chapter2PE3 {
public static void main (String[]args){
Scanner input = new Scanner (System.in);

[Code] ....

View Replies View Related

Roman To Arabic Numbers Converter

Oct 5, 2014

I'm trying to do a program to convert roman numbers to arabic numbers. My problem is that I don't have the right to use Methods and Arrays. Only loops and if/else.

View Replies View Related

How To Convert Integer To Roman Numerals

Aug 20, 2014

I don't need the code , I just want to try on my own ....

View Replies View Related

Roman To Arabic Converter Says Everything Equals 1

Mar 25, 2015

Im working on a roman numeral to arabic converter and all I had to do was fill out the conversion method romanToDecimal. But for some reason no matter what number I enter It always says my number is equal to one.

//Quiz 1 EC
import java.util.*;
class Roman {
private String romanNum;
private int decimalNum;
public Roman(){
romanNum = "I";
decimalNum = 1;

[code]....

View Replies View Related

Program To Add 2 Roman Numerals Together And Return The Results

Feb 26, 2014

Writing an program to add any 2 given Roman numerals together and return the results.

[I don't want to convert Roman numbers to decimal numbers & then add together, then convert in to Roman numerials ]

Is there any direct way to add roman numerials?

For example: I + I = II
III + I = IV

View Replies View Related

Java Program To Convert Integer To Roman Numbers And Vice Versa?

Aug 20, 2014

java program to convert integer to Roman numbers and vice versa?

View Replies View Related

JSP :: Conversion Of HTML?

Feb 2, 2015

I have requirement to convert the HTML to JSP.

purpose: From the mobile i will get the HTML content and need the change content so need to convert html to JSP.

View Replies View Related

Conversion From Double To Int?

Nov 30, 2014

I'm having some trouble with a code I am writing for class. I had an 2 errors like this before this one and fixed it by changing int avgRe, avgMiles =0; to double. Now I am getting this error and am stuck on what I need to change. Here is the code:

import java.io.*;
import java.util.*;
import java.text.*;
 public class Reimbursement_3_09 {
 static Toolkit tools = new Toolkit();
 public static void main (String [] args) throws Exception {
 
[Code] ....

This is my error:

[code=Java]
Reimbursement_3_09.java:33: error: incompatible types: possible lossy conversion from double to int
summary (outFile, totalAmount, ctrMiles, ctrMilesgt0, avgRe, avgMiles);
^
Some messages have been simplified; recompile with -Xdiags:verbose to get full output 1 error

View Replies View Related

Int To BigInteger Conversion?

Oct 13, 2005

How to convert an 'int' to BigInteger.

View Replies View Related

Conversion From While To For Loop

Aug 3, 2014

I just started to teach myself loops. I am trying to convert the while loop into for loops, however somehow I do not get the same printout.

While loop:
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
int i = 1;
int sum = 0;

[Code] ....

Print:
sum is 0 and i is 1
sum is 1 and i is 2
sum is 3 and i is 3
sum is 6 and i is 4

View Replies View Related

UTF-8 Conversion In Java?

Oct 30, 2014

When I try to convert this value, "Testingu2120" (along with UTF coed u2120)comes as a string as part of SOAP response. I need to convert this UTF-8 characters in to a symbol, in this case it is SM (Service Mark) symbol and show it on the UI.

How can we achieve this in JAVA?

I have four different UTF-8 character set to convert.

TM - u2122
SM -u2120
R - u00AE
C - u00A9

View Replies View Related

LDIF To CSV Conversion?

Dec 11, 2012

I need to convert the LDIF data file to CSV format using Java. IS there any supporting JAR's, which we can use for the LDIF data file reading and parsing. Which is the best jar to use.

View Replies View Related

Socket Conversion TCP To UDP

Mar 4, 2014

Currently I have socket of the tcp version.

Java Code:

final ServerSocket serverSocketConn = new ServerSocket(9000);
while (true) {
try {
Socket socketConn1 = serverSocketConn.accept();
new Thread(new ConnectionHandler(socketConn1)).start();

[Code] .....

I managed to convert this final DatagramSocket serverSocketConn = new DatagramSocket (9000);

Now I am stuck here

Socket socketConn1 = serverSocketConn.accept();
new Thread(new ConnectionHandler(socketConn1)).start();

Can I use this or I need to create a manual thread pooling for UDP ?

View Replies View Related

If Else - Numbers To Words Conversion

Jul 23, 2014

Convert Number to words using If Else Codes?

View Replies View Related

Double To Hex String Conversion

May 8, 2014

I am trying to convert the double 4270571936.0000000000d to a hex string using Double.toHexString() and the answer I'm getting is 0x1.fd17834p31, what does p stands for?

The answer I'm expecting to get is 0x41efd17834000000 so not sure why it won't give me the correct answer?

The following floating point Double to hex calculator shows the write answer right Floating Point to Hex Converter

View Replies View Related

Infix And Postfix Conversion

Feb 25, 2014

Case study : infix to postfix conversion, i don't really know how i could make codes, I can understand what is the meaning of infix and postfix but when it comes of making codes i really have a hard time with it.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved