Hi,

Sorry for coming back again and adv thanks for guidance

My tutor gave me a assignment, couple of days before he taught me the work flow of java in eclipse, i am getting through it and i was asked to use constructors for the arithmetic operations as methods in Business location package and choice making, assigning the method as per choice code should be in presentation location package,

Now when i run these packages in cmd compiler says the business package is not available but in eclipse it says "field is not available", i don't even know how right my code could be,


Please tell what was the mistakes i did and i am i following the right way?,

package Business;

public class FirstJavaec{

	int a,c,y;
	int b, x, res;
		
	public FirstJavaec(){
		System.out.println("Inside default constructor");
		a=10;
	}

	public int multi(int x, int b, int res){
		
		res =  x*b;
		return res;
	}
	
	public int addition(int x, int b, int res){
		
		res =  x+b;
		return res;
	}
	public int subtract(int x, int b, int res){
		
		res =  x-b;
		return res;
	}
	public int div(int x, int b, int res){
		
		res =  x/b;
		return res;
	}
	public double module(double x, double b, double res){
		
		res =  x/b;
		return res;
	}

}
package Presentation;

import java.util.*;
import Business.*;


public class OperationsPresent {
	
	public static void main(String[] args) {
		String choice;
		int x, b, res;
		
	FirstJavaec obj = new FirstJavaec();
	obj.multi(x,b,res);
	int multi = obj.multi(x, b, res);
	
	Scanner Scanner = new Scanner(System.in);

	System.out.println("Enter 1 for Multiplication");
	System.out.println("or 2 for Subtraction");
	System.out.println("or 3 for Division");
	System.out.println("or 4 for Module");
	System.out.println("or 5 for Addition");
	System.out.println("or your Choice from 1 - 5 " +choice);
	choice = Scanner.nextLine();
	System.out.println("Enter the First Value" +x);
	x = Scanner.nextInt();
	System.out.println("Enter the Second Value" +b);
	b = Scanner.nextInt();
		
	if(choice=="1"){
		obj.multi(x, b, res);
		obj.res = obj.x * obj.b;
		}

	}

}

Ecplise :Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The field FirstJavaec.res is not visible
The field FirstJavaec.x is not visible
The field FirstJavaec.b is not visible

at Presentation.OperationsPresent.main(OperationsPresent.java:33)

Happen to get the solution from my co-worker

package Business;

public class FirstJavaec{

	int a;
	int res;
		
	public FirstJavaec(){
		System.out.println("Inside default constructor");
		a=10;
	}

	public int multi(int x, int b){
		
		res =  x*b;
		return res;
	}
	
	public int addition(int x, int b){
		
		res =  x+b;
		return res;
	}
	public int subtract(int x, int b){
		
		res =  x-b;
		return res;
	}
	public int div(int x, int b){
		
		res =  x/b;
		return res;
	}
	public double mod(double x, double b){
		
		
		return x%b ;
	}

}
package Presentation;

import java.util.*;
import Business.*;


public class OperationsPresent {
	
	
	public static void main(String[] args) {
		String choice;
		int x, b;
		
	FirstJavaec obj = new FirstJavaec();
	Scanner Scanner = new Scanner(System.in);

	System.out.println("Enter 1 for Multiplication");
	System.out.println("or 2 for Addition");
	System.out.println("or 3 for Subtract");
	System.out.println("or 4 for Division");
	System.out.println("or 5 for Mod");
	System.out.println("or your Choice from 1 - 5 ");
	choice = Scanner.nextLine();
	System.out.println("Enter the First Value: ");
	x = Scanner.nextInt();
	System.out.println("Enter the Second Value: " );
	b = Scanner.nextInt();
		
	
	
	switch (Integer.parseInt(choice)) {
	case 1:
		System.out.println("result :" +obj.multi(x, b));
		break;
	case 2:
		System.out.println("result :" +obj.addition(x, b));
		break;
	case 3:		
		System.out.println("result :" +obj.subtract(x, b));
		break;
	case 4:
		System.out.println("result :" +obj.div(x, b));
		break;
	case 5:
		System.out.println("result :" +obj.mod(x, b));
		break;

	default:
		System.out.println("returns nothing");
		break;
	}

	}

}

hi,I'm also with this problem recently,and I change the type of Parameters to "protected",and it disappeared,hope to be helpful to you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.