Help getting my code to run.
public class BusinessClass {
// Length
public static double inTOcm(double inches) {
return 2.54 * inches;
}public static double inTOmeter(double inches) {
return 0.0254 * inches;
}public static double inTOft(double inches) {
return 0.083333 * inches;
}public static double inTOyd(double inches) {
return 0.0277778 * inches;
}public static double inTOkm(double inches) {
return 0.000254 * inches;
}public static double ftTOmeter(double feet) {
return 0.3048 * feet;
}public static double ftTOyd(double feet) {
return 0.0003048 * feet;
}public static double ftTOkm(double feet) {
return 0.33333 * feet;
}public static double ftTOmiles(double feet) {
return 0.000189394 * feet;
}public static double ydTOmeter(double yard) {
return 0.914 * yard;
}public static double ydTOft(double yard) {
return 3.0 * yard;
}public static double ydTOkm(double yard) {
return 0.00091444 * yard;
}public static double ydTOmile(double yard) {
return 0.000568182 * yard;
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class MeasuementClassCalculationsTest
{
public static void main(String[] args)
{
// Scanner object for keyboard input
Scanner keyboardInput = new Scanner(System.in);
// Prompt the user to select an option
System.out.println("\nType an option to perform the operation\n" +
" Option 1: Calculate inches\n" +
" Option 2: Calculate feet\n" +
" Option 3: Calculate yards\n" +
" Option 4: End the Program\n");
optionSelected = keyboardInput.nextInt();
keyboardInput.nextLine(); //Consume enter key
while (optionSelected != 4)
{
switch(optionSelected)
{
case 1:
Calculate cal=new Calculate(inches);
System.out.println("\nOunces: "+cal.inTOcm());
System.out.println("\nKilograms: "+cal.inTOmeter());
System.out.println("\nOunces: "+cal.inTOft());
System.out.println("\nOunces: "+cal.inTOyd());
System.out.println("\nOunces: "+cal.inTOkm());
System.out.print("\n");
break;
case 2:
Calculate cal=new Calculate(feet);
System.out.println("\nOunces: "+cal.ftTOmeter());
System.out.println("\nKilograms: "+cal.ftTOyd());
System.out.println("\nOunces: "+cal.ftTOkm());
System.out.println("\nOunces: "+cal.ftTOmiles());
System.out.print("\n");
break;
case 3:
Calculate cal=new Calculate(yard)
System.out.println("\nOunces: "+cal.ydTOmeter());
System.out.println("\nKilograms: "+cal.ydTOft());
System.out.println("\nOunces: "+cal.inTOkm());
System.out.println("\nOunces: "+cal.inTOmile());
System.out.print("\n");
break;
case 4:
break;
default:
System.out.println("Enter a number from 1 to 4 only ");
} // End of the switch statement
// Prompt the user to select an option
System.out.println("\nType an option to perform the operation\n" +
" Option 1: Calculate inches\n" +
" Option 2: Calculate feet\n" +
" Option 3: Calculate yards\n" +
" Option 4: End the Program\n");
optionSelected = keyboardInput.nextInt();
keyboardInput.nextLine();
}
}
}Hello,
Here is the code, I have modified your MeasuementClassClaculationsTest. java to MeasurementClassCalculationsTest.java. There was a reference that you were making to a class called Calculate, it was supposed to be the reference of BusinessClass. Your BusinessClass.java has been retained as is. There has been no constructors with args in BusinessClass.java. However, for some reason I could see that you were trying to pass the parameter while instantiation. I have corrected that, please take a look. Also, I have a double variable called inputValue being introduced and is passed across all the methods. In addition, 3 objects are created cal1, cal2, cal3. Now, the program is running fine, I am also enclosing the screenshots for your reference.



MeasurementClassCalculationsTest.java
import java.util.Scanner;
public class MeasurementClassCalculationsTest
{
public static void main(String[] args)
{
// Scanner object for keyboard input
/*
Variable inputValue is the once which is passed across all the methods below
Change the value of it whenever needed
*/
double inputValue = 10; // I am giving input as 10, you can change it to whatever you want
Scanner keyboardInput = new Scanner(System.in);
// Prompt the user to select an option
System.out.println("\nType an option to perform the operation\n" +
" Option 1: Calculate inches\n" +
" Option 2: Calculate feet\n" +
" Option 3: Calculate yards\n" +
" Option 4: End the Program\n");
int optionSelected = keyboardInput.nextInt();
keyboardInput.nextLine(); //Consume enter key
while (optionSelected != 4)
{
switch(optionSelected)
{
case 1:
BusinessClass cal1=new BusinessClass(); // Creating an obj - cal1
System.out.println("\nOunces: "+cal1.inTOcm(inputValue));
System.out.println("\nKilograms: "+cal1.inTOmeter(inputValue));
System.out.println("\nOunces: "+cal1.inTOft(inputValue));
System.out.println("\nOunces: "+cal1.inTOyd(inputValue));
System.out.println("\nOunces: "+cal1.inTOkm(inputValue));
System.out.print("\n");
break;
case 2:
BusinessClass cal2=new BusinessClass(); // Creating an obj - cal2
System.out.println("\nOunces: "+cal2.ftTOmeter(inputValue));
System.out.println("\nKilograms: "+cal2.ftTOyd(inputValue));
System.out.println("\nOunces: "+cal2.ftTOkm(inputValue));
System.out.println("\nOunces: "+cal2.ftTOmiles(inputValue));
System.out.print("\n");
break;
case 3:
BusinessClass cal3=new BusinessClass(); // Creating an obj - cal3
System.out.println("\nOunces: "+cal3.ydTOmeter(inputValue));
System.out.println("\nKilograms: "+cal3.ydTOft(inputValue));
System.out.println("\nOunces: "+cal3.ydTOkm(inputValue));
System.out.println("\nOunces: "+cal3.ydTOmile(inputValue));
System.out.print("\n");
break;
case 4:
break;
default:
System.out.println("Enter a number from 1 to 4 only ");
} // End of the switch statement
// Prompt the user to select an option
System.out.println("\nType an option to perform the operation\n" +
" Option 1: Calculate inches\n" +
" Option 2: Calculate feet\n" +
" Option 3: Calculate yards\n" +
" Option 4: End the Program\n");
optionSelected = keyboardInput.nextInt();
keyboardInput.nextLine();
}
}
}
--------------------------------------------------------------------------------------------------
BusinessClass.java
THIS CLASS HAS BEEN RETAINED WITHOUT ANY CHANGES, HENCE NO COMMENTS/ EXPLANATION GIVEN
public class BusinessClass {
// Length
public static double inTOcm(double inches) {
return 2.54 * inches;
}public static double inTOmeter(double inches) {
return 0.0254 * inches;
}public static double inTOft(double inches) {
return 0.083333 * inches;
}public static double inTOyd(double inches) {
return 0.0277778 * inches;
}public static double inTOkm(double inches) {
return 0.000254 * inches;
}public static double ftTOmeter(double feet) {
return 0.3048 * feet;
}public static double ftTOyd(double feet) {
return 0.0003048 * feet;
}public static double ftTOkm(double feet) {
return 0.33333 * feet;
}public static double ftTOmiles(double feet) {
return 0.000189394 * feet;
}public static double ydTOmeter(double yard) {
return 0.914 * yard;
}public static double ydTOft(double yard) {
return 3.0 * yard;
}public static double ydTOkm(double yard) {
return 0.00091444 * yard;
}public static double ydTOmile(double yard) {
return 0.000568182 * yard;
}
}
Thank you,
All the best !!!
Help getting my code to run. public class BusinessClass { // Length public static double inTOcm(double...
I am working on this switch statement code and I am getting errors. Please help. import java.util.Scanner; public class Switchstatement { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here } class Convertor { public static void main(String[] args) { int choice; Double Yen, UsDollars, Kilometer, Miles, Kilograms, Pounds, Inches; Double Centimeters, result; Scanner scanner = new Scanner(System.in); System.out.print("Enter 1\t UsDollars to Yen:...
(How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...
I need the following java code commented import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner (System.in); int productNo=0; double product1; double product2; double product3; double product4; double product5; int quantity; double totalsales=0; while(productNo !=0) System.out.println("Enter Product Number 1-5"); productNo=input.nextInt(); System.out.println("Enter Quantity Sold"); quantity=input.nextInt(); switch (productNo) { case 1: product1=1.00; totalsales+=(1.00*quantity); break; case 2: product2=2.00; totalsales+=(2.00*quantity); break; case 3: product3=6.00; totalsales+=(6.00*quantity); break; case 4: product4=23.00; totalsales+=(23.00*quantity); break; case 5: product5=17.00; totalsales+=(17.00*quantity); break;...
Could you help me pleas , this is my code I want change it to insert student by user , and i have problem when i want append name it just one time i can't append or present more one. >>>>>>>>>>>>>>>>>>>. import java.util.Iterator; import java.util.Scanner; public class studentDLLTest { static int getChoice() { Scanner in = new Scanner(System.in); int choice; do { System.out.print("\nYour choice? : "); choice = in.nextInt(); } while (choice < 1 || choice > 9); return choice;...
Need Help ASAP!! Below is my code and i am getting error in
(public interface stack) and in StackImplementation class. Please
help me fix it. Please provide a solution so i can fix the
error.
thank you....
package mazeGame;
import java.io.*;
import java.util.*;
public class mazeGame {
static String[][]maze;
public static void main(String[] args)
{
maze=new String[30][30];
maze=fillArray("mazefile.txt");
}
public static String[][]fillArray(String file)
{
maze = new String[30][30];
try{...
Could someone re-write this code so that it first prompts the user to choose an option from the calculator (and catches if they enter a string), then prompts user to enter the values, and then shows the answer. Also, could the method for the division be rewritten to catch if the denominator is zero. I have the bulk of the code. I am just having trouble rearranging things. ------ import java.util.*; abstract class CalculatorNumVals { int num1,num2; CalculatorNumVals(int value1,int value2)...
I need help with this method (public static int computer_move(int board[][])) . When I run it and play the compute.The computer enters the 'O' in a location that the user has all ready enter it sometimes. I need to fix it where the computer enters the 'O' in a location the user has not enter the "X' already package tictactoe; import java.util.Scanner; public class TicTacToeGame { static final int EMPTY = 0; static final int NONE = 0; static final...
Why isnt my MyCalender.java working? class MyCalender.java : package calenderapp; import java.util.Scanner; public class MyCalender { MyDate myDate; Day day; enum Day { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday } public static void main(String[] args) { Scanner sc= new Scanner(System.in); System.out.println("Enter date below :"); System.out.println("Enter day :"); int day = sc.nextInt(); System.out.println("Enter Month :"); int month = sc.nextInt(); System.out.println("Enter year :"); int year = sc.nextInt(); MyDate md = new MyDate(day, month, year); if(!md.isDateValid()){ System.out.println("\n Invalid date . Try...
Evaluateeg
EvaluateInFix.java:
import java.util.Stack;
import java.util.Scanner;
public class EvaluateInfix
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.println("This program an inFix Expression: ");
System.out.print("Enter an inFix Expression that you want to
evaluate (or enter ! to exit): ");
String aString = keyboard.nextLine();
while (!aString.equals("!"))
{
System.out.println (evaluateinFix(aString));
System.out.print("Enter an inFix Expression that you
want to evaluate (or enter ! to exit): ");
aString = keyboard.nextLine();
} // end while...
JAVA --Design a class named StackOfStrings that contains: a. A private array elements to store strings in the stack b. A private data field size to store the number of strings in the stack c. A constructor to construct an empty stack with a default capacity of 4 d. A constructor to construct an empty stack with a specified capacity e. A method empty() that returns true if the stack is empty f. A method push(String value) that stores value...