Test Driver Does Not Accept String Parameter
Jan 6, 2015
I wrote a couple classes and am trying a test driver but it is having an error I do not know how to solve.
Student Class:
public class Student{
private Course[] courseList;
private static int numCourses;
private final int maxCourses;
public Student(int max){
maxCourses = max;
[Code] .....
Error:
javac tester.java
tester.java:6: error: cannot find symbol
one = new Course(name);
^
symbol: variable name
location: class tester
1 error
Same issue, just only one error as there is only one line. It seems like it does not accept my parameters as it cannot find symbol.
I forgot to put the "" in the brackets, it's been a month since I have looked at any java and made this simple mistake.
View Replies
ADVERTISEMENT
Apr 13, 2015
I am to create a Array class then create a Driver class (TestArray) to test all the methods in the Array Class. Here's the code i've written for the Array Class. I just nee developing the TestArray class.
import java.util.Scanner;
public class Array
{
Scanner sc = new Scanner(System.in);
private double[] array = new double[];
public void setArray(double[] arr) {
[Code] ...
View Replies
View Related
Jan 3, 2015
I have a method that accepts as a parameter an object:
public void addClient(Client c){ }
Client is a class which has a constructor that has two String parameters:
public Cliente (String name, String lastname){
this.name = name;
this.lastname = lastname;
}
In the main add a Client in this way:
addClient(new Cliente("first", "second"));
Now, i have an array of Client, so I would like to enter within this. Example:
public void addClient(Client c){
for (int i = 0; i<client.length ; i++) { // client is an array of Client object
client[i] = c; // Enter a c in the array, but does not work!
System.out.println("test "+clienti[i]); // print Client@15db9743
}
}
I have used the println for check if worked insertion, but the result shows no
View Replies
View Related
Nov 1, 2014
I am practicing some basic recursion and I was trying to solve this problem
Write a method sumTo that accepts an integer parameter n and returns the sum of the first n reciprocals. In other words:
sumTo(n) returns: 1 + 1/2 + 1/3 + 1/4 + ... + 1/n
For example, the call of sumTo(2) should return 1.5. The method should return 0.0 if passed the value 0 and should throw an IllegalArgumentException if passed a value less than 0.
This is my attempt to do it , however my output is always a 0.0 , and i do not understand why :
public static double sumTo(int n ){
if(n<0){
throw new IllegalArgumentException();
}
else if (n==0){
return 0.0;
[Code] .....
View Replies
View Related
Nov 20, 2014
Write a method maxOccurrences that accepts a list of integers as a parameter and returns the number of times the most frequently occurring integer (the “mode”) occurs in the list. Solve this problem using a map as auxiliary storage.
If the list is empty, return 0.
View Replies
View Related
Mar 30, 2015
I've a problem in encoding a URL string.
I know to encode a string we use,
URLEncoder.encode(stringname,"UTF-8");
But when I use this I'm getting an error telling that the encode method will accept only 1 String argument.
View Replies
View Related
Oct 14, 2014
What it is supposed to do is decide whether a ceiling fan is on or off, and describe it (color, area, speed). This is all user input (even pi) so it should decide whether to turn it on or off but for some reason skips over my if/else if statements all together.
I've tried changing it around a bit, looking up what my problem may be but this problem remains the same. my code:
import java.util.Scanner;
public class CeilingFan
{
final int slow = 1;
final int medium = 2;
final int fast = 3;
private int speed;
boolean on = false;
private double radius = 5;
private double pi = 3.1415;
String color = "blue";
[code]....
View Replies
View Related
Jan 14, 2015
I am trying to create a fortune teller and everything is running fine except the program does not prompt you to answer the questions
Do you like donuts?
and
What did you have for breakfast?
Here is the code this is in Bluej :
import java.util.Scanner;
public class FortuneTeller {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Welcome to Fortune Teller");
[Code] .....
View Replies
View Related
Oct 3, 2014
I'm having a hard time with this problem, this is what I have, but I can not use two integers, I have to use one integer and a string...
This is the question:
Write a method called printStrings that accepts a String and a number of repetitions as parameters and prints that String the given number of times. For example, the call:
printStrings("abc", 5);
will print the following output: abcabcabcabcabc
This is what I attempted:
public class printStringsproject {
public static void printStrings(int abc, int number) {
for (int i = 1; i <= number; i++) {
System.out.print("abc");
}
}
public static void main(String[] args) {
printStrings(1, 5);
}
}
View Replies
View Related
Jan 23, 2015
The program is to accept a string and display all the palindrome words(the words that are same even if they are reversed-------->mom,madam,malayalam etc.)in the string.
I need to solve this program urgently.
There are no syntax errors but after typing in the sentence,no output is displayed. This is my program....
import java.util.*;
class palindrome_test
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
System.out.println("Enter a sentence");
String usersInput=in.nextLine();
[Code] .....
View Replies
View Related
Jun 10, 2014
import java.io.*;
Class bubble
{
public static void main()throws IOException
{
BuffetedReader br=new BufferedReader (new InputStreamReader (System.in));
int j, k, temp;
String st[]=new string [10];
[Code] .....
View Replies
View Related
Feb 8, 2015
Write a java program to accept a string, float and an integer as command line arguments. String value should be displayed. Also the program should display the maximum value of two numbers. Use Integer.parseInt() and Float.parseFloat()
View Replies
View Related
Mar 25, 2015
I am taking a parameter of type String and checking if either the city or state contains the "keyword", whatever it may be. I am using an arrayList of 10,000 customers and adding any customer that lives in a city or state that contains the keyword to a new arrayList and then returning that arrayList. I thought my solution was correct, but when using the JUnitTest provided, it is not quite passing the test. My solution is as follows.
Java Code:
public ArrayList <Customer> getMailingList(String keyword){
ArrayList <Customer> key = new ArrayList<Customer>();
keyword = keyword.toLowerCase();
for(Customer c : data){
if(c.getState().contains(keyword) || c.getCity().contains(keyword)){
key.add(c);
}
}
return key;
} mh_sh_highlight_all('java');
View Replies
View Related
Feb 6, 2015
I have to write a program that inputs a string and tests whether or not it is a palindrome. This worked fine, and now I want to make it so I continually enter strings until I tell the program to stop.
The code below compiles just fine, but it doesn't do what I want. Why it doesn't work how I think it should work? (Typing in STOP does not make the program stop.)
Here is the code
import javax.swing.JOptionPane;
public class PalTest {
public static void main(String[] args){
String S="pony";
while(S!="STOP"){
S=JOptionPane.showInputDialog("Enter a string (STOP to terminate):");
[Code] ....
View Replies
View Related
Feb 7, 2015
How does the Scanner goes through the String which is passed to it as a parameter. For example, String input = "222 dddd 222 ddd22" is passed to the method and here's the code:
Java Code:
public static void sum(String anything)
{
Scanner input = new Scanner(anything)
while(input.hasNext())
{
if(input.hasNextDouble())
{
double nextNumber = inut.nextDouble();
sum += nextNumber
}
......
......
} mh_sh_highlight_all('java');
{
So, how does Scanner calculates a passed String? I just want to know the way it calculates/reads.
View Replies
View Related
Oct 11, 2014
Question: 1. Declare and implement a class named Substrings. The class will contain the following data members and methods:
Data members:
string S
Methods:
setS() take a string as a parameter and store it in S
printSub1(), printSub2(), printSub3(), printSub4() print all substrings of S. If S = "abcd",
printSub1() will print "a", "ab", "abc", "abcd", "b", "bc", "bcd", "c", "cd", "d",
printSub2() will print "abcd", "bcd", "cd", "d", "abc", "bc", "c", "ab", "b", "a",
printSub3() will print "a", "b", "c", "d", "ab", "bc", "cd", "abc", "bcd", "abcd", and
printSub4() will print "abcd", "abc", "bcd", "ab", "bc", "cd", "a", "b", "c", "d".
Alright so after doing some googling and watching tutorials I managed to put together the first two but I still don't exactly understand how nested for loops work, however just a single loop I do understand.
Secondly, the 3rd and 4th prints are completely destroying my brain using for loops, which we are supposed to use. Check out my code below, also keep in mind the 3rd is giving errors and the 4th i had to revert back to the same as the first print temporarily because my code because so messed up. How to understand nested for loops better.
[code=Java]
import java.util.Scanner;
class subString {
String S;
void setSubstring(String SS) {
S = SS;
[Code] .....
Compiling: error for myS.printSub3 and myS.printSub4 is the same as 1 because i had to revert it after ruining the code.
View Replies
View Related
Jul 26, 2014
Where do I have to put the ojdbc6.jar file so that Java finally recognizes it?I'm trying to connect to a Oracle XE databse from a Java application, but
Class.forName("oracle.jdbc.OracleDriver");
Will throw a ClassNotFoundException no matter where I put the driver. Stuff like this should be extremely simple but I am about to give up for good now.
View Replies
View Related
May 2, 2014
Why we create a driver class?Instead of creating a driver class, if we want to compile our code so will it show output? Let say, we've created a class GradeBook of the institution for students.So they can easily view their profile information and scores in different semesters.so when we have created a class for this purpose, should we create a driver class or not?What is the big advantage of creating a driver class?
View Replies
View Related
Sep 25, 2014
I'm trying to use a setter method to pick a random integer to be the MPG for a car. However, I'm having major issues in my driver when trying to use that random number in an instance. I'm not finished with the driver yet because I keep getting "cannot find symbol errors"
import java.util.Random;
public class Car {
private String make;
private String model;
private int year;
private int mpg;
private int odometer;
Random generator = new Random();
[code]...
View Replies
View Related
Feb 20, 2014
I am having trouble creating a driver for the following program. im new to creating interfaces and i need to make this work.
Lockable interface:
Java Code:
public interface Lockable {
boolean locked();
public void setKey(int key);
public void lock(int key);
public void unlock(int key);
} mh_sh_highlight_all('java');
[code]....
View Replies
View Related
Feb 25, 2014
I want to write java code which can block unbuffered I/O requests send to CD driver ...
View Replies
View Related
Mar 22, 2015
I started learning mysql to connect my program to a database but every time i try to connect I get this error.
java.sql.SQLException: No suitable driver found for dbms:mysql://localhost:3306/apexdemo
at java.sql.DriverManager.getConnection(DriverManager.java:596)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at JDBCdemo2.main(JDBCdemo2.java:7)
I did the following:
- added the mysql-connector-java-5.1.34 jar to my classpath
- added mysql jdbc driver to the project library
- double checked the url syntax and spelling errors
- checked that the server is running
import java.sql.*;
public class JDBCdemo2 {
public static void main(String[] args) {
Connection conn = null;
[Code] ....
View Replies
View Related
May 14, 2015
I came across the below
1) When a variables are declared "Private" How should it be accessed from the driver class ? Sometimes i get an error in driver class saying "your variable is declared Private" why am I getting this error ...
The document says "Private" declared variables should be accessed only through methods. What does that mean.
View Replies
View Related
May 10, 2014
public class Car
{
//instance variables ----------------------
private String make;
private String model;
private int year;
private double vehiclePrice;
private double downPayment;
private double milesPerGallon;
[code]....
I created this class "Car" (also not sure if it's correct) and need to write a driver program that creates two instances of the class Car. One must use the default constructor, and the other must use the non-default constructor. It must demonstrate the methods used in the Car class using those instances.
public class DriverCar
{
public static void main(String[] args) {
Car car1 = new Car("Toyota", "Corolla", 2013, 20000, 3000, 35);
Car car2 = new Car("Ford", "Taurus", 2005, 14000, 1500, 25);
System.out.println(car1);
[Code] ....
View Replies
View Related
Oct 15, 2014
I need to access Oracle database without using ODBC driver using DAO only, how to do that...
View Replies
View Related
May 13, 2014
Assignment:
Create a class; call it Lab4a that will have one method called pull. This method does not return anything and requires no parameters.
-In the method, create three random integers in the range 1 to 7. The method will then display the three numbers to the terminal window.
-Now create a driver program, called SlotMachine, to invoke the pull method of the Lab4a class.
-As a refresher, you will have a main method in the driver class that will create an object of Lab4a and then use the only method of this object.
-In your driver program, invoke the roll method 10 times.
-See the back of this lab for an example of the output.
This is what I have so far.
Slot machine
import java.util.Random;
public class Lab4a {
public static void main (String[]args) {
Random pull=new Random();
[code]....
View Replies
View Related