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.
Related
Here is the below code:
import comp102x.IO;
public class CalculatorEx01 {
public static void multiply() {
// Please write your code after this line
System.out.print("Enter an integer, x: ");
int x =IO.inputInt();
System.out.print("Enter an integer, y: ");
int y = IO.inputInt();
System.out.print("Answer = "+ (x*y));
}
}
And what does these errors mean?
[ERROR] cannot find symbol, symbol: method inputInt(), location: class comp102x.IO.
[ERROR] cannot find symbol, symbol: method inputInt(), location: class comp102x.IO.
How about using Scanner?
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
multiply();
}
public static void multiply() {
// Please write your code after this line
Scanner IO = new Scanner(System.in);
System.out.print("Enter an integer, x: ");
int x = IO.nextInt();
System.out.print("Enter an integer, y: ");
int y = IO.nextInt();
System.out.print("Answer = " + (x * y));
IO.close();
}
}
You are using a function (method)
inputInt()
which you haven't defined anywhere or isn't present in the import class which you have used , this what the error is trying to tell you.
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.
So I have been asked to create a program that can evaluate and print the value of...
0.1 + (0.1)^2 + (0.1)^3 . . . + (0.1)^n
using a while loop. So far I have
import java.util.Scanner;
class Power
{
public static void main(String[] args)
{
Double x;
Scanner input = new Scanner(System.in);
System.out.println("What is the maximum power of 0.1?");
x = input.nextLine;
Double n = 0.1;
Int exp = 1;
while (exp <= x)
{
Double Answer = Math.pow(n, exp); //Had to look this one up
exp++;
}
System.out.print(Answer);
}
}
I'm still having trouble trying to decode the following few Compile-time errors I am getting with this program.
Power.java:11: error: cannot find symbol
x = input.nextLine;
^
symbol: variable nextLine
location: variable input of type Scanner
Power.java:13: error: cannot find symbol
Int exp = 1;
^
symbol: class Int
location: class Power
Power.java:19: error: cannot find symbol
System.out.print(Answer);
^
symbol: variable Answer
location: class Power
Any fix? Thanks guys
~Andrew
Here you go:
import java.util.Scanner;
class Power
{
public static void main(String[] args)
{
Double x;
Scanner input = new Scanner(System.in);
System.out.println("What is the maximum power of 0.1?");
x = input.nextDouble(); //Use nextDouble to take in double
Double n = 0.1;
int exp = 1;
Double Answer = 0.0; //You have to declare Answer outside of the while loop below or else Answer will be undefined when you try to print it out in the last line.
while (exp <= x)
{
Answer = Math.pow(n, exp);
exp++;
}
System.out.print(Answer);
}
}
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.
This question already has answers here:
What does a "Cannot find symbol" or "Cannot resolve symbol" error mean?
(18 answers)
What does "Could not find or load main class" mean?
(61 answers)
Closed 2 years ago.
Here's the new coding that I re-did:
ThreeDPoint.java
public class ThreeDPoint{
private double x, y, z;
public threeDPoint(){
coordX=0;
coordY=0;
coordZ=0;
}
public threeDPoint(double x, double y, double z){
coordX = x;
coordY = y;
coordZ = z;
}
public double getCoord(double x, double y, double z){
return coordX;
return coordY;
return coordZ;
}
}
Main.java
import java.util.Scanner;
public class Main{
double coordX, coordY, coordZ;
public static void main(String[] args){
threeDPoint myThreeDPoint=new threeDPoint();
Scanner sc=new Scanner(System.in);
String coordX, coordY, coordZ;
System.out.println("Input Coordinate X");
myThreeDPoint.coordX(sc.nextDouble());
System.out.println("Input Coordinate Y");
myThreeDPoint.coordY(sc.nextDouble());
System.out.println("Input Coordinate Z");
myThreeDPoint.coordZ(sc.nextDouble());
}
}
It gave me these errors:
Build Output:
C:\Users\BurneySoo\Documents\Main.java:8: error: cannot find symbol
threeDPoint myThreeDPoint=new threeDPoint();
^
symbol: class threeDPoint
location: class Main
C:\Users\BurneySoo\Documents\Main.java:8: error: cannot find symbol
threeDPoint myThreeDPoint=new threeDPoint();
^
symbol: class threeDPoint
location: class Main
2 errors
General Output:
Error: Could not find or load main class Main
What am I doing wrong?
Thanks so very much for the codes Gagandeep. Somehow I tried them but it gave out more errors than what I had before.
C:\Users\BurneySoo\Documents\ThreeDPoint.java:5: error: invalid method declaration; return type required
public threeDPoint(){
^
C:\Users\BurneySoo\Documents\ThreeDPoint.java:11: error: invalid method declaration; return type required
public threeDPoint(double x, double y, double z){
^
C:\Users\BurneySoo\Documents\Main.java:14: error: cannot find symbol
myTreeDPoint.coordX(sc.nextLine());
^
symbol: variable myTreeDPoint
location: class Main
C:\Users\BurneySoo\Documents\Main.java:17: error: cannot find symbol
myTreeDPoint.coordY(sc.nextLine());
^
symbol: variable myTreeDPoint
location: class Main
C:\Users\BurneySoo\Documents\Main.java:20: error: cannot find symbol
myTreeDPoint.coordZ(sc.nextLine());
^
symbol: variable myTreeDPoint
location: class Main
C:\Users\BurneySoo\Documents\Main.java:22: error: non-static variable coordY cannot be referenced from a static context
myThreeDPoint.setCoord(coordX, coordY, coordZ);
^
C:\Users\BurneySoo\Documents\Main.java:22: error: non-static variable coordZ cannot be referenced from a static context
myThreeDPoint.setCoord(coordX, coordY, coordZ);
^
C:\Users\BurneySoo\Documents\Main.java:22: error: method setCoord in class ThreeDPoint cannot be applied to given types;
myThreeDPoint.setCoord(coordX, coordY, coordZ);
^
required: double,double,double
found: String,double,double
reason: actual argument String cannot be converted to double by method invocation conversion
C:\Users\BurneySoo\Documents\ThreeDPoint.java:6: error: cannot find symbol
coordX=0;
^
symbol: variable coordX
location: class ThreeDPoint
C:\Users\BurneySoo\Documents\ThreeDPoint.java:7: error: cannot find symbol
coordY=0;
^
symbol: variable coordY
location: class ThreeDPoint
C:\Users\BurneySoo\Documents\ThreeDPoint.java:8: error: cannot find symbol
coordZ=0;
^
symbol: variable coordZ
location: class ThreeDPoint
C:\Users\BurneySoo\Documents\ThreeDPoint.java:12: error: cannot find symbol
coordX = x;
^
symbol: variable coordX
location: class ThreeDPoint
C:\Users\BurneySoo\Documents\ThreeDPoint.java:13: error: cannot find symbol
coordY = y;
^
symbol: variable coordY
location: class ThreeDPoint
C:\Users\BurneySoo\Documents\ThreeDPoint.java:14: error: cannot find symbol
coordZ = z;
^
symbol: variable coordZ
location: class ThreeDPoint
14 errors
And It still won't prompt me to input coordinate X in the general output.
it only gave me:
Error: Could not find or load main class Main
The problem here is that you are not calling a constructor, you're trying to call a method.
Make a constructor for your threeDPoint class, and then use a setter to set the field coordX. You can't call
threeDPoint myThreeDPoint=new coordX();
Because this is a method, not a constructor. What you want is in your threeDPoint class a constructor like so:
public threeDPoint(args){
//dostuff
}
and then a setter to set your Coords like
public void setCoordx(double coordx){
this.coordx = coordx}
Also, as a matter of Data hiding, make sure to delcare your fields as private or protected.
protected double coordX;
You have to write
threeDPoint myThreeDPoint=new threeDPoint("Send Arguments Here");
inside your main method, to make an object, now using this object you have to access your method myThreeDPoint.coordX(11.11);
Change your ThreeDPoint class to this :
public class ThreeDPoint
{
private double x, y, z;
public ThreeDPoint()
{
this.x = 0;
this.y = 0;
this.z = 0;
}
public ThreeDPoint(double x, double y, double z)
{
this.x = x;
this.y = y;
this.z = z;
}
public double getCoordX()
{
return this.x;
}
public double getCoordY()
{
return this.y;
}
public double getCoordZ()
{
return this.z;
}
}
Now make objects of this class as
ThreeDPoint myThreeDPoint = new ThreeDPoint();
So your Main Class will look like this :
import java.util.Scanner;
public class Main
{
double coordX, coordY, coordZ;
public static void main(String[] args)
{
ThreeDPoint myThreeDPoint = new ThreeDPoint();
Scanner sc=new Scanner(System.in);
String coordX, coordY, coordZ;
System.out.println("Input Coordinate X");
coordX = sc.nextDouble();
System.out.println("Input Coordinate Y");
coordY = sc.nextDouble();
System.out.println("Input Coordinate Z");
coordZ = sc.nextDouble();
// This will initialize your Constructor with Arguments.
ThreeDPoint myThreeDPointArgConst = new ThreeDPoint(coordX, coordY, coordZ);
coordX = myThreeDPointArgConst.getCoordX();
System.out.println("Co-ordinate X is : " + coordX);
coordY = myThreeDPointArgConst.getCoordY();
System.out.println("Co-ordinate Y is : " + coordY);
coordZ = myThreeDPointArgConst.getCoordZ();
System.out.println("Co-ordinate Z is : " + coordZ);
// This will initialize the no-arg constructor.
ThreeDPoint myThreeDPoint = new ThreeDPoint();
coordX = myThreeDPoint.getCoordX();
System.out.println("Co-ordinate X is : " + coordX);
coordY = myThreeDPoint.getCoordY();
System.out.println("Co-ordinate Y is : " + coordY);
coordZ = myThreeDPoint.getCoordZ();
System.out.println("Co-ordinate Z is : " + coordZ);
}
}