Question

In: Computer Science

in java: In my code at have my last two methods that I cannot exactly figure...

in java: In my code at have my last two methods that I cannot exactly figure out how to execute. I have too convert a Roman number to its decimal form for the case 3 switch. The two methods I cannot figure out are the public static int valueOf(int numeral) and public static int convertRomanNumber(int total, int length, String numeral). This is what my code looks like so far:

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner in = new Scanner(System.in);

String fName = "";

String lName = "";

double hoursWorked = 10;

double hourlyRate = 10;

double regularPay = 10;

double overtimeHours = 10;

int choice;

System.out.println("Calculator Menu");

System.out.println("1) Wage Calculator");

System.out.println("2) Coupon Calculator");

System.out.println("3) Roman Number Converter");

System.out.println("4) Exit");

System.out.println("");

System.out.println("Enter choice: ");

choice = in.nextInt();

switch(choice) {

case 1:

System.out.println("Enter first name: ");

fName = in.next();

System.out.println("Enter last name: ");

lName = in.next();

System.out.println("Enter hourly rate: ");

hourlyRate = in.nextDouble();

System.out.println("Enter hours worked: ");

hoursWorked = in.nextDouble();

System.out.printf("Name: " + fName + "," + lName);

System.out.println("");

wageCalculator(hoursWorked, overtimeHours, hourlyRate, regularPay);

break;

case 2:

double purchaseAmount;

int purchaseType;

final double autoP = 1;

final double frag = 2;

final double acc = 3;

System.out.println("Enter purchase amount: ");

purchaseAmount = in.nextDouble(); {

System.out.println("Choose purchase type: ");

System.out.println("1) Auto Parts");

System.out.println("2) Fragrances");

System.out.println("3) Accessories");

purchaseType = in.nextInt();

}

couponCalculator(purchaseType, purchaseAmount, autoP, frag, acc);

break;

case 3:

double calc_w;

/*

int length = Integer.toString(numeral).length();

System.out.println("Please enter Roman Number: ");

*/ String numeral = null;

int total = 0;

int length = numeral.length();

System.out.print("Enter roman numeral to convert: ");

numeral =in.next();

// total = convertNum(romanNum);

System.out.println("The roman numeral converted is: " + total);

total = in.nextInt();

// Method valueOf - Gives the value of the Roman numeral @param numeral a single Roman numeral

// @return the decimal value of numeral

//promp user to enter roman number

// then convert it to regular number

convertRomanNumber(total, length, numeral);

break;

case 4:

// exit program

System.out.println("Thank you for using our program. Have a great day!");

}

}

public static void wageCalculator(double hoursWorked, double overtimeHours, double hourlyRate, double regularPay) {

// TODO Auto-generated method stub

double overtimePay = 0;

if (hoursWorked > 40) {

overtimeHours = hoursWorked - 40;

System.out.println("Overtime hours: " + overtimeHours);

overtimePay = overtimeHours*(1.5*hourlyRate);

System.out.println("Overtime Pay: " + overtimePay);

System.out.printf("Total Pay $%.2f", regularPay + overtimePay);

hoursWorked = 40;

}

regularPay = hourlyRate*hoursWorked;

System.out.println("Regular hours worked: " + hoursWorked);

System.out.println("Regular Pay: $" + regularPay);

System.out.printf("Total Pay $%.2f", regularPay + overtimePay);

}

// add all variables to method header

public static void couponCalculator(int purchaseType, double purchaseAmount, double autoP, double frag, double acc) {

if (purchaseType == autoP) {

System.out.println("Your coupon is: $" + purchaseAmount*.10 + "(Auto Parts)");

} if (purchaseType == frag) {

System.out.println("Your coupon is: $" + purchaseAmount*.15 + "(Fragrances)");

} if (purchaseType == acc) {

System.out.println("Your coupon is: $" + purchaseAmount*.20 + "(Accessories)");

}

}

public static int convertRomanNumber(String str) {

}

return total;

}

public static int valueOf(char numeral) {

if (numeral == 'I') {

return 1;

}

if (numeral == 'V') {

return 5;

} if (numeral == 'X') {

return 10;

} if (numeral == 'L') {

return 50;

} if (numeral == 'C') {

return 100;

} if

(numeral == 'D')

return 500;

else if (numeral == 'M')

return 1000;

return numeral;

}

}

Solutions

Expert Solution

Implementation:

   public static void main(String[] args) {
        // TODO code application logic here
       

// TODO Auto-generated method stub

Scanner in = new Scanner(System.in);

String fName = "";

String lName = "";

double hoursWorked = 10;

double hourlyRate = 10;

double regularPay = 10;

double overtimeHours = 10;

int choice;

System.out.println("Calculator Menu");

System.out.println("1) Wage Calculator");

System.out.println("2) Coupon Calculator");

System.out.println("3) Roman Number Converter");

System.out.println("4) Exit");

System.out.println("");

System.out.println("Enter choice: ");

choice = in.nextInt();

switch(choice) {

case 1:

System.out.println("Enter first name: ");

fName = in.next();

System.out.println("Enter last name: ");

lName = in.next();

System.out.println("Enter hourly rate: ");

hourlyRate = in.nextDouble();

System.out.println("Enter hours worked: ");

hoursWorked = in.nextDouble();

System.out.printf("Name: " + fName + "," + lName);

System.out.println("");

wageCalculator(hoursWorked, overtimeHours, hourlyRate, regularPay);

break;

case 2:

double purchaseAmount;

int purchaseType;

final double autoP = 1;

final double frag = 2;

final double acc = 3;

System.out.println("Enter purchase amount: ");

purchaseAmount = in.nextDouble(); {

System.out.println("Choose purchase type: ");

System.out.println("1) Auto Parts");

System.out.println("2) Fragrances");

System.out.println("3) Accessories");

purchaseType = in.nextInt();

}

couponCalculator(purchaseType, purchaseAmount, autoP, frag, acc);

break;

case 3:

double calc_w;

/*

int length = Integer.toString(numeral).length();

System.out.println("Please enter Roman Number: ");

*/ 
String numeral;

int total = 0;



System.out.print("Enter roman numeral to convert: ");

numeral =in.next();
int length = numeral.length();
 total = convertRomanNumber(total, length, numeral);

System.out.println("The roman numeral converted is: " + total);


// Method valueOf - Gives the value of the Roman numeral @param numeral a single Roman numeral

// @return the decimal value of numeral

//promp user to enter roman number

// then convert it to regular number


break;

case 4:

// exit program

System.out.println("Thank you for using our program. Have a great day!");

}

}


public static void wageCalculator(double hoursWorked, double overtimeHours, double hourlyRate, double regularPay) {

// TODO Auto-generated method stub

double overtimePay = 0;

if (hoursWorked > 40) {

overtimeHours = hoursWorked - 40;

System.out.println("Overtime hours: " + overtimeHours);

overtimePay = overtimeHours*(1.5*hourlyRate);

System.out.println("Overtime Pay: " + overtimePay);

System.out.printf("Total Pay $%.2f", regularPay + overtimePay);

hoursWorked = 40;

}

regularPay = hourlyRate*hoursWorked;

System.out.println("Regular hours worked: " + hoursWorked);

System.out.println("Regular Pay: $" + regularPay);

System.out.printf("Total Pay $%.2f", regularPay + overtimePay);

}

// add all variables to method header

public static void couponCalculator(int purchaseType, double purchaseAmount, double autoP, double frag, double acc) {

if (purchaseType == autoP) {

System.out.println("Your coupon is: $" + purchaseAmount*.10 + "(Auto Parts)");

} if (purchaseType == frag) {

System.out.println("Your coupon is: $" + purchaseAmount*.15 + "(Fragrances)");

} if (purchaseType == acc) {

System.out.println("Your coupon is: $" + purchaseAmount*.20 + "(Accessories)");

}

}

public static int convertRomanNumber(int total,int length,String str) {

  for(int i=0;i<length;i++)//loop till length of string
  {
      int str1=valueOf(str.charAt(i));//getting value at str[i];
      if(i+1<length)
      {
          int str2=valueOf(str.charAt(i+1));//at str[i+1]
          
          if(str1<str2)
          {
              total=total+(str2-str1);
              i++;
          }
          else if(str1>=str2)
          {//if(current symbol is greater than or equal to next symbol then need to add both number otherwise subtract (str2-str1) 
              total=total+str1;
              
          }

          
      }else{
          total=total+str1;//simply add last number
          i++;
          
      }
  }

return total;

}

public static int valueOf(char numeral) {

if (numeral == 'I') {

return 1;

}

if (numeral == 'V') {

return 5;

} if (numeral == 'X') {

return 10;

} if (numeral == 'L') {

return 50;

} if (numeral == 'C') {

return 100;

} if

(numeral == 'D')

return 500;

else if (numeral == 'M')

return 1000;

return -1;

}

}

//you have done a pretty nice job well-done keep growing!!

