How To Write A Client Class To Test Methods For Assignment

Jan 20, 2014

Write a class encapsualting the concept of a course grade, assuming a course grade has the following attributes: a course name and a letter grade. Include a constructor, the accessor and mutator, and methods toString and equals.Write a client class to test all the methods in your class.

package labmodule7num57;
import java.util.*;
public class LabModule7Num57 {
// Constructors//

[code]....

View Replies


ADVERTISEMENT

How To Write Driver Class To Test Methods

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

How To Write Test Cases For Void Methods

Mar 19, 2014

I'm trying to write test cases for void methods. Here is my sample code

public void objIntoFile() throws Exception {
addAdminObjects();
file = new File("D:ExtractingDBexport.txt");
writer = new BufferedWriter(new FileWriter(file));

[Code] .....

View Replies View Related

Methods From Original Class Receiving Error When In Test Class

Jul 5, 2014

I am working on a program that simulates a bug moving along a horizontal line, My code works correctly when I test it in it's own class but when I tried testing my constructor and methods in a test class I received an error saying, "package stinkBug does not exist" on lines with my methods. However, stinkbug is not a package.

Java Code:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

[code]....

View Replies View Related

Create Two Instances Of Class And Test Each Of Methods

Nov 1, 2014

How do I use two constructors and I'm having trouble with using char for gender...

Write a program to test the Person class defined below. Your test program should create two instances of the class (each to test a different constructor) and test each of the methods. You are also required to illustrate the error in trying to access private data members from the client class (for clarity temporarily change the private modifier to public and test again). See screenshots below for sample output.

The screen shots are displayed as:

p1 name = Not Given Age = 0 Gender = U
p2 name = Jane Doe Age = 0 Gender = F
p1 name = John Doe Age = 25 Gender = M

and

PersonTester.jave:20: name has private access in Person
System.out.println("p2 name = " + p2.name + "Age = " + p2.age + "Gender = " + p2.gender);
 PersonTester.jave:20: age has private access in Person
System.out.println("p2 name = " + p2.name + "Age = " + p2.age + "Gender = " + p2.gender);
  PersonTester.jave:20: gender has private access in Person
System.out.println("p2 name = " + p2.name + "Age = " + p2.age + "Gender = " + p2.gender);
 
3 errors

Here is the class given :

class Person {
// Data Members
private String name; // The name of this person
private int age; // The age of this person
private char gender; // The gender of this person
 
[Code] .....

View Replies View Related

Unable To Call / Test All Of The 5 Sorting Methods At Same Time In Main Class

Dec 19, 2014

For reference I am programming Java in BlueJ. I am fairly new to the language and I am having trouble with sorting.

I am trying to call / test all of the 5 sorting methods (at the same time) in the main class. To be specific, the sorted list has to technically outputted 5 times.

I figured out how to call / test Quicksort:

Sorting.quickSort(friends, 0, friends.length-1);

But the others are not working correctly. Specifically these:

Sorting.mergeSort(friends, 0, friends.length-1);
Sorting.PbubbleSort(friends, 0, friends.length-1);
Sorting.PinsertionSort(friends, 0, friends.length-1);
Sorting.selectionSort(friends, 0, friends.length-1);

For reference, this is the output when it is not sorted:

Smith, John 610-555-7384
Barnes, Sarah215-555-3827
Riley, Mark 733-555-2969
Getz, Laura 663-555-3984
Smith, Larry464-555-3489
Phelps, Frank322-555-2284
Grant, Marsha243-555-2837

This is the output when it is sorted:

Barnes, Sarah215-555-3827
Getz, Laura 663-555-3984
Grant, Marsha243-555-2837
Phelps, Frank322-555-2284
Riley, Mark 733-555-2969
Smith, John 610-555-7384
Smith, Larry464-555-3489

This is the class Sorting, which I should note is all correct:

public class Sorting{
/**
* Swaps to elements in an array. Used by various sorting algorithms.
*
* @param data the array in which the elements are swapped
* @param index1 the index of the first element to be swapped
* @param index2 the index of the second element to be swapped
*/
private static <T extends Comparable<? super T>> void swap(T[] data,
int index1, int index2){
T temp = data[index1];
data[index1] = data[index2];

[Code]...

This is the Main class in which I am supposed to call the sorting methods, SortPhoneList:

public class SortPhoneList{
/**
* Creates an array of Contact objects, sorts them, then prints
* them.
*/
public static void main (String[] args){
Contact[] friends = new Contact[7];
friends[0] = new Contact ("John", "Smith", "610-555-7384");
friends[1] = new Contact ("Sarah", "Barnes", "215-555-3827");

[Code]...

View Replies View Related

Write A Class Named Calculator Add Four Methods To That Class

Jan 30, 2014

Write a class named Calculator add four methods to that class:

add(int a, int b)
sub(int a, int b)
mul(int a, int b)
div(int a, int b)

Then write a Tester class with main function and show the use of the methods in Calculator class..

View Replies View Related

Write A Program That Use Java String Class Methods

Feb 10, 2015

There are two versions

1. The words remain in their places but the letters are reversed. Eg I love you becomes Ievol uoy
2. The words are also reversed. Eg I love you becomes uoy evol IWrite a program that use the java String class methods.

View Replies View Related

Using MATH Class For Assignment?

Sep 18, 2014

Here is the assignment:

Prompt the user to input two sides (a and b) of a right triangle. Calculate, using the

formulas below, the hypotenuse and the other two angles of the triangle. Calculate the

perimeter and the area.

Here are the formulas:

a^2 + b^2 = h^2

sinθ = a/h

A + B + C = 180 degrees

how to start this program out, i know which math classes i need to use.

View Replies View Related

Assignment To Create A Sphere Class

May 8, 2015

I have an assignment to create a Sphere class that will allow you to create Sphere objects using the code below. Then create a program called SphereTester that prompts the user for the radii of two spheres in meters. The program should display which sphere is larger and by how many cubic meters and display only four digits after the decimal point. I have the sphere class given to us for the assignment which is this:

public class Sphere {
// instance variable (i.e., a field)
private double radius;
// constructor for the Sphere class
public Sphere(double r) {
radius = r;

[code]....

Here is a sample run of what the final result should look like

Enter the radius of a sphere (in meters): 1
Enter the radius of a 2nd sphere (in meters): 2
Sphere 2 is greater than Sphere 1 by 29.3215 cubic meters

View Replies View Related

How To Write JUnit Test Classes For Application

Apr 16, 2014

I am working on a class project and I have to write the JUnit test for the GUI class ... what I did wrong ... Here is the code for the GUILauncher:

package edu.oakland.production;
import java.awt.*;
import javax.swing.*;
public class GUILauncher{
public static void main(String[] args){
RetrieveWindow gui = new RetrieveWindow();

[Code] .....

View Replies View Related

Write A Program That Asks Users To Input 5 Test Scores

Apr 22, 2015

Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program:

calculateAverage This method should accept five test scores as arguments and return the average of the scores. determineGrade This method should accept a test score as an argument and return a letter grade for the score, based on the following grading scale

Score Letter Grade
90-100 A
80-89 B
70-79 C
60-69 D
Below 60 F

double test1,test2,test3,test4,test5;
double average;
char grade;

Scanner keyboard = new Scanner(System.in);

System.out.println("Enter the first score");
test1 = keyboard.nextDouble();
System.out.println("Enter the second score");
test2 = keyboard.nextDouble();

[code]....

View Replies View Related

Declaring Methods For A Class In Its Own Class Whilst Objects Of Class Declared Elsewhere?

Mar 5, 2015

How do you declare methods for a class within the class whilst objects of the class are declared else where?

Say for instance, I have a main class Wall, and another class called Clock, and because they are both GUI based, I want to put a Clock on the Wall, so I have declared an instance object of Clock in the Wall class (Wall extends JFrame, and Clock extends JPanel).

I now want to have methods such as setClock, resetClock in the Clock class, but im having trouble in being able to refer to the Clock object thats been declared in the Wall class.

Is this possible? Or am I trying to do something thats not possible? Or maybe I've missed something really obvious?

View Replies View Related

Relate Fraction Objects With Read / Write Methods Used In Binary I/O

Apr 25, 2014

We're learning how to use Binary I/O commands...which equates to....

My issue is trying to relate the Fraction objects (which we are to create using a loop) with the read/write methods used in Binary I/O (input/output streams). I left a blank after the output.write(), so you can see where the issue exist.

Java Code:

import java.io.*;
public class FractionTest {
public static void main(String[] args) {
int [] fraction = new int[3];
for(int i = 0; i <= fraction.length; i++){
Fraction numbers = new Fraction();

[Code] ....

View Replies View Related

How To Test If Class / Object Is Immutable

Jul 2, 2014

I have make the immutable class as below, Now my question is how I can test if my this class/object is immutable

package com.learning;
import java.util.*;
import java.util.Map.Entry;
public final class ImmutableTest {
private final int id;
private final String name;
private final HashMap<String, String> hm ;

[Code]...

How I can Test If it is immutable class without looking ?

View Replies View Related

Binary Tree Java Test Class

Mar 24, 2014

So, managed to get my Binary Search Tree to work properly:

package SystemandDesign.BinaryTree;
 import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
import java.io.ObjectInputStream;
import java.util.Scanner;
 
[Code] ....

No matter how many times I keep rewritting the testInsert method I get a chock full of errors.

View Replies View Related

How To Test Default Constructor In Different Class In Java

Nov 5, 2014

How do you test a default constructor in one class and then test it in a different class? This is the code for the Person class which has the default constructor. I'm not sure in the PersonTester class how to access this default constructor and how to test it - what I have so far for the second class is also below.

class Person {
// Data Members
private String name; // The name of this person
private int age; // The age of this person
private char gender; // The gender of this person

[code]...

View Replies View Related

Writing A Test Class Using (invoke) Method

May 4, 2015

I had to write a class called Thermometer, that has one instance variable (an integer) for the temperature in Fahrenheit. I had to include the following methods

-a constructor that initializes the temperature to 60

-there is a method to change the temperature

-there is a method to display the temperature

-there is a method to reset the teperature to 60

Here is the code for that.

public class Thermometer {
private int temp;
private int thermometer;
public Thermometer() {
thermometer = 60;

[code]....

Now I get to the issue. I have to write a test class called thermometer to test the thermometer class. I need to test each method while displaying the temperature after it. My professor said I should use the invoke method but didn't go into much more detail than that.

View Replies View Related

Writing A Program To Test Person Class

Nov 4, 2014

User-defined classes. The concept of getters and setters goes right over my head. Right now we're to write a program to test the Person class below. We have to create 2 instances of the class to test each constructor, and test each method.

class Person {
// Data Members
private String name; // The name of this person
private int age; // The age of this person
private char gender; // The gender of this person
// Default constructor
public Person() {
this("Not Given", 0, 'U');

[code]....

then my output will print out the name. But the assignment doesn't tell us to modify the Person class at all, just to create a tester one.

View Replies View Related

Test To See If Object Is Instance Of Interface Class

Mar 7, 2015

I am currently trying to use Junit to test a whole bunch of stuff. I almost have full line coverage but I am getting hung up on testing an if statement that consists of whether or not an object is an instance of another class. This class happens to be an interface, and even the object is an interface. Weird I know but I just want to know how to get into that if statement. I realize testing interfaces might be a waste of time but I still really want to know how. Here is an example of what I am trying to test:

Java Code:

if(x instance of y){ //where x and y are both interface objects
doSomething();
} mh_sh_highlight_all('java');

View Replies View Related

Inheritance In Java - Child Class Get Copy Of Methods And Variables Of Parent Class?

Mar 1, 2015

Does child class gets a copy of the methods and variables of parent class?

public class test1 {
public static void main(String a[]) {
Child c = new Child();
c.print();

[Code] ....

why is the output 1?

View Replies View Related

JUnit - Test Class Not Found In Selected Project

Jul 21, 2010

I'm trying to write JUnit test but I'm having trouble with the following errors:

"Test class not found in selected project" -> when running AClassTest.java

"Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class" -> when running AClass.java

I have class AClass.java

and class AClassTest.java

They both are in the same package and there is JUnit library

Here's the code:

AClass.java:

Java Code:

public class AClass {
working code is in the last post
} mh_sh_highlight_all('java');
AClassTest.java:

Java Code: public class AClassTest extends TestCase {

working code is in the last post

} mh_sh_highlight_all('java');

View Replies View Related

How To Build Test Cases So When New Class Is Added It Automatically Gets Tested

Jul 2, 2014

I'm trying to develop a system for test cases so that whenever a test case is added to a particular package it will automatically be included in testing without having to manually add that particular test case.  What is the best way to achieve this?  Should I use java reflection? I'm just getting started with Jenkins and trying to configure Selenium test cases.

View Replies View Related

Client Class - Cannot Get Total Price To Recognize Surcharge

Apr 26, 2015

I am almost finished with my code. The only hangup I am having is that in my client class, I can't get the total price to recognize a surcharge.

This is my output:
-------------------------------------------------
Your order consists of:

coffee, type mocha, size large, cost: $5.8
tea, flavor earl grey, size medium, cost: $3.6

The total cost of your order is: $8.4
----------------------------------------------------
Notice that the total should be $9.4, rather than $8.4. It is odd because I was able to add a surcharge to my coffee(50 cents), and it does in fact recognize it when calculating the price of the coffee. So why won't my totalPrice in the client class recognize it?

Here is my Client class:

public class CoffeeShop {
public static void main(String[] args)
//One coffee
Coffee coffee = new Coffee(16,"mocha");
coffee.set_price_per_oz(coffee.size);

[Code] ....

View Replies View Related

Rational Number Class - Java Client Code For Testing

Mar 7, 2014

We are making a Rational Number class. After that we must create client code to test it out. The instructions-

•Create 3 instances of RationalNumber. Remember every time you say “new” you are creating an instance.
oOne of them should use the default constructor
oOne of them should use the constructor with one parameter
oOne of them should use the concstructor with two parameters.
•Print out the int and double value of each Rational Number
•Print out the sum (as a double) of all the numbers.
•Print out the sum (as an int) of all the numbers.

My rational number class :

public class RationalNumber{
private int numerator;
private int denominator;
public RationalNumber()
{
numerator =1;
denominator = 4;

[Code] .....

View Replies View Related

Client And Server Class For UDP Protocol Sending Integer Numbers By Packets

Apr 21, 2014

I have to write a client and server class for a UDP protocol sending integer numbers by UDP packets. So far i have this;

Client Code:

import java.io.*;
import java.net.*;
class UDPClient {
public static void main(String args[]) throws Exception {
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));

[Code] ....

But i now need to change this so that:

The client;

1. Reads an integer from keyboard input and stores its value in a UDP packet.
// byte[] send = ByteBuffer.allocate(4).putInt(num).array(); ???

2. Sends the UDP packet to the server, on port number 1999;

3. Listens for UDP packets from the server (until it receives a packet with a non-positive number; see
step (b) below). While listening:

(a) Once it receives a UDP packet from the server, it subtracts 2 from the integer value num contained in it.
// int num = ByteBuffer.wrap(receive).getInt(); ???
(b) Checks the integer value num: if the value is greater than 0 (num>0) then the client stores it in a new UDP packet and sends the packet to the server; otherwise (num<=0) the client terminates.

The Server;

1. Listens on port 1999;

2. For each UDP packet it receives from a client:
(a) extracts the integer value n contained in it;
(b) decreases the value of n by 2;
(c) sends back to the client a UDP packet containing the new value of n.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved