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//
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) {
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. */
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
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:
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");
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.
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
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();
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
System.out.println("Enter the first score"); test1 = keyboard.nextDouble(); System.out.println("Enter the second score"); test2 = keyboard.nextDouble();
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?
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();
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 ?
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
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.
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.
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');
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.
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);
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;
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.