I am experiencing a strange error after I compile and run my program. I believe that these are called run time errors? Is that correct? The program compiles perfectly, all of the classes included. When I open the compiled program, I am prompted (correctly) to enter all information and after that when the program is supposed to print out the final output I receive a pop up error message ( with a yellow exclamation point on the java coffee cup) that says " The Java Class file 'Employee10.java' could not be launched. Check console for possible error messages. " Does anyone know why I am getting this message if the rest of the program runs correctly? Is my print statement not correct? Below I have added all the classes just incase the error isn't necessarily in Employee10.java. If anyone can help at all with this I would be very grateful. I am new to Java programing and could really use the help and guidance. Thank you very much all.
Here is Employee10
public class Employee10
{
public static void main ( String[] args )
{
System.out.println("Begin Program");
Employee e1 = new Employee();
Employee[] arr = new Employee[2];
int j = 0;
for ( int i=0; i < 3; i++)
{
arr[0] = e1;
String nameF = Input.getString("Please enter a First Name");
String nameL = Input.getString("Please enter a Last Name");
int Number = Input.getInt("Please enter an Employee Number");
String Street = Input.getString("Please enter a Street address");
String City = Input.getString("Please enter a City");
String State = Input.getString("Please enter a State");
double Zip = Input.getDouble("Please enter a Zip Code");
int Month = Input.getInt("Please enter a Month in numbers");
int Day = Input.getInt("Please enter a Day");
int Year = Input.getInt("Please enter a Year");
e1.setNumber(Number);
e1.setName( new Name(nameF, nameL));
e1.setAddress(new Address(Street, City, State, Zip));
e1.setHireDate(new Date(Month, Day, Year));
System.out.println(e1.getEmployeeString());
arr[i] = e1;
}
for ( j=0; j < arr.length; j++ )
{
System.out.println( arr[j].getEmployeeString() );
}
}
}
Here is Employee
public class Employee
{
private int Number;
Name name;
Address address;
Date HireDate;
public void setNumber ( int N )
{
Number = N;
}
public void setName ( Name n )
{
name = n;
}
public void setAddress ( Address a )
{
address = a;
}
public void setHireDate ( Date h )
{
HireDate = h;
}
public String getEmployeeString()
{
return name.getNameString() + Number + address + HireDate;
}
}
Here is Date
public class Date
{
private int month;
private int day;
private int year;
public Date() { month = 0; day = 0; year = 0; }
public void setDate( int m, int d, int y )
{
month = m; day = d; year = y;
}
public String getDateString()
{
return month + "/" + day + "/" + year;
}
public Date( int m, int d, int y )
{
month = m;
day = d;
year = y;
}
}
Here is Name
public class Name
{
private String NameF;
private String NameL;
public void setNameF ( String F )
{
NameF = F;
}
public void setNameL ( String L )
{
NameL = L;
}
public String getNameString ()
{
return NameF + NameL;
}
public Name ( String F, String L )
{
NameF = F;
NameL = L;
}
public Name ()
{
NameF = "John";
NameL = "Doe";
}
}
Here is Address
public class Address
{
private String Street;
private String City;
private String State;
private double Zip;
public void setStreet ( String s )
{
Street = s;
}
public void setCity ( String c )
{
City = c;
}
public void setState ( String T )
{
State = T;
}
public void setZip ( double z )
{
Zip = z;
}
public String GetAddressString ()
{
return Street + City + State + Zip;
}
public Address ( String s, String c, String T, double z )
{
Street = s;
City = c;
State = T;
Zip = z;
}
public Address ()
{
Street = "No street";
City = " No City";
State = "No state";
Zip = 00000;
}
}
Here is Input
import javax.swing.*;
public class Input
{
public static byte getByte( String s )
{
String input = JOptionPane.showInputDialog( s );
return Byte.parseByte( input );
}
public static short getShort( String s )
{
String input = JOptionPane.showInputDialog( s );
return Short.parseShort( input );
}
public static int getInt( String s )
{
String input = JOptionPane.showInputDialog( s );
return Integer.parseInt( input );
}
public static long getLong( String s )
{
String input = JOptionPane.showInputDialog( s );
return Long.parseLong( input );
}
public static float getFloat( String s )
{
String input = JOptionPane.showInputDialog( s );
return Float.parseFloat( input );
}
public static double getDouble( String s )
{
String input = JOptionPane.showInputDialog( s );
return Double.parseDouble( input );
}
public static boolean getBoolean( String s )
{
String input = JOptionPane.showInputDialog( s );
return Boolean.parseBoolean( input );
}
public static char getChar( String s )
{
String input = JOptionPane.showInputDialog( s );
return input.charAt(0);
}
public static String getString( String s )
{
String input = JOptionPane.showInputDialog( s );
return input;
}
}
In Employee class file can you replace
public String getEmployeeString()
{
return name.getNameString() + Number + address + HireDate;
}
with
public String getEmployeeString()
{
return name.getNameString() + Number + address.GetAddressString() + HireDate.getDateString();
}
Related
I don't know what I'm doing and would appreciate any help.
I'm reading a text file with the following code:
7
10 416-555-6667 Burgess Smith 15
15 905-777-8888 Thomas Patel 10
20 905-111-2222 Morris J. Stevenson 5
25 416-222-3333 Spencer Larson 30
30 416-333-4444 Adams Doe 18
35 905-122-5454 Price Hanks 15
40 905-343-5151 Clement L. Webster 8
private static void fileReader() throws FileNotFoundException
{
int eId = 0;
String nme = "";
String phne = "";
int yrs = 0;
String line ="";
Employee emp = new Employee(eId, nme, phne, yrs);
File inputfile = new File("Emp.txt");
Scanner in = new Scanner(inputfile);
n = in.nextInt() - 1;
in.nextLine();
in.useDelimiter("");
for (int i=0;i<=n;i++)
{
int l = 0;
int m = 0;
int n = 0;
line = in.nextLine();
while (Character.isDigit(line.charAt(l)))
{
l++;
}
m = l + 1;
while (!Character.isLetter(line.charAt(m)) && !Character.isWhitespace(line.charAt(m)))
{
m++;
}
n = m + 1;
while (!Character.isDigit(line.charAt(n)))
{
n++;
}
eId = Integer.parseInt(line.substring(0, l));
emp.setEmpId(eId);
phne = line.substring(l + 1, m - 1);
emp.setTelephone(phne);
nme = line.substring(m + 1, n - 1);
emp.setName(nme);
yrs = Integer.parseInt(line.substring(n));
emp.setYears(yrs);
empArr.add(i, emp);
}
in.close();
}
class for set and get methods:
public class Employee
{
private int empId;
private String telephone;
private String name;
private int yearsOfWork;
public Employee(int id, String name, String telephone, int yearsOfWork)
{
empId = id;
this.telephone = telephone;
this.name = name;
this.yearsOfWork = yearsOfWork;
}
public void setEmpId(int id)
{
empId = id;
}
public void setName(String name)
{
this.name = name;
}
public void setTelephone(String telephone)
{
this.telephone = telephone;
}
public void setYears(int years)
{
yearsOfWork = years;
}
public int getEmpId()
{
return empId;
}
public String getName()
{
return name;
}
public String getTelephone()
{
return telephone;
}
public int getYears()
{
return yearsOfWork;
}
public String toString()
{
return "ID:" + empId + ", name: " + name + ", phone: " + telephone + ", years of work: " + yearsOfWork + "\n";
}
}
When I call the get method of my ArrayList outside of its for loop, the text at each index is overwritten by the text at the last index.
I think I'm missing some fundamental concept of constructors and objects here.
Any help is appreciated. Thanks.
Your hunch is correct, you are missing the emp object creation. You have to move the emp object creation into the loop.
Your Employee class and getter/setter methods are correctly written.
Rewrite your fileReader() method similar to given below : -
String line ="";
//Declare an Arraylist for an Employee
List<Employee> employee = new ArrayList<Employee>();
//Read a file
File inputfile = new File("Emp.txt file path");
Scanner in = new Scanner(inputfile);
//Reading a number from a first sentence
int n = Integer.parseInt(in.nextLine());
for (int i=0;i<n;i++) {
// Reading each sentence
line = in.nextLine();
//Parse an Emp id
int eId = Integer.parseInt(line.substring(0, 2));
//Parse a phone number
String phone = line.substring(3, 14);
//Parse a name
String name = line.split("\\d+")[4];
//Parse years
int years = Integer.parseInt(line.split("\\D+")[4]);
//Now create an object by putting all above values in a constructor
Employee emp1 = new Employee(eId, name, phone, years);
//Add that object in an arraylist
employee.add(emp1);
}
//As you have overridden toString method, print an arraylist
System.out.println(emp.toString());
//Closing the scanner
in.close();
}
Hope this helps.
I made a program which stores movie names, hour and time of showing.
I saved the details inputted to arrays and then saved the arrays by getter and setter methods as a record.
In my final method i attempt to use a for loop to print out the details stored in the records but constantly get errors.
Any help to where the issue is would be greatly appreciated.
//Demonstrates usage of loops/adt/gettersetters
import java.util.Scanner;
class movies {
public static void main(String[] p) {
Movie m = new Movie();
int[] screenn = new int[4];
int[] namee = new int[4];
int[] hourr = new int[4];
int[] minn = new int[4];
for (int i = 0; i < 4; i++) {
screenn[i] = i + 1;
String moviename = input("Film for screen " + (i + 1));
namee[i] = moviename;
int moviehour = inputint("what hour does it start?");
hourr[i] = moviehour;
int moviemin = inputint("what min does it start?");
minn[i] = moviemin;
}
sethour(m, namee);
setmin(m, minn);
setscreen(m, screen);
setname(m, namee);
showtime(m);
System.exit(0);
}
//Getter Method
public static String[] getname(Movie m) {
return m.name;
}
public static int[] getscreen(Movie m) {
return m.screen;
}
public static int[] gethour(Movie m) {
return m.hour;
}
public static int[] getmin(Movie m) {
return m.min;
}
//Setter Method
public static Movie sethour(Movie m, int[] hour) {
m.hour = hour;
return m;
}
public static Movie setmin(Movie m, int[] min) {
m.min = min;
return m;
}
public static Movie setname(Movie m, String[] name) {
m.name = name;
return m;
}
public static Movie setscreen(Movie m, int[] screen) {
m.screen = screen;
return m;
}
public static String input(String message) {
Scanner scanner = new Scanner(System.in);
print(message);
String answer = scanner.nextLine();
return answer;
}
public static String print(String message) {
System.out.println(message);
return message;
}
public static int inputint(String message) {
int number = Integer.parseInt(input(message));
return number;
}
public static void showtime(movie m) {
print("Cineworld Movies For Tonight");
for (int i = 0; i < 4; i++) {
print("");
print(m.screen[i]);
print(m.movie[i]);
print(m.hour[i]);
print(m.min[i]);
}
}
}
class Movie {
String[] name = new String[4];
int[] hour = new int[4];
int[] min = new int[4];
int[] screen = new int[4];
}
You are getting your assignment wrong. According to OOP The Movie class should store Movie's properties (name, hour, mins, etc) and then on your MainProgram you should store an array of movies. How you create and the usage of these objects is not concern of the class it self. Having said that i re-implemented your mainProgram to:
Ask for each (4) movie attributes.
Create the movie.
add it to a list of movies.
for each movie (4) print its properties.
MovieClass:
public class Movie
{
String name;
int hour , min , screen;
public Movie ( )
{
super ( );
}
public Movie ( String name , int hour , int min , int screen )
{
super ( );
this.name = name;
this.hour = hour;
this.min = min;
this.screen = screen;
}
public String getName ( )
{
return name;
}
public void setName ( String name )
{
this.name = name;
}
public int getHour ( )
{
return hour;
}
public void setHour ( int hour )
{
this.hour = hour;
}
public int getMin ( )
{
return min;
}
public void setMin ( int min )
{
this.min = min;
}
public int getScreen ( )
{
return screen;
}
public void setScreen ( int screen )
{
this.screen = screen;
}
#Override
public String toString ( )
{
return "Movie [name=" + name + ", hour=" + hour + ", min=" + min + ", screen=" + screen
+ "]";
}
}
MainProgram:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class MainProgram
{
public static void main ( String [ ] args )
{
List < Movie > movieList = new ArrayList < Movie > ( );
for(int i = 1; i <= 4; i++ )
{
int screen = i;
String name = inputString ( "Film for screen "+(i));
int hour = inputInt ("what hour does it start?");
int min = inputInt ("what min does it start?");
Movie movie = new Movie ( name , hour , min , screen );
movieList.add ( movie );
}
print("Cineworld Movies For Tonight");
for( Movie movie : movieList)
{
print ( "" );
print ( Integer.toString ( movie.getScreen ( ) ));
print (movie.getName ( ));
print (Integer.toString ( movie.getHour ( ) ));
print ( Integer.toString ( movie.getMin ( ) ));
}
}
public static String inputString ( String message )
{
Scanner scanner = new Scanner ( System.in );
print ( message );
String answer = scanner.nextLine ( );
return answer;
}
public static String print ( String message )
{
System.out.println ( message );
return message;
}
public static int inputInt ( String message )
{
int number = Integer.parseInt ( inputString ( message ) );
return number;
}
}
Note: as you can see i re-used some of your static methods but if you need something else you have to implement it by yourself.
I/O Example:
Film for screen 1
The Shawshank Redemption
what hour does it start?
19
what min does it start?
30
Film for screen 2
The Godfather
what hour does it start?
20
what min does it start?
15
Film for screen 3
The Godfather: Part II
what hour does it start?
20
what min does it start?
30
Film for screen 4
The Dark Knight
what hour does it start?
21
what min does it start?
15
Cineworld Movies For Tonight
1
The Shawshank Redemption
19
30
2
The Godfather
20
15
3
The Godfather: Part II
20
30
4
The Dark Knight
21
15
Hope it helps.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
so what I'm trying to do is create a menu of food items with ArrayLists. My task is to complete the following definition of the static method profits that inputs an ArrayList items of MenuItems and returns an array of doubles. Each entry in the output is the difference between the price and the cost of the corresponding element of items. I have to process the result of each calculation involving money using the static method roundMoney.
public class MenuItem
{
private String myName;
private double myPrice,
myCost;
private int myCode;
private boolean myAvailability;
public MenuItem( String name, double price, double cost, int code, boolean available )
{
myName = name;
myPrice = price;
myCost = cost;
myCode = code;
myAvailability = available;
}
public String getName() { return myName; }
public double getPrice() { return myPrice; }
public double getCost() { return myCost; }
public int getCode() { return myCode; }
public boolean available() { return myAvailability; }
public String menuString()
{
return getName() + " ($" + getPrice() + ")";
}
public static double roundMoney( double amount )
{
return (int)(100 * amount + 0.5) / 100.0;
}
public static String printAmount( double d )
{
String s = "" + d;
int k = s.indexOf( "." );
if ( k < 0 )
return s + ".00";
if ( k + 1 == s.length() )
return s + "00";
if ( k + 2 == s.length() )
return s + "0";
else
return s;
}
}
//***********************************************************************
public static double[] Profits(ArrayList<MenuItem> items)
{
double[] profits = new double[items.size()];
for (int i = 0; i < profits.length; i++)
{
profits[i] = roundMoney (items.get(i).getPrice() - items.get(i).getCost());
}
return profits;
}
//***********************************************************************
public static void main( String[] args )
{
ArrayList<MenuItem> items1 = new ArrayList<MenuItem>();
items1.add( new MenuItem("Stir Fry",5.43,0.45,1,true) );
items1.add( new MenuItem("Nachos",3.49,0.15,0,false) );
items1.add( new MenuItem("Mud Pie",6.50,1.25,2,true) );
items1.add( new MenuItem("Jerk Chicken",8.99,3.20,1,false) );
double[] t = profits( items1 );
for ( double d : t )
System.out.print( printAmount( d ) + " " );
}
My expected result is: 4.98 3.34 5.25 5.79, but I keep receiving the error: TC1.java:30: error: cannot find symbol
double[] t = profits( items1 );
Could somebody please help me figure out what's wrong? Thank you!
You define your function profits with a capital "P."
public static double[] Profits(ArrayList<MenuItem> items)
Change the line with the error to match the name of the function:
double[] t = Profits( items1 );
There is a sytanx issue for the MenuItem.java
Try running the below program.
package com.stackoverflow;
import java.util.ArrayList;
public class MenuItem
{
private String myName;
private double myPrice,
myCost;
private int myCode;
private boolean myAvailability;
public MenuItem( String name, double price, double cost, int code, boolean available )
{
myName = name;
myPrice = price;
myCost = cost;
myCode = code;
myAvailability = available;
}
public String getName() { return myName; }
public double getPrice() { return myPrice; }
public double getCost() { return myCost; }
public int getCode() { return myCode; }
public boolean available() { return myAvailability; }
public String menuString()
{
return getName() + " ($" + getPrice() + ")";
}
public static double roundMoney( double amount )
{
return (int)(100 * amount + 0.5) / 100.0;
}
public static String printAmount( double d )
{
String s = "" + d;
int k = s.indexOf( "." );
if ( k < 0 )
return s + ".00";
if ( k + 1 == s.length() )
return s + "00";
if ( k + 2 == s.length() )
return s + "0";
else
return s;
}
//***********************************************************************
public static double[] profits(ArrayList<MenuItem> items)
{
double[] profits = new double[items.size()];
for (int i = 0; i < profits.length; i++)
{
profits[i] = roundMoney (items.get(i).getPrice() - items.get(i).getCost());
}
return profits;
}
//***********************************************************************
public static void main( String[] args )
{
ArrayList<MenuItem> items1 = new ArrayList<MenuItem>();
items1.add( new MenuItem("Stir Fry",5.43,0.45,1,true) );
items1.add( new MenuItem("Nachos",3.49,0.15,0,false) );
items1.add( new MenuItem("Mud Pie",6.50,1.25,2,true) );
items1.add( new MenuItem("Jerk Chicken",8.99,3.20,1,false) );
double[] t = profits( items1 );
for ( double d : t )
System.out.print( printAmount( d ) + " " );
}
}
The following code should produce a program that allows one to search for people in an address book, but I'm having some issues with the following lines of code marked. I don't think I'm missing a class...This is odd.
I'm fairly new in java so I apologize if this is basic.
Apparently BinarySearchTree can't be resolved to a type
import java.util.Scanner;
import java.io.*;
public class useBinarySearchTree
{
public static void main (String[] args)
{
BinarySearchTee<AddrEntry> addrbook = new BinarySearchTree<AddrEntry>();// error exists here
AddrEntry inentry, tentry;
String nameLook;
Scanner keybd = new Scanner(System.in);
String again;
final int INORDER = 1;
int numentries;
int i;
int ok;
// create address book from input file
buildAddrBook(addrbook);
do
{
// prompt user for name to look up
System.out.println("Address/Phone Lookup:\n" + "Enter name: ");
nameLook = keybd.nextLine();
inentry = new AddrEntry(nameLook, null, null, null);
tentry = addrbook.get(inentry);
if (tentry != null)
{
// print the address book entry
System.out.println("\nAddress Book Entry\n");
System.out.println("__________________\n");
System.out.println(tentry);
System.out.println();
}
else
{
// if the person is not in the book, see if they should be added
System.out.println("\n" + nameLook + " not found in address book\n");
System.out.println("\nWould you like to add this person? [y or n] => ");
again = keybd.nextLine();
System.out.println(again);
if (again.equals("Y") || again.equals("y"))
addEntry(addrbook, keybd);
}
System.out.println("\nAnother Lookup? [y or n] => ");
again = keybd.nextLine();
}
while (again.equals("Y") || again.equals("y"));
// prompt the user to see if they want to see the entire address book before exiting
System.out.println("\nPrint the address book? [y or n] => ");
again = keybd.nextLine();
if (again.equals("Y") || again.equals("y"))
{
System.out.println();
numentries = addrbook.reset(INORDER);
for (i = 1; i <= numentries; i++)
{
tentry = addrbook.getNext(INORDER);
System.out.println(tentry);
}
}
}
// read entries from file and insert them into the address book
public static void buildAddrBook (BinarySearchTree<AddrEntry> addrbook)// here as well {
AddrEntry hold;
String name;
String street;
String town;
String phone;
int ok = 1;
try
{
FileReader freader = new FileReader("addrbook.dat");
BufferedReader addresses = new BufferedReader(freader);
name = addresses.readLine();
while (name != null)
{
street = addresses.readLine();
town = addresses.readLine();
phone = addresses.readLine();
hold = new AddrEntry(name, street, town, phone);
addrbook.add(hold);
name = addresses.readLine();
}
}
catch(
Exception e
)
{
}
}
// add a new entry to the address book
public static void addEntry (BinarySearchTree<AddrEntry> addrbook, Scanner keybd)//also here {
int ok;
AddrEntry hold;
String name;
String street;
String town;
String phone;
System.out.println("\nEnter name: ");
name=keybd.nextLine();
System.out.println("Enter street address: ");
street=keybd.nextLine();
System.out.println("Enter town, state, and zip: ");
town=keybd.nextLine();
System.out.println("Enter phone number: ");
phone=keybd.nextLine();
hold=new
AddrEntry (name, street, town, phone);
addrbook.add(hold);
}
AddrEntry class
public class AddrEntry implements Comparable<AddrEntry> {
private String name;
private String street;
private String town;
private String phone;
public AddrEntry() {}
public AddrEntry(String nn, String st, String tt, String ph) {
name = nn;
street = st;
town = tt;
phone = ph;
}
public void setEntry(String nn, String st, String tt, String ph) {
name = nn;
street = st;
town = tt;
phone = ph;
}
public String toString() {
return name + "\n" + street + "\n" + town + "\n" + phone;
}
public boolean equals(Object ptest) {
if (ptest == null || !(ptest instanceof AddrEntry))
return false;
return this.name.equals(((AddrEntry)ptest).name) &&
this.street.equals(((AddrEntry)ptest).street) &&
this.town.equals(((AddrEntry)ptest).town) &&
this.phone.equals(((AddrEntry)ptest).phone);
}
public int compareTo(AddrEntry ent) {
return name.compareTo(ent.name);
}
}
So, i was using some variables in my methods but I get errors and I dont know how to fix this heres my code from my first class:
import java.util.Scanner;
public class Gerbilfood {
public static void main(String[] args) {
Gerbil[] gerbil;
Scanner scanner = new Scanner(System.in);
System.out.println("Please input how many types of food items the gerbils eat as an integer");
String n0 = scanner.nextLine();
int n1 = Integer.parseInt(n0);
String[] food = new String[n1];
for (int i = 0; i < n1; i++) {
System.out.println("Please enter a food name");
String n2 = scanner.nextLine();
food[i] = n2;
int[] maximum = new int[n1];
System.out.println("Please enter maximum amount of food per day");
String n33 = scanner.nextLine();
int n3 = Integer.parseInt(n33);
maximum[i] = n3;
}
System.out.println("Please enter in the number of gerbils in the lab");
String n73 = scanner.nextLine();
int n4 = Integer.parseInt(n73);
gerbil = new Gerbil[n4];
int[] combo = new int[n4];
String[] ids = new String[n4];
for (int i = 0; i < n4; i++) {
Gerbil g = new Gerbil(n1);
System.out.println("Please enter in the lab id for each gerbil");
String n5 = scanner.nextLine();
g.setId(n5);
//ids[i] = n5;
//String[] names = new String[n4];
System.out.println("Please enter in the name of each gerbil");
String n6 = scanner.nextLine(); // gerbil name
g.setName(n6);
String[] amountfood = new String[n1];
for (int j = 0; j < n1; j++) {
System.out.println("how much of" + food[j] + "did the gerbil eat");
String n8 = scanner.nextLine();
amountfood[i] = n8;
}
String[] bite = new String[n4];
System.out.println("Does this Gerbil bite? Enter True or False");
String n77 = scanner.nextLine();
bite[i] = n77;
String[]escape = new String[n4];
System.out.println("Does this Gerbil escape? Enter True or False");
String n89 = scanner.nextLine();
escape[i] = n89;
}
System.out.println("What information would you like to know?");
String n55 = scanner.nextLine();
String n33 = "search";
String n34 = "average";
String n35 = "restart";
String n36 = "quit";
if(n55.equalsIgnoreCase(n34)) {
System.out.println(averagefood());
} else {
if(n55.equalsIgnoreCase(n33)) {
System.out.println("Please type the lab id of the gerbil you wish to search for");
String n87 = scanner.nextLine();
System.out.println();
} else {
if (n55.equalsIgnoreCase(n35)) {
//go back to beginning of program
} else {
if (n55.equalsIgnoreCase(n36)) {
System.exit(0);
} else {
System.out.println("ERROR");
}
}
}
}
}
public static int averagefood(int n4, int n3, int n8) {
for (int i = 0; i < n4; i++) {
long percent = Math.round(n8 * 100.0 / n3);
return averagefood(newName, newId, percent);
}
}
public static int searchForGerbil() {
n87 = setId;
return 0;
// return (new Gerbil[i]
and heres the code from my second class:
public class Gerbil {
private String id;
private String name;
private int[] amountfood;
//private int numbergerbils;
//private int maxfood;
private boolean escape;
private boolean bite;
public Gerbil(String n5, String n6, int numOfFood, boolean newEscape, boolean newBite) {
id = n5;
name = n6;
amountfood = new int[numOfFood];
escape = newEscape;
bite = newBite;
}
public Gerbil(int numOfFood) {
amountfood = new int[numOfFood];
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public void setId(String newId) {
id = newId;
}
public void setName(String newName) {
name = newName;
}
}
it says next to System.out.println(averagefood()); The method
averagefood(int, int, int) in the type Gerbilfood is not applicable
for the arguments ()
If you check your code your function definition requires three arguments and you have not passed any.
getName cannot be resolved to a variable
This is a function in class Gerbil and hence needs to be called as follows:
Gerbil gb = new Gerbil();
gb.getName();
Syntax error on token "return", Name expected after this token - getId
cannot be resolved to a variable - newId cannot be resolved to a
variable - newName cannot be resolved to a variable it says that next
to return averagefood(newName, newId, percent);
None of these variables have been defined in class Gerbilfood. What values are you expecting to pass using these variables?