//code is self-explanatory do tell me in comment if unable to understand!!


Related Solutions

Show work please, this is the last problem for my homework and I cannot figure this...
Show work please, this is the last problem for my homework and I cannot figure this out for the life of me An IP4 datagram arrived with the following information in the header (in hexadecimal):                0x4A 00 00 56 00 03 58 50 18 06 58 50 7C 4E 03 02 B4 0E OF 15 2f………. Are there any options? How many bytes, if any? How many more routers can the packet travel to? Explain. What is the size...
JAVA: How do I fix the last "if" statement in my code so that outputs the...
JAVA: How do I fix the last "if" statement in my code so that outputs the SECOND HIGHEST/MAXIMUM GPA out of the given classes? public class app { private static Object minStudent; private static Object maxStudent; public static void main(String args[ ]) { student st1 = new student("Rebecca", "Collins", 22, 3.3); student st2 = new student("Alex", "White", 19, 2.8); student st3 = new student("Jordan", "Anderson", 22, 3.1); student[] studentArray; studentArray = new student[3]; studentArray[0] = st1; studentArray[1] = st2; studentArray[2]...
JAVA JAVA JAVA Hey i need to find a java code for my homework, this is...
JAVA JAVA JAVA Hey i need to find a java code for my homework, this is my first java homework so for you i don't think it will be hard for you. (basic stuff) the problem: Write a complete Java program The transport Company in which you are the engineer responsible of operations for the optimization of the autonomous transport of liquid bulk goods, got a design contract for an automated intelligent transport management system that are autonomous trucks which...
I have the following code for my java class assignment but i am having an issue...
I have the following code for my java class assignment but i am having an issue with this error i keep getting. On the following lines: return new Circle(color, radius); return new Rectangle(color, length, width); I am getting the following error for each line: "non-static variable this cannot be referenced from a static context" Here is the code I have: /* * ShapeDemo - simple inheritance hierarchy and dynamic binding. * * The Shape class must be compiled before the...
this is my assignment for intro to java tha i could not figure out, my system...
this is my assignment for intro to java tha i could not figure out, my system just crashed wit a lot of errors. thank for your help Create a new Java class inside your project folder. The name of the class should be: TempConverter Note that this means you should have the following line at the top of your program: public class TempConverter Write a program that allows the user to convert a temperature given in degrees Celsius or Fahrenheit...
The programming language that is being used here is JAVA, below I have my code that...
The programming language that is being used here is JAVA, below I have my code that is supposed to fulfill the TO-DO's of each segment. This code in particular has not passed 3 specific tests. Below the code, the tests that failed will be written in bold with what was expected and what was outputted. Please correct the mistakes that I seem to be making if you can. Thank you kindly. OverView: For this project, you will develop a game...
Cannot figure out why my c++ program keeps crashing, I am attempting to have the user...
Cannot figure out why my c++ program keeps crashing, I am attempting to have the user decide the size of a 2d array then fill said array. #include <iostream> using namespace std; typedef int* IntArrayPtr; int main(void) { int column, row, i, j; IntArrayPtr *arr_num = new IntArrayPtr[row]; cout << " " << endl << " This program creates a 2D array of dynamic memory, fills it with user entered numbers, " << endl << " Then prints the array...
IN JAVA. I have the following code (please also implement the Tester to test the methods...
IN JAVA. I have the following code (please also implement the Tester to test the methods ) And I need to add a method called public int remove() that should remove the first integer of the array and return it at the dame time saving the first integer and bring down all other elements. After it should decrease the size of the array, and after return and save the integer. package ourVector; import java.util.Scanner; public class ourVector { private int[]...
Language: Java I have written this code but not all methods are running. First method is...
Language: Java I have written this code but not all methods are running. First method is running fine but when I enter the file path, it is not reading it. Directions The input file must be read into an input array and data validated from the array. Input file format (500 records maximum per file): comma delimited text, should contain 6 fields: any row containing exactly 6 fields is considered to be invalid Purpose of this code is to :...
I Have posted my Java code below. Fix the toString, add, and remove implementations so that...
I Have posted my Java code below. Fix the toString, add, and remove implementations so that the following test cases work. Note: I have removed all the unnecessary inherited List implementations. I have them to: throw new UnsupportedException(); For compilation, you could also add //TODO. Test (Main) List list = new SparseList<>(); list.add("0"); list.add("1"); list.add(4, "4"); will result in the following list of size 5: [0, 1, null, null, 4]. list.add(3, "Three"); will result in the following list of size...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT