Amount Of Money - Compile Error / Unreachable Statement
Feb 14, 2014
This method accepts 1 integer, amount (the amount of money). Output the minimum number of in quarters, dimes, nickels and pennies used to make up the amount. For example, an amount of 32 would require 1 quarter, 1 nickel and 2 pennies.
This is the question^
My codes are:
public static int change (int amount) {
int quarters = amount / 25 ;
int firstresult = amount % 25 ;
return quarters ;
int nickel = firstresult / 5 ;
[Code] .....
The codes were working when i used System.out.println instead of return, but our teacher required us to use return (functions).
I cannot see why I am getting an 'Unreachable statement' error on 'return -1;' on line 13126.I am also getting a 'missing return statement' error on the very last line.
/* 12992: */ private int extractInterfaceValues(RSInterface class9, int j) /* 12993: */ { /* 12994:11712 */ if ((class9.valueIndexArray == null) || (j >= class9.valueIndexArray.length)) { /* 12995:11713 */ return -2; /* 12996: */ } /* 12997: */ try /* 12998: */ { /* 12999:11716 */ int[] ai = class9.valueIndexArray[j]; /* 13000:11717 */ int k = 0;
programming altogether and after almost reaching half way in the 'Head first java' book I decided to try and apply some of what I've learnt so far and write my first 'Object orientated' program. As this is pretty much the first program I've ever written, I decided to write a program to ask for two integers and add them both together and then present them to the user (the goal eventually being a basic fully working command line calculator with +,-,* and /. I'm expecting many compile errors but not the following errors below.
I have three .java files contained within a folder and after trying to figure out how to compile all three files (as they use one another) all at once, I came across this ---> javac *.java
so I typed this in the command line whilst in the directory containing the three files assuming *.java is the best approach and then I receive the following errors:
inputOutput.java:10: error: cannot find symb c.addition() = intIn.nextInteger(); ^ symbol: variable c location: class inputOutput
I'm writing basically my first program for school. I've written small ones, following instructions, but this is the most vague. I'm having issues. I can't figure out what the error means. I'm not done with the code, but I think the ArrayList is throwing me off. I'm trying to gather user input and sum the total. Here's the code:
package graduationplanner; import java.util.ArrayList; import java.util.Scanner; import java.lang.Double; public class GraduationPlanner { public static void main(String[] args) {
I keep getting the error Admit.java:10 cannot find symbol
import java.util.*; public class Admit { public static void main(String[] args) { sayIntro(); Scanner console = new Scanner(System.in); System.out.println("Information for applicant #1:"); getScore(console); getGPA(console);
[Code] ....
The compiler then reads:
Admit.java:10: error: cannot find symbol score1(ACTScore, SATScore, GPAScore); ^ symbol: variable ACTScore location: class Admit Admit.java:10: error: cannot find symbol
I have a msg object that contains an ArrayList<Integer> collection. However, in order to send the elements in the array over the udp socket, it needs to be sent as a byte[] array. So why am I using ArrayList<Integer> over byte array in first place? Well when I receive data from socket from embedded c program, I need to get an unsigned representation of the data, and thus I need to store it in integers, since bytes in Java are unsigned and unsigned chars in c that are greater than 127 will yield incorrect values in java. But when I send an ack back over the socket, I need to send the data back as bytes. So I convert the ArrayList<Integer> to a byte array:
Java Code: byte[] data = msg.toByteArray(); DatagramPacket response = new DatagramPacket(data, data.length, packet.getAddress(), packet.getPort()); public class Gprs { ... public byte[] toByteArray(){
[Code] ....
The problem is I get an "Cannot cast from Integer to byte" when trying to cast the integer to byte: data[i] = (byte)m_data.get(i);
This is likely a simple matter, but my error is confusing given the line it flags matches a working project I have. I get the following error on line 6 in the Controller:
cannot find symbol v.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ...........................................^ (carrot at the J)
My view file:
import java.awt.*; import javax.swing.*; import java.awt.event.*; public class View extends JFrame{ private JLabel lbl; private JButton btn;
Netbeans do not detect any syntax errors, but I when I check the build it retuned areas they were a few; It's a simple program name 5 people, gade them then do final calulatoins it's called "grade tool.
heres the code
package gradingapplication; import java.util.Scanner; public class GradingApplication { public static double score(double score){ if(score >= 90){ System.out.println("A");
[code]...
~Problems~
1. It has no gui, I don't know java fx, is java groove used? awt is useful for creating spam bots in robot class, I know it's not very useful but it's so much fun.
class SubB{ public void foo(){ System.out.println(" x"); } } public class X extends SubB { public void foo() throws RuntimeException{ super.foo(); if(true) throw new RuntimeException(); System.out.println(" B"); } public static void main(String [] args){ new X().foo(); } }
Why the foo method of class X is not throwing a compile error because according to the override rule, if the superclass method has not declared exception, the subclass method can't declare a new exception...
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"
I decided to code this quiz I took in class about asking the user to input a string and the code is suppose to check for upper case letters. If a upper case letter is found, it should increase a count by one. Once the check is done, it should display the number of uppercase letters. For some reason I am getting this weird compile error stating that symbols can't be found...
Java Code:
import java.util.*; import java.lang.*; public class StringCheck{ public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("please enter a string: " ); String s = input.nextLine();
I was almost finished with my program when I noticed I had a big logical error. At the very beginning of my else if statements I would jump down to my else statement.
Java Code:
import java.util.Scanner; public class InternetServiceProviderNew { public static void main(String[] args) { double packageA, packageB, packageC, extraA, extraB, userHours, aHours, bHours, cHours, userCharges; packageA = 9.95; packageB = 13.95; packageC = 19.95; aHours = 10; bHours = 20; String userPackage, A, B, C ;
This is what i have so far, I use BlueJay to write this:
import javax.swing.JOptionPane; public class payroll { String again = y; // private String name; private double rate; private double hours; static double gross; //gross pay
[code]....
my first problem is that it expects a ")" on this line :"if ((hours <=40)rate *1);"For the assignment itself these are the requirements:
-Create a class called payroll with private variables for rate hours and name
-Create static variables for gross pay, union dues, health coverage (hp in my case), FICA taxes, State taxes, Federal taxes, net pay, all must be initialized to 0
-default constructor that assigns default values
a function called calcPay that will do the following tasks and print it to a pay stub :
- function that checks the hours ( if hours are 40 or less pay rate, if over 40 pay 150% of the rate) - calculates gross pay before any deductions (using user inputted hours and rate) - deduct medical coverage and union dues from gross pay and call this adjusted gross pay (also this should have its own line on the paystub) - A function that deducts State, federal and fica taxes from adjusted gross - FICA - 7% for any income -Federal - 2% for $0-$150 / 6% for 150.01 - 300 / 14% for 300.01 - 600 / 18% for 600.01 - unlimited -State - 1% for 0-150/ 3% 150.01 - 300 / 5% 300.01 - 600/ 8% 600.01 - unlimited - amount after all deductions is the net pay ( show this amount on its own line) - Start a loop that asks each time if there are more employees (y/n) y should continue the program and n should end it -dialog boxes should be created to recieve values for name, hours and rate - if the rate is entered below $8 dollars a new box should pop up and ask for a higher value - When there are no more employees, print out a summary of quantities stored in static variable (also had a problem with this) - End
So I think i completed most of these objectives but am having trouble with the syntax and some of the objectives
I'm getting errors on all the exceptions called EmptyCollectionException. I think this is because the import statement has a error on it but I'm not sure. I'm suppose to add methods for peek, isEmpty, size, and toString methods. I only started isEmpty also am wondering what I have to change from peek method if anything at all.
import jsjf.exceptions.*;//Error on jsjf import java.util.Arrays; public class ArrayStack<T> implements StackADT <T> { //Error on StackADT private final static int DEFAULT_CAPACITY = 100; private int top; private T[] stack;
My if else statement is not working...it keeps telling me that the else in the statement is a syntax error and that I should remove it. Whats wrong with it?
package Homework2; import java.util.Scanner; public class Homework2 { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Welcome to the Triangle Program.");
I am Having trouble with my program to validate. It is outputting null into the validation statement then it brings back a run-time error to that validation Statement for the String.
public String validateData () { if (nm == null)nm = "Error! Must enter at least one character"; else nm = name; return name; }//end validation method
Why is this happening, and then once that is completed, why is the validation Sentence in tests Scores not able to validate. I traced it back to out put "Error, a number between 1<100".
public void validateTests () { String testschange; if (test1 < 0 || test1 > 100) { testschange = " You have entered an invalid number, between 1-100. Please restart!"; testschange = Integer.toString( test1 ) ;
I have a problem about this numeric or value error on my java class. Whenever I am calling for the procedure in callable statement it says that error. I don't know what is the problem with my sql code because I;ve tried running it on database alone and it runs perfectly. The results that I need came out fine. But when I'm already calling it in java that error appears. But I tried on finding the line that the said error is coming from and here is the code...
create or replace PROCEDURE RENTING (P_NNAME IN VARCHAR2, P_ADD IN VARCHAR2, P_PHONE IN NUMBER,
I've created a constructor in bean and put an value to my string after doing so all started to work properly. I am trying to get my application to work but no luck so far. I have looked for similar issues but although there were similar I've got no luck in fixing mine.
When I am trying to put an value in the input file i got error message (/zadanie_1.xhtml @15,75 value="#{z_1.lancuch}": Target Unreachable, identifier 'z_1' resolved to null).
My starting page:
<?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html">