Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Problem creating an instance(Harder than you think)

$
0
0
I understand that creating an instance of a class is very simple which it is, but I do not understand why I am having this error. The IDE keeps saying quote, "No enclosing instance of type ClassAndAbove1 is accessible. Must qualify the allocation with an enclosing instance of type ClassAndAbove1 (e.g. x.new A() where x is an instance of ClassAndAbove1)," where ClassAndAbove1 is the project name. Attached is a file with the code so you can pick apart the error if you so choose. The problem occurs at the bottom of the code,please help!

import java.io.*;
import java.util.*;
class gvars
{
	static float debt1;
	static float income1;
	static float tax1;
	static float payofftime1;
	static float interest1;
}
        public class ClassAndAbove1 {
	    public static void main(String[] args) {
		System.out.println("Amount of debt : ");
		float debt;
		Scanner debtfile = new Scanner(System.in);
		debt = debtfile.nextFloat();
		gvars.debt1 = debt;
		System.out.println("Amount of income : ");
		float income;
		Scanner incomefile = new Scanner(System.in);
		income = incomefile.nextFloat();
		gvars.income1 = income;
		System.out.println("Tax rate paid(In PERCENT form) : ");
		float taxrate;
		Scanner taxfile = new Scanner(System.in);
		taxrate = taxfile.nextFloat();
		float rawtax = taxrate/100;
		gvars.tax1 = rawtax;
		System.out.println("Unit of time for debt to be paid of in\n1: Months\n2: Years\n: ");
		int decision;
		Scanner timefile = new Scanner(System.in);
		decision = timefile.nextInt();
		if(decision == 1)
		{
			System.out.println("Enter number of months for debt to paid off in : ");
			float month;
			Scanner monthfile = new Scanner(System.in);
			month = monthfile.nextFloat();
			float payofftime = month/12;
			gvars.payofftime1 = payofftime;
		}
		else if(decision == 2)
		{
			System.out.println("Enter number of years(YEARS ONLY) for debt to be paid off in : ");
			float years;
			Scanner yearfile = new Scanner(System.in);
			years = yearfile.nextFloat();
			System.out.println("Enter number of months in addition to the years for debt to be paid off in : ");
			float decismonth;
			Scanner monthfile = new Scanner(System.in);
			decismonth = monthfile.nextFloat();
			float rawmonth = decismonth/12;
			float payofftime = years+rawmonth;
			gvars.payofftime1 = payofftime;
			}
		System.out.println("Amount of interest paid(In PERCENT) : ");
		float interest;
		Scanner intfile = new Scanner(System.in);
		interest = intfile.nextFloat();
		float  decint = interest/100;
		gvars.interest1 = decint;
		Financials action = new Financials();
	}
	class Financials
	{
		float debt = gvars.debt1;
		float income = gvars.income1;
		float tax = gvars.tax1;
		float payofftime = gvars.payofftime1;
		float interest = gvars.interest1;
	}
	}

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>