Basically I'm trying to code this program but I keep getting error can't be applied to given types. I know it has to do with my method trying to be called by an array, but I'm just kinda lost.
Write a program that prompts the user to input cash amounts and use a method to calculate the average amount for a week given 7 inputs of daily cash intake amounts for a cash register. Use an array to store the values. Recall that average is the sum of the values divided by the number of values. The method should take argument(s) of type double and return average weekly cash amount as a double.
Make sure you test your program using the test data given below and calls the averageCash() method defined above passing in the values. Verify that the input values are greater than or equal to 0. Negative numbers are not allowed. Output the values used and the averageCash value.
import java.util.*;
public class ArrayHandout {
public static void main(String args[]) {
int[] a=new int[6];
Scanner sc=new Scanner(System.in);
I'm working with Libgdx but I have a basic java question. I'm trying to access the overridden methods from and interface in another class via a call but I'm not sure how. This is what I've got so far :
Java Code:
public interface Controller { public void show (); } public class MainActivity extends AndroidApplication implements Controller { @Override public void showAd(boolean show) { System.out.println("TEST");
[Code] ....
Right now this code returns a null pointer at the call.
I have two classes, MonsterGame (shown below) and Monster. Monster has a public accessor method to get it's private character variable, which represents the first character of the name of the Monster in question.
I'm just a bit confused as to why am I unable to cycle through the array of Monsters I have in the MonsterGame class and call
m.getCharacter(); (pretty much the last line of code) public class MonsterGame{
private static final char EMPTY_SQUARE = ' '; private char[][] gameBoard = new char[10][10]; private Monster[] monsters = new Monster[4]; private int maxXBoardSize = gameBoard.length -1; private int maxYBoardSize = gameBoard[0].length -1;
[Code] ....
I understand that there need to be instances of objects to call methods, but is that not the case here? the Monster objects are have already been created, no? Do I need to create an index for the array? is the for loop not enough?
I can call a child method from a main method. If I have a parent called "Assessment", a child called "Quiz", and another child called "test". Can I instantiate an object like Assessment a = new test(); and call a method in test.
I know the method can be called if I instantiate the test t = new test() but that defeats the purpose of inheritance...
So I'm just a little unclear about this, but how would I call methods from the 'top' of an inheritance chain? I say 'top' because Object is the top... E.g.:
public class AClass { public void myMethod() { ... } } public class BClass extends AClass { public void myMethod() { ... } } public class CClass extends AClass { public void myMethod() { ... } }
Assuming that BClass.myMethod() completely overrides AClass.myMethod() (so that there is no call to super.myMethod() in BClass.myMethod()) How can I call AClass.myMethod() from CClass.myMethod()?
This current one is to calculate a planes holding pattern. I have to write a method to prompt user to enter speed in knots, then it converts it to km/hr. Another method to calc. pattern width using the speed, another method to calc. pattern length, than a main method which would call and print out the speed in knots, speed in km, pattern width and length.My current problem is on the second method. It works in that I can enter the values and it gives me the correct answers, however it's asking me to enter the speed twice, instead of just once. Anything I try just results in errors and won't compile.
import java.util.Scanner ; //main method public class TitleRemoved { public static void main(String[] args) { double airSpeedKm = airSpeedOts () ; System.out.println("That speed is " + airSpeedKm + " km/hr.") ;
[code].....
I want my code to not only work, but be organized and easily readable as well, so I want to avoid bad habits.
In this project each individual will create a data analysis program that will at a minimum,
1) read data in from a text file, 2) sort data in some way, 3) search the data in some way, 4) perform at least three mathematical manipulations of the data, 5) display results of the data analysis in numeric/textual form, and 6) display graphs of the data. In addition, 7) your program should handle invalid input appropriately and 8) your program should use some "new" feature that you have not been taught explicitly in class.
(Note: this is to give you practice learning new material on your own - a critical skill of today's programmer.) If you do not have a specific plan in mind for your project, below is a specific project that meets all of the qualifications as long as 7) and 8) are addressed in the implementation.
Everything is done except I need to call my methods in my GradeTester.
GradeBook:
/** *This class creates an array called scores. *This class determines the length of the array scores and determines the last grade in the array scores. *This class sorts the array using a bubble sort, and searches the array. *This class calculates the mean, standard deviation, and the median of the grades in the array scores. *Once the grades in the array is sorted, the class then calculates the highest and lowest grades in the array. */
public class GradeBook { public final int MAXARRAY_SZ = 20; double [] scores = new double [MAXARRAY_SZ]; int lastGrade = 0; double mean = 0;
I have a JSP page that calls a Java method .. using GlassFish 4.0 it worked just fine, now I'm trying to run it on a new server with Tomcat 6.0 but it keeps giving me this error: "the function result must be used with a prefix when a default namespace is not specified"
Generic methods are methods that introduce their own type parameters. This is similar to declaring a generic type, but the type parameter's scope is limited to the method where it is declared. Static and non-static generic methods are allowed, as well as generic class constructors.
1. The method is only exclusively to be used for the declared argument parameter? For example given a generic method:public static <String, Integer> boolean method(Pair<K, V> p1) {}I could only invoke the method if Pair argument parameter is <String, Integer>?
I have a problem with multi threading calling with for loop. I have those two and many other classes in one jar file but n 2 different packages.
When i execute the jar file first runs the Aclass, from where i try to run multi threads. From the run() of the class RunTheGame i call many other classes which are in the same package. Like you can see from the for loop is executed the threads.
The problem is that when the second thread starts the first one is stopped this happens for all the threads, more simply when a new thread starts the old one is dead.
It seems that liken the threads uses the classes called from run() of the class RunTheGame as non multi threaded. It gives this error:
Java Code:
Exception in thread "Thread-0" java.lang.NullPointerException at thePackage2.EClass.getWhiteRemaining(EClass.java:49) at thePackage2.EClass.isFinal(DClass.java:84) at thePackage2.Spiel.<init>(Cclass.java:76) at thePackage2.RunTheGame.run(RunTheGame.java:198) at java.lang.Thread.run(Thread.java:745) mh_sh_highlight_all('java');
All the above refereed classes are called from the from run() of the class RunTheGame . Like i understand all the threads use those classes as non thread autonomous classes.
Java Code:
public class Aclass { private static Thread t[]; public static void main(String[] args) throws IOException { for (int Game = 0; Game< 10; Game++) { t[Game] = new Thread(new thePackage2.RunTheGame(aplayer, bplayer, Name, ID , Pmach)); t[Game].start();
I'm trying to call the grade.processFile method from the main method but I'm getting this Error below. I'll post my code which includes the main method and the class underneath the error message:
Exception in thread "main" java.lang.NullPointerException at java.io.FileInputStream.<init>(FileInputStream.jav a:130) at java.util.Scanner.<init>(Scanner.java:611) at MyGrades.processFile(MyGrades.java:49) at myGradesMain.main(myGradesMain.java:19) import java.util.Scanner; import java.io.*;
package Experimentation; import javax.swing.*; import java.awt.event.*; public class SimpleGUI1B implements ActionListener { JButton button; public static void main(String[] args) { SimpleGUI1B gui = new SimpleGUI1B(); gui.go();
[code]...
This is a program from Head First Java! since main is static it shouldn't be able to call non-static methods because statics do not use any instance variable values but in the above program we're call a non-static method go() how is it possible?
I am getting the error message as Exception in thread "main" java.lang.Error: Unresolved compilation problems: NewExcel cannot be resolved to a type for the line NewExcel test = new NewExcel(); in the below code to read the columns from an excelsheet "test.xls". Why I am getting the error message :-
import java.io.File; import java.io.IOException; import jxl.Cell; import jxl.Sheet; import jxl.Workbook; import jxl.read.biff.BiffException; public class ReadExcel
I am currently working on modules of a java program but am having issues with this module . it gives this error code"syntax error on token '?', invalid primitive type".
Multiple markers at this line - void is an invalid type for the variable loadDictionaryFromFile - Syntax error on token ")", ; expected - Syntax error on token "(", ; expected
Line 13 starts public void load....
Code:
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Scanner; public class PirateTranslator { public static void main(String[] args)
The program is just a simple one to print grades using only methods. The problem is Im trying to use a returned value in another method but the compiler keeps telling me it cannot find the symbol "mark". the problem areas are marked in blue. I am basically trying to input a value into the keyboard and then use it in another method.
public static void main(String[] args) { printTitle(); enterMark(); gradeCalculator(mark); printGrade();
I am trying to make a Applet and it works fine in Eclipse, but when I use it on the webserver I only obtain this Exception. It only happen when I make calls like this:
I have a code in which I am reading input from System.in and Destination is some where else
Here is my code
File file=new File("D:/output.txt"); OutputStream os=new java.io.FileOutputStream(file); Scanner scanner=new Scanner(System.in); System.out.println("Enter Data to write on File"); String text=scanner.nextLine(); int c=Integer.parseInt(text); int a; while((a=c.read())!=-1) os.write(a); System.out.println("File Written is Successful");
In the line while((a=c.read())!=-1)
a compile time error is shown "cannot invoke read on primitive data type int"