Create a class named Commission that includes three variables: a double sales figure, a double commission rate, and an int commission rate. Create two overloaded methods named computeCommission (). The first method takes two double parameters representing sales and rate, multiplies them, and then displays the results. The second method takes two parameters: a double sales figure and an integer commission rate. This method must divide the commission rate figure by 100.0 before multiplying by the sales figure and displaying the commission. Supply appropriate values for the variables, and write a main () method that tests each overloaded method. Save the file as Commission.java
b. Add a third overloaded method to the Commission application you created in Exercise 1a. The third overloaded method takes a single parameter representing sales. When this method is called, the commission rate is assumed to be 7.5% and the results are displayed. To test this method, add an appropriate call in the Commission program's main () method. Save the application as Commission2.java
COMMISSION.JAVA
public class Commission
{
public static void main(String[] args)
{
double Sales = 10000;
double commRate = 0.075;
int rate = 7;
computeCommission(Sales, commRate);
computeCommission(Sales, rate);
}
public static void computeCommission(double Sales, double commRate)
For some reason, even though I am giving it the correct number of arguments for the constructor to be initalized it doesn't go through. I end up with a compile error:
PatientBuilder.java:17: error:
constructor Patient in class Patient cannot be applied to given types; Patient aPatient = new Patient(bloodType, rhFactor, ID, age); ^ required: no arguments found: String,String,int,int reason: actual and formal argument lists differ in length
And I'm not understanding how that's possible when it calls for 2 strings and 2 ints and that's what I am passing.
I have this in my main method Scanner inputDevice = new Scanner(System.in);
System.out.println("What is the patients ID number?"); int ID = inputDevice.nextInt(); System.out.println("What is the patients age?"); int age = inputDevice.nextInt();
[Code] ....
And then here are my two constructors, one default and one overloaded.
public Patient() { patientBlood = new BloodData(); ID = 0; age = 0; bloodType = "O"; rhFactor = "+";
1. public void f(int i, long j){System.out.println("1");} 2. public void f(int...i){System.out.println("2");} 3. public void f(long l, long p){System.out.println("3");} 4. public void f(int j, int k){System.out.println("4");}
With the function call: f(1,2), the output is: 4.
My questions are the following:
a. Why is the compiler choosing #4 to execute and not the rest? b. If I remove 4 and replace it with: 5. public void f(long j, int k){System.out.println("5");}, why does the compiler now give an error complaining of ambiguous function defintions when 'f' is called?
Overloaded methods CAN declare new or broader checked exceptions. We know that FileNotFoundException is a subclass of IOException and according to the above statement an overloaded method cannot throw a narrower exception. But the below code does not throw a compiler error. How?
Animal.java
Java Code:
package pack1;
import java.io.FileNotFoundException; import java.io.IOException; public class Animal{ public void drink(int s) throws IOException {
public test5 { public boolean test(int grille[][]){ for (int i = 0 || i < grille.length || i++){ int max = grille[i][0]; for (int e = 1 || e < grille[i].length || j++){ if (grille[i][e]== max && max !=0){ solution = false; System.exit(1);
So say I write up a program like a dice roll game, which I see on the forums here. It's all written and good to go and when I hit Run it does what I want it to do, no errors..What do I do with those .class and .java files? Do I compile it somehow into an app I can put on the google play store? What is the NEXT STEP after the program is all written?
I get quite a few errors while trying to compile the BeerSong from the Head First Java book. I copied the text from another person that did the beer song on this forum and it worked as expected. What I can't figure out is why mine is not working when it looks like the text is exactly the same between the two versions. His works, but mine doesn't.
Here is the text and errors that I get:
public class BeerSong { public static void main (String[] args) { int beerNum = 99; String word = "bottles";
I am watching BrandonioProductions on youtube. His videos are pretty good, but he doesn't seem to get errors where I get them. Here is an example.
public class compareUnequal { public static void main(String[] args){ compareTwo(); } public static void compareTwo(){ String x = "david"; String y = "Notdavid"; if (!x.equals(y)){ System.out.println("Not equal"); } } }
It runs ok, but asked me to proceed when there is an error, but I can`t figure out where the error is!
import java.util.*; public class CQ1v1{ public static void main(String args []) { Scanner in = new Scanner (System.in) ; String name = ""; System.out.println("Welcome to the Interrogator") ;
[Code] ....
When I compile getting
CQ1v1.java:12: error: cannot find symbol x = in.nextLine (); ^ symbol: variable x location: class CQ1v1 CQ1v1.java:21: error: cannot find symbol
I am trying to create an array where each object includes a service description, price, and time in minutes. I have a Service class and a SalonReport class:
import java.util.*; public class Service { public String serviceDescription; public double servicePrice; public int timeMinutes;
[Code] ....
When I compile this, I get an error message that says:
SalonReport.java:8: error: constructor Service in class Service cannot be applied to given types; salonServices[0] = new Service("Cut", 8.00, 15); ^ required: no arguments found: String,double,int reason: actual and formal argument lists differ in length
What this error message means and how I can correct it? I am confused because my SalonService() method has (String service, double price, int minutes), and each object is listed in that exact order.
String filename="C:UsersRajashekarDesktopfwfwdSoftware Failures1_Test.txt";//Input Files String data; public ArrayList<String> value=new ArrayList<String>(); public void read() throws IOException{ File f = new File(filename);
When I try to compile the code it says " method determineWinner in class RPS cannot be applied to given types;" I think there is something wrong with the way i called the determineWinner method but i'm not what exactly is wrong.
public class RPS { public static void main( String [] args ) { String result; String userName = getUserName(); String playerChoice, computerChoice;
I made a software using Netbeans and javaswing. Accidently i deleted my main file which contains my main class and main method. Just to test, i tried to compile and run and it worked but the style of my buttons and windows has changed. So, what happened? How can i change the style of my programs?
//File Accidently deleted package time; public class Time { public static void main( String[] args ) { Window wdow = new Window(); wdow.setVisible( true ); } }
I am new in java. I executed a java program using eclipse. the program contain two java file. when i try to run it using terminal in Ubuntu. Two files are not linking. it shows error. i am attaching all the data.
It shows the following error
regex2string.java:83: error: cannot find symbol str = randomstr.nextString(2000); ^ symbol: variable randomstr location: class regex2string 1 error
I have an input text file as file.txt where, it consists of only real values separated with commas, and arranged as rows as columns as mentioned below :
the number of rows is 100 and the number of columns are 9, that is they are fixed.Above is just an example, the file consists of decimal values.What I require is for each column of values I need to find out it's average or mean, that is in above example,
for 1st column:(1+1+2)/3 for 2nd column(2+4+4)/3 for 3rd column(3+7+5)/3,,,,,,,like this till the last column.
So I need to take the input from the .txt file, calculate the column average of each column and the average of each column must be displayed as output. I have done a bit of coding, but it is giving a run-time error as NullPointerException.I will forward my code as attachment, the reading of file, is done as string in java and then it must be converted to double values, also to read the comma separated input from a file I have used the split().
I made a web app to test the ServletContextListener in tomcat according to the book head first servlets and jsps and used the code
out.println("test context attributes set by listener<br>"); Dog dog = (Dog) getServletContext().getAttribute("dog"); out.println("Dog's breed is: "+dog.getBreed());
in the listener class.But the output is showing the first line only and the second println() is not showing any output whereas my Dog class compiled successfully and I didn't see any NullPointerException as expected in the book but somehow it seems like the problem is in the 2nd line of code only but I don't know what.
I also tried to add a 4th line at the end with println() only but with a simple text even that is not running but when I put that same line after the 1st line, the output is shown.I am unable to see what has gone wrong in the 2nd line of code.
I am operating java from the command line (using Terminal on Mac OSX 10.9.5).The current directory within Terminal is called "orange" and the following sourcecode file is in the orange directory :
Test1.java package orange; public class Test1 { public static void main(String[] args) { System.out.println("Test1 works"); } }
This complies to Test1.class (visible in the orange directory) but when I try to run it in Terminal (simply using "java Test1" from within the orange directory). I get the following error message (which I don't get if I simply comment out the line //package orange;)
Exception in thread "main" java.lang.NoClassDefFoundError: Test1 (wrong name: orange/Test1) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:800) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
I am a beginner here at JAVA and I am trying to program a Gratuity Calculator using both interface class and object class but it keeps on compiling with errors saying "cannot find symbol".I tried everything to fix it but it just keeps on stating symbol.
[CODE] public class GratuityCalculator extends JFrame { /* declarations */
// color objects Color black = new Color(0, 0, 0); Color white = new Color(255, 255, 255); Color light_gray = new Color(192, 192, 192);
I'd like to know how to return a new array, I wrote in a method below the main method. I want to print the array but system.out.print doesn't work for arrays apparently. What structure i should use?