Java - "Cannot find symbol" error [closed] - java

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
It's my first time writing a class and I am getting all these errors:
C:\Users\Eamon\programming\java>javac -Xlint:unchecked Shop1.java
Shop1.java:20: error: cannot find symbol
if (cart.itemsInCart.products.get(itemIndex).quantity != 0)
^
symbol: variable quantity
location: class Object
Shop1.java:21: error: cannot find symbol
System.out.println(cart.itemsInCart.products.get(itemIndex).quantity
^
symbol: variable quantity
location: class Object
Shop1.java:22: error: cannot find symbol
+ " " + cart.itemsInCart.products.get(itemIndex).name
^
symbol: variable name
location: class Object
Shop1.java:23: error: cannot find symbol
+ " $"+ df.format(cart.itemsInCart.products.get(itemIndex).price)
^
symbol: variable price
location: class Object
Shop1.java:25: error: cannot find symbol
((cart.itemsInCart.products.get(itemIndex).quantity
^
symbol: variable quantity
location: class Object
Shop1.java:26: error: cannot find symbol
* cart.itemsInCart.products.get(itemIndex).price)));
^
symbol: variable price
location: class Object
Shop1.java:35: error: cannot find symbol
subtotal += cart.itemsInCart.products.get(itemIndex).quantity
^
symbol: variable quantity
location: class Object
Shop1.java:36: error: cannot find symbol
* cart.itemsInCart.products.get(itemIndex).price;
^
symbol: variable price
location: class Object
Shop1.java:126: error: cannot find symbol
if (codeInput.equals(this.itemsInCart.products.get(itemIndex).code))
^
symbol: variable code
location: class Object
Shop1.java:138: error: cannot find symbol
this.itemsInCart.products.get(itemIndex).quantity = scanner.nextInt();
^
symbol: variable quantity
location: class Object
Shop1.java:140: error: cannot find symbol
if (this.itemsInCart.products.get(itemIndex).quantity > 100)
^
symbol: variable quantity
location: class Object
Shop1.java:143: error: cannot find symbol
+ this.itemsInCart.products.get(itemIndex).quantity
^
symbol: variable quantity
location: class Object
Shop1.java:145: error: cannot find symbol
+ this.itemsInCart.products.get(itemIndex).quantity
^
symbol: variable quantity
location: class Object
Shop1.java:147: error: cannot find symbol
if (scanner.nextInt() != this.itemsInCart.products.get(itemIndex).quantity)
^
symbol: variable quantity
location: class Object
Shop1.java:148: error: cannot find symbol
this.item[itemIndex].quantity = 0;
^
symbol: variable item
Shop1.java:150: error: cannot find symbol
if (this.itemsInCart.products.get(itemIndex).quantity < 0)
^
symbol: variable quantity
location: class Object
Shop1.java:151: error: cannot find symbol
this.itemsInCart.products.get(itemIndex).quantity = 0;
^
symbol: variable quantity
location: class Object
Shop1.java:50: error: cannot find symbol
ArrayList products = new Arraylist<Product>(3);
^
symbol: class Arraylist
location: class Catalogue
Shop1.java:54: warning: [unchecked] unchecked call to add(E) as a member of the raw type ArrayList
products.add(new Product("Condensed Powdered water", "P3487", 2.50
^
where E is a type-variable:
E extends Object declared in class ArrayList
Shop1.java:56: warning: [unchecked] unchecked call to add(E) as a member of the raw type ArrayList
products.add(new Product("Distilled Moonbeams", "K3876", 3.00
^
where E is a type-variable:
E extends Object declared in class ArrayList
Shop1.java:58: warning: [unchecked] unchecked call to add(E) as a member of the raw type ArrayList
products.add(new Product("Anti-Gravity Pills", "Z9983", 12.75
^
where E is a type-variable:
E extends Object declared in class ArrayList
Shop1.java:80: error: Illegal static declaration in inner class Catalogue.Product
static final Pattern productCodeRegex =
^
modifier 'static' is only allowed in constant variable declarations
Shop1.java:83: error: Illegal static declaration in inner class Catalogue.Product
public static boolean isValidCode(String codeInput)
^
modifier 'static' is only allowed in constant variable declarations
Shop1.java:92: error: cannot find symbol
+ this.products.get(itemIndex).name
^
symbol: variable name
location: class Object
Shop1.java:93: error: cannot find symbol
+ " [" + this.products.get(itemIndex).code + "], $"
^
symbol: variable code
location: class Object
Shop1.java:94: error: cannot find symbol
+ df.format(this.products.get(itemIndex).price) + " "
^
symbol: variable price
location: class Object
Shop1.java:95: error: cannot find symbol
+ this.products.get(itemIndex).rate + ".");
^
symbol: variable rate
location: class Object
24 errors
3 warnings
I'm working my way back, and I can find those variables just fine; what gives?
import java.util.Scanner;
import java.util.ArrayList;
import java.util.regex.Pattern;
import java.text.DecimalFormat;
public class Shop1
{
public static void main(String args[])
{
Cart cart = new Cart(new Catalogue());
printOrder(cart);
}
public static void printOrder(Cart cart)
{
DecimalFormat df = new DecimalFormat("0.00");
System.out.println("Your order:");
for(int itemIndex = 0; itemIndex < cart.itemsInCart.products.size();
itemIndex++)
if (cart.itemsInCart.products.get(itemIndex).quantity != 0)
System.out.println(cart.itemsInCart.products.get(itemIndex).quantity
+ " " + cart.itemsInCart.products.get(itemIndex).name
+ " $"+ df.format(cart.itemsInCart.products.get(itemIndex).price)
+ " = $" + df.format
((cart.itemsInCart.products.get(itemIndex).quantity
* cart.itemsInCart.products.get(itemIndex).price)));
double subtotal = 0;
int taxPercent = 20;
double tax;
double total;
for(int itemIndex = 0; itemIndex < cart.itemsInCart.products.size();
itemIndex++)
subtotal += cart.itemsInCart.products.get(itemIndex).quantity
* cart.itemsInCart.products.get(itemIndex).price;
tax = subtotal * taxPercent / 100;
total = subtotal + tax;
System.out.print("Subtotal: $" + df.format(subtotal)
+ " Tax # " + taxPercent + "%: $" + df.format(tax)
+ " Grand Total: $" + df.format(total));
}
}
class Catalogue
{
DecimalFormat df = new DecimalFormat("0.00");
ArrayList products = new Arraylist<Product>(3);
public Catalogue()
{
products.add(new Product("Condensed Powdered water", "P3487", 2.50
, "per packet"));
products.add(new Product("Distilled Moonbeams", "K3876", 3.00
, "a dozen"));
products.add(new Product("Anti-Gravity Pills", "Z9983", 12.75
, "for 60"));
}
class Product
{
String name;
double price;
String code;
String rate;
int quantity;
public Product(String startName, String startCode, double startPrice
, String startRate)
{
name = startName;
code = startCode;
price = startPrice;
rate = startRate;
quantity = 0;
}
static final Pattern productCodeRegex =
Pattern.compile("^[a-zA-Z][0-9]{4}$");
public static boolean isValidCode(String codeInput)
{return productCodeRegex.matcher(codeInput).matches();}
}
public void printCatalogue()
{
System.out.println("Our catalogue (product codes in brackets):");
for(int itemIndex = 0; itemIndex < this.products.size(); itemIndex++)
System.out.println("(" + (itemIndex + 1) + ") "
+ this.products.get(itemIndex).name
+ " [" + this.products.get(itemIndex).code + "], $"
+ df.format(this.products.get(itemIndex).price) + " "
+ this.products.get(itemIndex).rate + ".");
System.out.println("Buy something!");
}
}
class Cart
{
Scanner scanner = new Scanner(System.in); //
int size = 3; //
String codeInput = "";
Catalogue itemsInCart;
public Cart(Catalogue catalogue)
{
itemsInCart = catalogue;
catalogue.printCatalogue();
this.selectProducts();
}
public void selectProducts()
{
while (true)
{
System.out.print("Enter product code (0 to check out): ");
codeInput = scanner.next();
scanner.nextLine();
if (codeInput.equals("0")) return;
for (int itemIndex = 0; itemIndex < this.itemsInCart.products.size();
itemIndex++)
if (codeInput.equals(this.itemsInCart.products.get(itemIndex).code))
this.addToCart(itemIndex);
if (Product.isValidCode(codeInput))
System.out.println("This product code is not on record.");
else System.out.println
("Sorry, I don't understand! Use product codes only.");
}
}
public void addToCart(int itemIndex)
{
System.out.print("Enter quantity: ");
this.itemsInCart.products.get(itemIndex).quantity = scanner.nextInt();
scanner.nextLine();
if (this.itemsInCart.products.get(itemIndex).quantity > 100)
{
System.out.print("That is a large order, "
+ this.itemsInCart.products.get(itemIndex).quantity
+ " counts. Is this correct? Enter \""
+ this.itemsInCart.products.get(itemIndex).quantity
+ "\" to confirm, or, enter any other integer to cancel: ");
if (scanner.nextInt() != this.itemsInCart.products.get(itemIndex).quantity)
this.item[itemIndex].quantity = 0;
}
if (this.itemsInCart.products.get(itemIndex).quantity < 0)
this.itemsInCart.products.get(itemIndex).quantity = 0;
}
}

In Catalogue, you need
ArrayList<Product> products = new ArrayList<Product>(3);
instead of
ArrayList products = new Arraylist<Product>(3);
or else the compiler does not know which type will be returned by
cart.itemsInCart.products.get(itemIndex)
Only if the compiler knows the returned type here is Product, he knows you can access the quantity field. If any type could be returned, it could be types were .quantity is not present or not accessible.
For future reference, please provide the code you are actually using, because yours wouldn't even compile. You have Arraylist where it should be ArrayList (Java is case sensitive). Also it is good practice to program against the interface, so it would be even better to write List<Product> products = new ArrayList<Product>(3);

From what I can see, some symbols you're trying to use could be inaccessible. Try defining each class in its own file, then making the symbols you want to use public and see if that resolves the issue. After that, you can structure your code in a better manner (that is, with getters and setters instead of direct access).
EDIT: My mistake. jlordo's answer is the correct one.

Related

Cannot find symbol when I've defined it already

I'm making a Guess the Number game, and this is my code for the game.
import java.util.Random;
import java.util.Scanner;
public class Guess {
public static void main(String[] args) {
int guess, diff;
Random random = new Random();
Scanner in = new Scanner(System.in);
int number = random.nextInt(100) + 1;
System.out.println("I'm thinking of a number between 1 and 100");
System.out.println("(including both). Can you guess what it is?");
System.out.print("Type a number: ");
guess = in.nextInt();
System.out.printf("Your guess is: %s", guess);
diff = number - guess;
printf("The number I was thinking of is: %d", guess);
printf("You were off by: %d", diff);
}
}
However, when I try to compile it, it comes up with the following error:
Guess.java:20: error: cannot find symbol
printf("The number I was thinking of is: %d", guess);
^
symbol: method printf(String,int)
location: class Guess
Guess.java:21: error: cannot find symbol
printf("You were off by: %d", diff);
^
symbol: method printf(String,int)
location: class Guess
2 errors
What is wrong with the code?
I assume you are trying to call the printf method of the System.out object. That would look like:
System.out.printf("You were off by: %d", diff);
You need to make the method call using the right object target: in general the method call syntax is "receiver . method name ( parameters )". If the receiver is the current object, it can be omitted.

How to solve these errors in vocareum

import java.util.Random;
import java.util.*;
public class WhackAMole {
int score;
int molesLeft;
int attemptsLeft;
char[][] molegrid;
int actualDimension;
WhackAMole(int numAttempts,int gridDimension){
this.attemptsLeft=numAttempts;
this.actualDimension=gridDimension;
score=0;
molesLeft=10;
molegrid=new char[10][10];
for(int i=0;i<gridDimension-1;i++) {
for(int j=0;j<gridDimension-1;j++) {
molegrid[i][j]='*';
}
}
}
boolean place(int x,int y) {
if((x<actualDimension && x>=0)&& (y<actualDimension && y>=0)) {
molegrid[x][y]='M';
return true;
}
else {
return false;
}
}
void whack(int x,int y) {
if(molegrid[x][y]=='M'){
score++;
molesLeft--;
attemptsLeft--;
molegrid[x][y]='W';
System.out.println("You have made a whack");
System.out.println("You have" +attemptsLeft+"remaining tries");
}
else {
attemptsLeft--;
System.out.println("You have" +attemptsLeft+"remaining tries");
System.out.println("("+x+","+y+") doesnt have a mole");
}
}
void printGridToUser() {
for(int i=0;i<actualDimension;i++)
{
for(int j=0;j<actualDimension;j++) {
if(molegrid[i][j]=='M') {
molegrid[i][j]='*';
System.out.print(molegrid[i][j] );
molegrid[i][j]='M';
}
else {
System.out.print(molegrid[i][j] );
}
}
System.out.print("\n");
}
}
void printGrid() {
for(int i=0;i<actualDimension;i++) {
for(int j=0;j<actualDimension;j++) {
System.out.print(molegrid[i][j]);
}
System.out.print("\n");
}
}
public static void main(String[] args) {
WhackAMole a=new WhackAMole(50,10);
for(int i=0;i<10;i++) {
Random randomGenerator = new Random();
Random randomGenerator1 = new Random();
int molelocationx= randomGenerator.nextInt(9);
int molelocationy= randomGenerator1.nextInt(9);
boolean b= a.place(molelocationx, molelocationy);
if(b==true) {
System.out.println("Mole placed");
}
else {
System.out.println("Mole not placed");
}
}
System.out.println("You have maximum 50 chances");
for(int j=0;j<50;j++) {
Scanner scanner=new Scanner(System.in);
System.out.println("Enter first coordinate");
int userlocx=scanner.nextInt();
Scanner scanner1=new Scanner(System.in);
System.out.println("Enter second coordinate");
int userlocy=scanner1.nextInt();
if(userlocx==-1 && userlocy==-1)
{
System.out.println("Exiting");
System.out.println("Your score is"+a.score);
a.printGrid();
System.exit(1);
}
else if(userlocx>9 || userlocx<-1 || userlocy>9 || userlocy<-1 ){
System.out.println("Invalid");
continue;
}
else {
a.whack(userlocx, userlocy);
a.printGridToUser();
if(a.molesLeft==0) {
System.out.println("You have won!!");
System.exit(2);
}
}
}
System.out.println("Game over try again next time");
}
}
ERRORS SHOWN
/WhackAMoleTestGrader.java:98: error: cannot find symbol
int actualRow = whack.moleGrid.length;
^
symbol: variable moleGrid
location: variable whack of type WhackAMole
/home/ccc_v1_c79431__48717/asn12900_Whack_a_Mole/asn12901_JUnit/asnlib/WhackAMoleTestGrader.java:102: error: cannot find symbol
int actualCol = whack.moleGrid[i].length;
^
symbol: variable moleGrid
location: variable whack of type WhackAMole
/home/ccc_v1_c79431__48717/asn12900_Whack_a_Mole/asn12901_JUnit/asnlib/WhackAMoleTestGrader.java:107: error: cannot find symbol
char actualChar = whack.moleGrid[i][j];
^
symbol: variable moleGrid
location: variable whack of type WhackAMole
/home/ccc_v1_c79431__48717/asn12900_Whack_a_Mole/asn12901_JUnit/asnlib/WhackAMoleTestGrader.java:123: error: cannot find symbol
char actualOneOne = whack.moleGrid[1][1];
^
symbol: variable moleGrid
location: variable whack of type WhackAMole
/home/ccc_v1_c79431__48717/asn12900_Whack_a_Mole/asn12901_JUnit/asnlib/WhackAMoleTestGrader.java:125: error: cannot find symbol
assertEquals("Expected char at (1, 2): M, but actual: " + whack.moleGrid[1][2], 'M', whack.moleGrid[1][2]);
^
symbol: variable moleGrid
location: variable whack of type WhackAMole
/home/ccc_v1_c79431__48717/asn12900_Whack_a_Mole/asn12901_JUnit/asnlib/WhackAMoleTestGrader.java:125: error: cannot find symbol
assertEquals("Expected char at (1, 2): M, but actual: " + whack.moleGrid[1][2], 'M', whack.moleGrid[1][2]);
^
symbol: variable moleGrid
location: variable whack of type WhackAMole
/home/ccc_v1_c79431__48717/asn12900_Whack_a_Mole/asn12901_JUnit/asnlib/WhackAMoleTestGrader.java:129: error: cannot find symbol
assertEquals("Mole placed at wrong place: (" + i + ", " + j + ")", '*', whack.moleGrid[i][j]);
^
symbol: variable moleGrid
location: variable whack of type WhackAMole
/home/ccc_v1_c79431__48717/asn12900_Whack_a_Mole/asn12901_JUnit/asnlib/WhackAMoleTestGrader.java:139: error: cannot find symbol
assertEquals("(1, 1) doesn't have a mole", 'M', whack.moleGrid[1][1]);
^
symbol: variable moleGrid
location: variable whack of type WhackAMole
8 errors
(Failed)
Command exited with non-zero status 1
I can compile you code and there is no errors.
1) There is no actualRow in your code, but it is first error. Others are the same...
I think you need to write code that would be called by testing program. And they assume you have actualRow and other. Read your task again...
2) It doesn't look like a java compiler output. It looks like code compiled with C++ or Python compiler. Check what language you have to use for submission OR maybe there is check-box for selecting language of your submit.

Java class error Main.java:3: error:

I keep getting this error message I have checked my file names, and my public class is the same as my .java file. Besides checking that I have no idea where to go.
Main.java:3: error: class ClassGenderPercentages is public, should be declared in a file named ClassGenderPercentages.java
public class ClassGenderPercentages
^
Here is my code
import java.util.Scanner;
public class ClassGenderPercentages
{
public static void main (String args[])
{
Scanner keyboard = new Scanner(System.in);
int maleStudents, femaleStudents;
int totalStudents;
double maleStudentPercentage, femaleStudentPercentage;
maleStudents = keyboard.nextInt();
System.out.println("Enter number of male registered:" + maleStudents);
femaleStudents = keyboard.nextInt();
System.out.println("Enter number of female registered:" + femaleStudents);
totalStudents = (int) (maleStudents + femaleStudents);
maleStudentPercentage = ((100 * maleStudents) / totalStudents);
femaleStudentPercentage = ((100 * femaleStudents) / totalStudents);
System.out.println("The percentage of males registered is: " + maleStudentPercentage + "%");
System.out.println("The percentage of females registed is: " + femaleStudentPercentage + "%");
}
}
Your files is named Main.java, your class ClassGenderPercentages.
You can rename your file to ClassGenderPercentages.java
(that is already said in the error you received from the compiler)

Troubles with Return this and #override programing

So first I'm gonna post the code then ill explain my problems
import java.util.*;
class Loader
{
protected int BucketSize;
protected int bucket;
protected int price;
public void SetBucketSize(int b)
{
Scanner input = new Scanner(System.in);
System.out.println("What Bucket Size (1-5)?");
bucket = input.nextInt();
while (bucket <6)
{
System.out.println("Enter valid Bucket Size(1-5)");
}
if (bucket == 1)
{
price = 100;
}
if (bucket == 2)
{
price = 200;
}
if (bucket == 3)
{
price = 300;
}
if (bucket == 4)
{
price = 400;
}
if (bucket == 5)
{
price = 500;
}
b = price;
price = BucketSize;
}
public void GetBucketSize()
{
return this.BucketSize;
}
#Override
public void setRentalProfit()
{
RentalProfit = (RentalRate * RentalDays);
}
#Override
public String toString() {
return "Tractor (Rental days = " + RentalDays + ", Rental Rate = " + RentalRate +
", Rental profit = " + RentalProfit + ", VehicleID = " + VehicleID + BucketSize + ")";
}
}
Heres the errors :
Loader.java:46: error: incompatible types: unexpected return value
return this.BucketSize;
^
Loader.java:49: error: method does not override or implement a method from a supertype
#Override
^
Loader.java:52: error: cannot find symbol
RentalProfit = (RentalRate * RentalDays);
^
symbol: variable RentalProfit
location: class Loader
Loader.java:52: error: cannot find symbol
RentalProfit = (RentalRate * RentalDays);
^
symbol: variable RentalRate
location: class Loader
Loader.java:52: error: cannot find symbol
RentalProfit = (RentalRate * RentalDays);
^
symbol: variable RentalDays
location: class Loader
Loader.java:57: error: cannot find symbol
return "Tractor (Rental days = " + RentalDays + ", Rental Rate = " + RentalRate +
Things like RentalDays and other variables are in another class I'm just stuck on what to do here. I can't figured out why its telling me the return thisBucketSize is an incompatible type and also I'm not sure why its not finding the RentalDays and variables that i have in another class in same final. any help/tips would be appreciated
The issue with "return thisBucketSize" is that it's in a method which has a void return type. The issue with the override annotation is that Loader doesn't extend our implement anything, so there is no superclass to override. The other issues appear to be undeclared variables.
As a side note, class names are usually uppercase while variables are lowercase.

Variable declared, compiler cannot find symbol

So for a project I'm working on this program. It's intended to take an input from the user and use it to convert the measurement. I'm getting these errors:
ConversionWilson.java:69: error: cannot find symbol
kilometers = meters * 0.001;
^
symbol: variable kilometers
location: class ConversionWilson
ConversionWilson.java:70: error: cannot find symbol
System.out.println(meters + " meters converted to kilometers becomes: " + kilometers + "km");
^
symbol: variable kilometers
location: class ConversionWilson
ConversionWilson.java:75: error: cannot find symbol
inches = meters * 39.37;
^
symbol: variable inches
location: class ConversionWilson
ConversionWilson.java:76: error: cannot find symbol
System.out.println(meters + " meters converted to inches becomes: " + inches + "in");
^
symbol: variable inches
location: class ConversionWilson
ConversionWilson.java:81: error: cannot find symbol
feet = meters * 3.281;
^
symbol: variable feet
location: class ConversionWilson
ConversionWilson.java:82: error: cannot find symbol
System.out.println(meters + " meters converted to feet becomes: " + feet + "ft");
^
symbol: variable feet
location: class ConversionWilson
ConversionWilson.java:87: error: cannot find symbol
switch (conversion)
^
symbol: variable conversion
location: class ConversionWilson
ConversionWilson.java:90: error: cannot find symbol
showKilometers(meters);
^
symbol: variable meters
location: class ConversionWilson
ConversionWilson.java:94: error: cannot find symbol
showInches(meters);
^
symbol: variable meters
location: class ConversionWilson
ConversionWilson.java:98: error: cannot find symbol
showFeet(meters);
^
symbol: variable meters
location: class ConversionWilson
10 errors
I have all the variables declared. Not sure what exactly it is that's going wrong.
double meters; // Distance as set by the user.
String input; // Input by the user.
char conversion; // Code for the type of conversion.
double kilometers; // The kilometers from the conversion.
double inches; // The inches from the conversion.
double feet; // The feet from the conversion.
// Scanner object to read input
Scanner keyboard = new Scanner (System.in);
// Prompt the user for distance and conversion.
System.out.println("Welcome to the Conversion Program.");
System.out.println("With this program, you can enter a distance and convert it to another form of measurement.");
System.out.print("Please enter the distance in meters: ");
if (meters >= 0)
{
meters = keyboard.nextDouble();
}
else
{
System.out.println("Meters cannot be a negative number. Please choose a positive number.");
}
System.out.print("Please enter the number of the conversion you want to make: \n" +
"1. Convert to Kilometers \n" + "2. Convert to Inches \n" + "3. Convert to Feet \n" +
"4. Quit Program");
input = keyboard.nextLine();
conversion = input.charAt(0);
// Deciding what conversion method to call.
switch (conversion)
{
case '1':
showKilometers(meters);
break;
case '2':
showInches(meters);
break;
case '3':
showFeet(meters);
break;
case '4':
System.out.println("Beep boop bop. Quitting the program now. Later.");
break;
default:
System.out.println("You did not select a possible choice. Please run the program again and be sure to choose a correct number.");
}
}
public static void showKilometers(double meters)
{
kilometers = meters * 0.001;
System.out.println(meters + " meters converted to kilometers becomes: " + kilometers + "km");
}
public static void showInches(double meters)
{
inches = meters * 39.37;
System.out.println(meters + " meters converted to inches becomes: " + inches + "in");
}
public static void showFeet(double meters)
{
feet = meters * 3.281;
System.out.println(meters + " meters converted to feet becomes: " + feet + "ft");
}
It must be something simple I'm just missing right?
You need to declare this variables as instance variable to be accessible within all your class methods.
I think that you have declared these variables inside you main method or one of your class method, so you need to move them out side the method.
public class MyClass {
private double meters; // Distance as set by the user.
private String input; // Input by the user.
private char conversion; // Code for the type of conversion.
private double kilometers; // The kilometers from the conversion.
private double inches; // The inches from the conversion.
private double feet; // The feet from the conversion.
public static void showKilometers(double meters)
{
kilometers = meters * 0.001;
System.out.println(meters + " meters converted to kilometers becomes: " + kilometers + "km");
}
}

Categories

Resources