Results 1 to 16 of 16
- 02-22-2012, 06:52 AM #1
Member
- Join Date
- Jan 2012
- Location
- India
- Posts
- 34
- Rep Power
- 0
Interface in java - an error in an example program
Please help me to clear this error:
E:\java\somas\chapter9\workedprog>javac Prob91.java
Prob91.java:11: error: Hysin is not abstract and does not override abstract method Hypfun(double) in Hyper class Hysin implements Hyper {
^
1 error
i am using jdk1.7.
Java Code:/* Problem 9.1 , Page : 156 - 158. Write an interface called Hyperbolic with a method to find either Cosh or Sinh. Implement this interface to calculate Sinh(x) and Cosh(x) given by: Sinh(x) = x + ( 10 sumE n=1 ( (x^(2n + 1))/ (2n + 1)! Cosh(x) = 1 + ( 10 sumE n=1 ( (x^(2n))/ (2n)! */ interface Hyper { final int n = 10; double Hypfun(double x); } class Hysin implements Hyper { double sinh; long factn; int i; long Factfun(int nmax) { long fact = 1; for(i=2; i <= nmax; i++) { fact *= i; return fact; } } public double Hypnfun(double x) { sinh = x; for(int k = 1; k <= n; k++) { factn = Factfun(2 * k + 1); sinh = sinh + Math.pow(x,( 2 * k + 1)) / factn; } return sinh; } } class Hycos implements Hyper { double cosh; long factn; int i; long Factfun(int max) { long fact = 1; for(i =2; i <= max ; i++) fact *= 1; return fact; } public double Hypfun(double x) { cosh = 1; for(int k = 1; k <= x; k++) { factn = Factfun(2 * k); cosh = cosh + Math.pow(x, (2 * k)) / factn; } return cosh; } } class Prob91 { public static void main(String args[]) { double x, sinh, cosh, jsh, jch; Hyper hcos; Hyper hsin; int pn = 50; for(int i = 0; i < pn ; i++) System.out.println("-"); System.out.println("\n"); System.out.println("x \t sinh \t cosh \t"); for(int i = 0; i < pn ; i++) System.out.println("-"); System.out.println("\n"); for(x = 0; x <= 5; ) { hsin = new Hysin(); hcos = new Hycos(); sinh = hsin.Hypfun(x); cosh = hcos.Hypfun(x); // Reduce the fractional digits for display double sx = (int)(sinh * 1000); double cx = (int)(cosh * 1000); sinh = sx / 1000; cosh = cx / 1000; System.out.println(x + "\t" + sinh + "\t" + cosh); x += 0.5; } for(int i = 0; i < pn; i++) System.out.print("-"); System.out.println("\n"); } }
- 02-22-2012, 07:11 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Re: Interface in java - an error in an example program
Did you read the error message properly?
- 02-22-2012, 07:16 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Re: Interface in java - an error in an example program
Check the class access modifier where you want to implement your interface.
- 02-22-2012, 08:47 AM #4
Member
- Join Date
- Jan 2012
- Location
- India
- Posts
- 34
- Rep Power
- 0
- 02-22-2012, 08:52 AM #5
Member
- Join Date
- Jan 2012
- Location
- India
- Posts
- 34
- Rep Power
- 0
Re: Interface in java - an error in an example program
The message shows error on line number 11 where i think all are correct . i will check those modifiers...
- 02-22-2012, 09:14 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Re: Interface in java - an error in an example program
Because your class has default access.
- 02-22-2012, 09:34 AM #7
Re: Interface in java - an error in an example program
Your code is difficult to follow because you have not adopted standard coding conventions. Method (and variable) names should start with a lowercase letter.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-22-2012, 09:42 AM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Interface in java - an error in an example program
In the interface:
double Hypfun(double x);
In the class implementing the interface:
public double Hypnfun(double x)
They're not the same...
- 02-22-2012, 10:46 AM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Re: Interface in java - an error in an example program
The name is 'Hypfun', not 'Hypnfun' in yout Hysin class ...
kind regards,
Jos
edit: *darn* too slow again ... ;-)When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-22-2012, 11:19 AM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Interface in java - an error in an example program
Only by an hour.
:)
- 02-22-2012, 11:25 AM #11
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
- 02-22-2012, 12:10 PM #12
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Interface in java - an error in an example program
I do that.
Open a load of thread pages and then do some work occasionally dipping in...only to find someone has answered in the intervening time.
The other classic is to completely miss the fact that the thread has gone onto a second (or more) page...
- 02-22-2012, 12:28 PM #13
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
- 02-22-2012, 12:54 PM #14
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Interface in java - an error in an example program
"ooh look. Shiny things!"
:)
- 02-22-2012, 01:11 PM #15
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Re: Interface in java - an error in an example program
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-22-2012, 06:46 PM #16
Member
- Join Date
- Jan 2012
- Location
- India
- Posts
- 34
- Rep Power
- 0
Similar Threads
-
Program for interface
By NetJava in forum New To JavaReplies: 5Last Post: 11-20-2011, 07:12 PM -
class interface or enum expected Imports java.io.*; error
By prathamkool in forum New To JavaReplies: 2Last Post: 10-02-2011, 04:53 PM -
Java program error
By Taszk in forum New To JavaReplies: 16Last Post: 06-06-2011, 05:59 AM -
error in java program..
By mudit222 in forum New To JavaReplies: 2Last Post: 12-17-2010, 09:32 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks