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:
");
Yen = scanner.nextDouble(0);
System.out.print("Enter 2\t Kilograms to Pounds:
");
Kilograms = scanner.nextDouble;
System.out.print("Enter 3\t Miles to Kilometers: ");
Miles = scanner.nextDouble;
System.out.print("Enter 4\t Inches to Centmeter: ");
Inches = scanner.nextDouble;
Yen = scanner.nextDouble();
UsDollars = scanner.nextDouble();
Kilograms = scanner.nextDouble();
Pounds = scanner.nextDouble();
Miles = scanner.nextDouble();
Inches = scanner.nextDouble();
switch (Convertor) {
case 1:
result = UsDollar * Yen;
System.out.print("UsDollars "*" Yen + " = " +
result+);
break;
case 2:
result = Kilograms * Pounds;
System.out.print("Kilograms + "*" + Pounds + " = " +
result");
break;
case 3:
result = Miles * Kilometers;
System.out.print(Miles + "*" + Kilometers + " = " + result);
break;
case 4:
result = Inches * Centimeters;
System.out.print(Inches + "/" + Centimeters + " = " +
result);
break;
default:
System.out.println("Invalid entry!");
break;
}
import java.util.Scanner;
/*
public class Switchstatement {
* @param args the command line arguments
public static void main(String[] args) { //There can be one main
in the program
}
*/
class Convertor
{
public static void main(String[] args) {
int choice;
Double Yen, UsDollar, Kilometer, Miles, Kilograms, Pounds,
Inches;
Double Centimeters, result;
Scanner scanner = new Scanner(System.in);
/*
System.out.print("Enter 1\t UsDollars to Yen: ");
UsDollar = 1.0;
Yen = scanner.nextDouble();
System.out.print("Enter 2\t Kilograms to Pounds: ");
Pounds = 1.0;
Kilograms = scanner.nextDouble();
System.out.print("Enter 3\t Miles to Kilometers: ");
Miles = scanner.nextDouble();
Kilometer = 1.0;
System.out.print("Enter 4\t Inches to Centmeter: ");
Inches = scanner.nextDouble();
Centimeters = 1.0;
*/
System.out.println("MENU");
System.out.println(" 1\t UsDollars to Yen: ");
System.out.println(" 2\t Kilograms to Pounds: ");
System.out.println(" 3\t Miles to Kilometers: ");
System.out.println(" 4\t Inches to Centmeter: ");
System.out.println(" Enter your choice");
choice = scanner.nextInt();
/*
//YOU HAVE ALREADY READ THE VALUES ABOVE
Yen = scanner.nextDouble();
UsDollars = scanner.nextDouble();
Kilograms = scanner.nextDouble();
Pounds = scanner.nextDouble();
Miles = scanner.nextDouble();
Inches = scanner.nextDouble();
*/
switch (choice) { //Instead of converter use the choice variable that you have declared above
case 1:
System.out.println("Enter number of Usdollars");
UsDollar = scanner.nextDouble();
System.out.println("Enter rate of UsDollar to Yen");
Yen = scanner.nextDouble();
result = UsDollar * Yen;
System.out.print(UsDollar + " * " + Yen + " = " + result +
"\n");
break;
case 2:
System.out.println("Enter number of Kilograms");
Kilograms = scanner.nextDouble();
System.out.println("Enter rate of Kilogram to Pounds");
Pounds = scanner.nextDouble();
result = Kilograms * Pounds;
System.out.print(Kilograms + " * " + Pounds + " = " + result+
"\n");
break;
case 3:
System.out.println("Enter number of Miles");
Miles = scanner.nextDouble();
System.out.println("Enter rate of Miles to Kilometer");
Kilometer = scanner.nextDouble();
result = Miles * Kilometer;
System.out.print(Miles + " * " + Kilometer + " = " + result +
"\n");
break;
case 4:
System.out.println("Enter number of Inches");
Inches = scanner.nextDouble();
System.out.println("Enter rate of Inches to Centimeter");
Centimeters = scanner.nextDouble();
result = Inches * Centimeters;
System.out.print(Inches + " * " + Centimeters + " = " + result +
"\n");
break;
default:
System.out.println("Invalid entry!");
break;
}
scanner.close();
}
}
COMMENT DOWN FOR ANY QUERY
PLEASE GIVE A THUMBS UP
I am working on this switch statement code and I am getting errors. Please help. import...
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...
I am trying to write a Geometry.java program but Dr.Java is giving me errors and I dont know what I am doing wrong. import java.util.Scanner; /** This program demonstrates static methods */ public class Geometry { public static void main(String[] args) { int choice; // The user's choice double value = 0; // The method's return value char letter; // The user's Y or N decision double radius; // The radius of the circle double length; // The length of...
Please make the following code modular. Therefore contained in a package with several classes and not just one. import java.util.*; public class Q { public static LinkedList<String> dogs = new LinkedList<String> (); public static LinkedList<String> cats = new LinkedList<String> (); public static LinkedList<String> animals = new LinkedList<String> (); public static void enqueueCats(){ System.out.println("Enter name"); Scanner sc=new Scanner(System.in); String name = sc.next(); cats.addLast(name); animals.addLast(name); } ...
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{...
Please, modify the code below to use the Switch Statements in Java instead of “if” statements to make the decisions. import java.util.Scanner; public class Area { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter code(C for circle, R for rectangle, S for square): "); char code = in.next().charAt(0); if(code == 'C') { System.out.print("Enter radius: "); double radius = in.nextDouble(); System.out.println("Area of circle is " + (Math.PI * radius * radius)); } else if(code == 'R') {...
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;...
Q: Create a version of the UnitConverter application to convert from inches to foot. Read the inches value from the user. A: import java.util.*; class UnitConverter{ public static void main(String[] args){ int inches; int foot; Scanner scan=new Scanner(System.in); System.out.println("Enter inches:"); inches=scan.nextInt(); System.out.println(inches/12+" feet and "+inches%12+" inches."); } } Q: Write a program that converts grams to pounds. (One pound equals 453.592 grams.) Read the grams value from the user as a floating point value. A: import java.util.*; class GramsToPounds{...
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;...
Below I have my 3 files. I am trying to make a dog array that aggerates with the human array. I want the users to be able to name the dogs and display the dog array but it isn't working. //Main File import java.util.*; import java.util.Scanner; public class Main { public static void main(String[] args) { System.out.print("There are 5 humans.\n"); array(); } public static String[] array() { //Let the user...
I keep getting this error and I do not know how to fix
it. this is the code I've been working on:
please help me
import java.util.*;
public class TelephoneNumber {
public static void main(String[] args)
{String number;
int i=0,j=0;
char c;
Scanner in=new Scanner (System.in);
System.out.println("Enter the phone number: ");
number=in.nextLine();
number=number.toUpperCase();
c=number.charAt(i);
while(c!='\n'&&j<=7)
{switch(c)
{case 'A':
case 'B':
case 'C':
System.out.print("2");
j++;
break;
case 'D':
case 'E':
case 'F':
System.out.print("3");
j++;
break;
case 'G':
case 'H':
case'I':
System.out.print("4");...