Setting Up A Test For Combination Method

Nov 18, 2014

I'm having trouble setting up a test for my combination method.Here's the method (It basically finds the most amount of characters that both substrings share and combines the two using the number of shared characters as a breaking point):

public static String combination(String str1, String str2, int overlap) {
assert str1 != null : "Violation of: str1 is not null";
assert str2 != null : "Violation of: str2 is not null";
assert 0 <= overlap
&& overlap <= str1.length()
&& overlap <= str2.length()
&& str1.regionMatches(str1.length() - overlap, str2, 0, overlap) : ""
+ "Violation of: OVERLAPS(str1, str2, overlap)";

[code]....

View Replies


ADVERTISEMENT

How To Test Object Boolean Method

Feb 18, 2014

I have been writing test scripts for my class but I'm stuck on this method. how do i test for an object?

@Override
public boolean equals(Object obj) {
if (obj.getClass() != Fraction.class)
return false;
return (this.toString().equals(obj.toString()));
}

View Replies View Related

Setting All Variables In Class To Null Or 0 To Make A New Method To Clear Everything

Mar 31, 2014

I am very Java illiterate and I need to know how would i set all the variables in the first class to null or 0 to make a new method to clear everything.

import java.util.Arrays;
import java.util.Scanner;
public class studentMethods
{
private double totalScore;
private int count;

[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

How To Test And Finish ToString And Equals Method In Code

Jan 19, 2014

Write a class encapsulating 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.

how to test and finish the toString and equals method in this code ?

package labmodule7num57;
import java.util.*;
public class LabModule7Num57 {
// Constructors//
private String name;
private String letterGrade;
public LabModule7Num57 (String name,String letterGrade) {

[code]....

View Replies View Related

Represent Time Span Of Hours And Minutes Elapsed - Method Is Undefined For Type TEST

Jul 29, 2014

I am trying to run a class with a client code and I get the following error

The method add(TimeSpan) is undefined for the type TEST

Why i get this error?

package timespan;
// Represents a time span of hours and minutes elapsed.
// Class invariant: minutes < 60
public class TimeSpan {
private int hours;
private int minutes;

[Code] ....

View Replies View Related

While Loop In Combination With A Scanner

May 17, 2014

I have the following task given to me (to be solved in NetBeans) :

View the contents of the file tuinman.txt: each line has a (real) number, followed by a line text.

Write the readGardener () method that reads the file completely. Only if the number is negative, write the rest of the line. (For each input line, a new line output.)

Extra: Adjust your method so you get the text after each negative number, written "word by word", among themselves. A word can contain characters that are not "letters" are (,,. '") - ,this you may ignore.

"tuinman.txt" is dutch for "gardener.txt". This txt file is located in the same map where build,nbproject,src, etc... are located. I couldn't solve this task so i looked at the solution. It didn't work... So i tried the solution of the extra bit:

package labo.pkg2;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Methods {
public void readGardener() throws FileNotFoundException {

[Code] ....

The txt file is added as an attachment to this post.

The weird thing is, the first thing the program prints is "Van" "morgen" "ijlt",... wich are words from line 19 in the txt file. All the ones before line 19 the program won't print, even if the number is negative. Even weirder, the next thing that is printed after line 19 is the NUMBER from line 20, nowhere in this code do i tell the program to print a number, and yet it does... But that's not all! From line 19 on, he just prints every single thing in the document except for the negative number, if your mind didn't explode already, it sure did now!

So in short: I need some code that prints all the lines from the txt files that start with a negative number. Only the text may be printed though, there may be no numbers in the output!

The txt file, i couldn't add it as a attachment

123
-456,12 De tuinman en de dood
184,67 was hij, Kees, de enige die het zag, want niemand lette d'r op...
-845,14
-8,12452 Een Perzisch Edelman:
157,24 Dus daar gaan we dan.

[Code] ....

View Replies View Related

Passing Object As Parameter - Combination Values Are All Zero

Mar 8, 2015

I have an object that has an instance of another object class as its parameter :

CombinationLock oneHundred = new CombinationLock(28,17,39);
Locker Mickey = new Locker(100, "Mickey", 3, oneHundred);

This is for a locker, which has a combination assigned to the student. Within the locker class I have the following constructor:

public Locker(int locker, String student, int numberOfBooks, CombinationLock combo) {
this.locker = locker;
this.combo = combo;
this.student = student;
this.numberOfBooks = numberOfBooks;
}

combo is the private CombinationLocker object I created within the Locker class. Do I need to pass the combo object on to the CombinationLock class? For reason, I do not comprehend, the combination password from the main class is not passing through to the CombinationLock class, and the combination values are all zero.

View Replies View Related

Repaint Work In Combination With PaintComponent (Graphics)?

Oct 3, 2014

I am teaching myself AWT/Swing ... It concerns an application that creates dynamic graphics using the Graphics class. I understand that the code that creates graphics should be put in a "paintComponent" method of a (descendant of a) JPanel class. And that when you want to change something on this panel outside "paintComponent", you have to call the "repaint" method, that somehow causes "paintComponent" to be invoked.

However, I don't fully understand the explanation of the example at [URL]... . It concerns an application that moves a red square when a mouse button is clicked. The code can be found at the link, but I also repeat it below.

package painting;
import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;

[Code]...

This code indeed works. However, I don't understand why. The explanation at the Oracle site is the following.

Because we are manually setting the clip, our moveSquare method invokes the repaint method not once, but twice. The first invocation tells Swing to repaint the area of the component where the square previously was (the inherited behavior uses the UI Delegate to fill that area with the current background color.) The second invocation paints the area of the component where the square currently is.

However, what I don't understand: when repaint is first invoked, squareX and squareY still have their old values. If the invocation of repaint simply causes an invocation of paintComponent, then paintComponent should draw a red square at (squareX, squareY). Just like the second invocation of repaint causes paintComponent to draw a red suare at the new values of (squareX, squareY). Instead, the first invocation results in the red square being wiped out by the background color.

So apparently, the first invocation of repaint does not simply cause an invocation of paintComponent. What does it do?

View Replies View Related

Swing/AWT/SWT :: Creating A Combination Lock That Consist Of Three Strings

Oct 23, 2014

I need to use a counter to keep track of user's input. In this class I am trying to create a combination lock that takes three strings. In the tester class the user inserts three strings and both are compared to see if users input matches correct combination. I have no errors only problem is the setPosition method. My output is always false.

public class CombinationLock {
private String first;
private String second;
private String third;
private String firstGuess;
private String secondGuess;
private String thirdGuess;
private boolean open;
private int counter;

[code]....

View Replies View Related

Image Processing Pattern Matching / Combination Algorithm

Jun 9, 2014

The problem I am trying to solve relates to block-matching or image-within-image recognition. This is an algorithm problem I am working on in java, but computationally, my computer can't handle generating all the combinations at one time.

I see an image, extract the [x,y] of every black pixel and create a set for that image, such as

{[8,0], [9,0], [11,0]}

The set is then augmented so that the first pixel in the set is at [0,0], but the relationship of the pixels is preserved. For example, I see {[8,0], [9,0]} and change the set to {[0,0], [1,0]}. The point of the extraction is that now if I see {[4,0], [5,0]}, I can recognize that basic relationship as two vertically adjacent pixels, my {[0,0], [1,0]}, since it is the same image but only in a different location.

I have a list of these pixel sets, called "seen images". Each 'seen image' has a unique identifier, that allows it to be used as a nested component of other sets. For example:

{[0,0], [1,0]} has the identifier 'Z'

So if I see:

{[0,0], [1, 0], [5,6]}

I can identify and store it as:

{[z], [5, 6]}

The problem with this is that I have to generate every combination of [x,y]'s within the pixel set to check for a pattern match, and to build the best representation. Using the previous example, I have to check:

{[0,0], [1,0]},
{[0,0], [5,6]},
{[1,0], [5,6]} which is {[0,0], [4,5]}
{[0,0], [1,0], [5,6]}

And then if a match occurs, that subset gets replaced with it's ID, merged with the remainder of the original set, and the new combination needs to be checked if it is a 'seen image':

{[z],[5, 6]}

The point of all that is to match as many of the [x,y]'s possible, using the fewest pre-existing pieces as components, to represent a newly seen image concisely. The greedy solution to get the component that matches the largest subset is not the right one. Complexity arises in generating all of the combinations that I need to check, and then the combinations that spawn from finding a match, meaning that if some match and swap produces {[z], [1,0], [2,0]}, then I need to check (and if matched, repeat the process):

{[z], [1,0]}
{[z], [2,0]}
{[1,0], [2,0]} which is {[0,0], [1,0]}
{[z], [1,0], [2,0]}

Currently I generate the pixel combinations this way (here I use numbers to represent pixels 1 == [x,y]) Ex. (1, 2, 3, 4): Make 3 lists:

1.) 2.) 3.)
12 23 34
13 24
14

Then for each number, for each list starting at that number index + 1, concatenate the number and each item and store on the appropriate list, ex. (1+23) = 123, (1+24) = 124

1.) 2.) 3.)
12 23 34
13 24
14
---- ---- ----
123 234
124
134

So those are all the combinations I need to check if they are in my 'seen images'. This is a bad way to do this whole process. I have considered different variations / optimizations, including once the second half of a list has been generated (below the ----), check every item on the list for matches, and then destroy the list to save space, and then continue generating combinations. Another option would be to generate a single combination, and then check it for a match, and somehow index the combinations so you know which one to generate next.

How to optimize what I am doing for a set of ~million items. I also have not yet come up with a non-recursive or efficient way to handle that each match generates additional combinations to check.

View Replies View Related

How To Generate Alternate Color Of Balls Combination For 3 Boxes

Feb 24, 2014

I am working on a project in which I have three box (as of now) and each box will have some color of balls. So I am storing them in a Map of String and List of String as mention below.

Map<String, List<String>> boxBallMap = new LinkedHashMap<String, List<String>>();

Data in the above map is like this -

Java Code:

{box1=[blue, red, orange]}
{box2=[blue, red]}
{box3=[blue, red, orange]} mh_sh_highlight_all('java'); ProblemStatement:-

Basis on the above input, I need to return a mapping which will be List<Map<String, String>>, let's say for above input, below mapping would be return as an output -

Java Code:

[{box1=blue, box2=red, box3=orange},
{box1=red, box3=blue},
{box1=orange, box2=blue, box3=red}] mh_sh_highlight_all('java');

Here if you see, each row has alternate color of balls for each box - meaning blue for box1, red for box2, orange for box3 in first row. I cannot have same color of balls in each row. So this combination is not possible as it has same color of balls for two boxes in one row.

Java Code: {box1=blue, box2=blue, box3=orange} mh_sh_highlight_all('java');

And also, in the second row, I won't use those balls which have been used in the first row for that box. In second row, box1 has red why? bcoz blue was already used in the first row for box1 and box3 has blue and no box2 in second row.

The output combination is getting generated basis on the input being passed as shown above.

I started with the below code -

Java Code:

List<String> balls1 = Arrays.asList("red", "blue", "orange");
List<String> balls2 = Arrays.asList("red", "blue");
List<String> balls3 = Arrays.asList("red", "blue", "orange");
Map<String, List<String>> maps = new LinkedHashMap<String, List<String>>();

[Code] ....

Below is my method in which the crux of logic should be there

Java Code:

private static List<Map<String, String>> generateMappings(Map<String, List<String>> map) {
return null;
} mh_sh_highlight_all('java');

Below algorithm might work but still not sure how should I fit this in the code -

- sort the boxes by the number of balls they have in it (ascending, from the smallest to the largest box).
- while there are colors left
- loop over the sorted list of boxes
- in each iteration pick a color from the box (if there is one left), that is not already picked in the current iteration (of the while loop)

View Replies View Related

Validate String Whether It Is Combination Of Lowercase And Uppercase And Has Character

Jun 22, 2014

I have to validate a string whether it is a combination lowercase and uppercase and has the character '_'.

I m having trouble in framing the expression for these conditions in the matches function.

How it can be done..?? How to frame a the correct expression.

View Replies View Related

Telephone Number - Write To A File Every Possible Seven-letter Word Combination

Nov 23, 2014

I am having some trouble with this program. The assignment is to write a program, given a seven-digit phone number, uses a PrintStream object to write to a file every possible seven-letter word combination that corresponds to that number. I have to avoid using 0 or 1. Here is my code.

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;
public class TelephoneGenerator
{
String phoneNumber;
char numberLetters[][] = {

[Code] ....

I am getting an error dealing with the main class.

View Replies View Related

Create N Number Of Flows With Any Combination Of Values - Search Match

Apr 12, 2015

I have a requirement like to attach most suitable flow  to a request
  
Flows should be like below (eg:Flow1) .We can create n number of flows with any combination of values.

When I tried to create a request that have all the  features in the flow. And I have to attach the most suited flow to that request.

Suppose my request have the feature  Place = Place1 and company =Comp1 and Job=Job1 .here most suitable flow is Flow1.

So my question is how can I implement the logic in java for getting the most suitable match.

View Replies View Related

Retrieving Result By User Input Different Combination Using String Tokenizer (MYSQL)

Mar 30, 2014

I am creating a simple Symptom Checker application. The problem I have is that I'm trying to retrieve user input (JTextField) by comma's using StringTokenizer which contacts the database for a result which matches the user's input (SELECT * FROM DIAGNOSIS WHERE ?, ?, ?) . It successfully finds the correct result however only in a particular format. Not different combinations....

for example, if I enter say within the JTextField: "tearful, nausea, lack of motivation" it will find the result successfully (as that is how it is formatted within the particular column (in the database table) i wish to display a result from) however, if i enter a different combination of these symptoms: "nausea, lack of motivation, tearful" - it will not find any result. I'm very unsure how to make it work regardless of what is inputted first, second or last.

Here is the code:

public void actionPerformed(ActionEvent e) {
try {
String abc = fieldsymp1.getText();
StringTokenizer str = new StringTokenizer(abc);
while (str.hasMoreTokens()) {
str.nextToken((", ")).trim();
 
[Code] ....

View Replies View Related

Vending Machine - Tell User Combination Of Coins That Equals To Amount Of Change

Jan 25, 2012

I have a simple java program to write which tells the user combination of coins that equals to the amount of change i.e:

user input 87

output:

3 quarters
1 dime
0 nickels
2 pennies

How the program remembers the remainder which is passed to the next column of let say dime

i.e

originalAmount = amount;
quarters = amount /25;
amount = amount % 25; <---- this is confusing for me?!?! how can the integer = integer % 25
dimes = amount / 10; <--- HOW THE PROGRAM remembers the "remainder" instead of the original user input as the code it self tells you dimes = amount where "amount" is what user input NOT remainder.

amount = amount % 10;
so on ....;

What I don't understand is HOW this algorithm works. I mean we have int amount where user inputs the number we get the first calculation amount/25 = how many quarters and then amount %25 WILL tell us about the reminder. By looking at this piece of code I would say that the system should start the calculation for the dimes again from the original number since the code says dimes = amount/10 AND amount = amount%10. My understanding is that the calculation should be done from the original user input.

Book or code it self is not clear for me how the reminder is "REMEMBERED" and then pass on to the next calculation>!?!?

UNLESS the code: amount=amount%25 gets the remainder so the next code under it is REQUIRED to read from the last prompt code.

View Replies View Related

Region Is Created Dynamically Using Combination Of Pre-existing Region

May 8, 2014

I'm trying to add a feature to my game where a region is created dynamically using a combination of a pre-existing region.This part of the game will be a sort of adventure where the place is different every time.This is a picture of the original location, when called, the server would copy parts of this region and make an instance of a new region.This new region will always have the coordinates [6, 6] as the starting room. Each room has a certain number of doors used to get across each room.Here's a picture of the new region and all the potential spots the rooms can be placed.

new DungeonFloor(new int[] { 8, 632 }, FloorType.BASE_FLOOR, new int[] { NORTH, SOUTH, EAST, WEST }),
new DungeonFloor(new int[] { 8, 630 }, FloorType.BASE_FLOOR, new int[] { NORTH, SOUTH, WEST }),
new DungeonFloor(new int[] { 8, 628 }, FloorType.BASE_FLOOR, new int[] { NORTH, SOUTH, }),
new DungeonFloor(new int[] { 8, 626 }, FloorType.BASE_FLOOR, new int[] { SOUTH, WEST }),
new DungeonFloor(new int[] { 8, 624 }, FloorType.BASE_FLOOR, new int[] { SOUTH }),

Here's a picture of the dungeons.The parameters are as follows

[] { regionX and regionY } // Used to copy the original location
Type of floor
The door directions of that original location

These are all the same room except the doors are different. Each room can be rotated to make the doors work.The problem:I need an algorithm that finds a starter floor with the correct number of doors, places it at (6, 6).Places the best boss floor at any region makes a map around the boss floor covering x number of rooms. x being a parameter that's sent with the method call.

The code so far:

List<DungeonFloor> allFloors = Arrays.asList(DungeonRepository.DUNGEON_FLOORS);
List<DungeonFloor> starterRooms = new LinkedList<DungeonFloor>();

for (DungeonFloor floor : allFloors) {
if (floors.type() == FloorType.BASE_FLOOR)
starterFloors.add(floor);
}

View Replies View Related

Setting X And Y For String

Feb 15, 2014

I have been learning java and studying Swing but now i have a problem, i want to set x and y coordinates for this

Java Code:

JLabel jlbWorld = new JLabel("You have spawned"); mh_sh_highlight_all('java');

But how (I have searched internet for answers but all of them have JPanel)

View Replies View Related

Setting A String Using If

Oct 23, 2014

Here are two codes that I am using but I have one that just doesn't work for some reason and the other does. Encode doesn't work. I don't need the Character.isAlphabetic for encode but not sure what I can use with 'if' to set the String encodedString.

Java Code:

private String prepareString(String plainText)
{
String preparedString = "";
for(int i = 0 ; i < plainText.length();i++)
if(Character.isAlphabetic(plainText.charAt(i)))
{
preparedString = preparedString+Character.toUpperCase(plainText.charAt(i));

[code]....

View Replies View Related

Setting A Drive Label

Sep 22, 2014

I have been playing around with a snippet I wrote to get the Label on a drive (below). It works fine for me (though I will take any constructive criticism). My question is whether the is a way to set the drive label, purely with Java. I know I could call command line, or even resort to using the Windows API

import java.util.List;
import java.io.File;
import java.util.Arrays;

[Code]....

View Replies View Related

Error Setting Value For JSpinner

Apr 19, 2014

I'm using a jSpinner Number model:

Here's my code:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int qty2, total, payment, change;
String title;

[code]....

I tried using this since the jSpinner's minimum value is 1.. (I want it to reset the jSpinner after updating the database):

jSpinner1.setValue(new Integer(1));

But gives me an error:

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
at java.util.Vector.elementData(Vector.java:730)
at java.util.Vector.elementAt(Vector.java:473)
at javax.swing.table.DefaultTableModel.getValueAt(DefaultTableModel.java:649)
at shop.jSpinner1StateChanged(shop.java:267)
at shop.access$100(shop.java:22)
at shop$3.stateChanged(shop.java:145)
at javax.swing.JSpinner.fireStateChanged(JSpinner.java:457)

View Replies View Related

Setting Background Of JScrollPane?

Aug 19, 2014

My program's tree:

JFrame{
JPanel(That MenuBar at the top)
JPanel(That panel at center with table){
JScrollPane{
JTable
}
}
}

I want to add my custom image to that grey space right there. I guess it is a JScrollPane, because I added that orange background on JPanel that contains it. But when I add this code to my custom class of JScrollPane:

@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if(background == null){
background = new ImageIcon(ClassLoader.getSystemResource("tableBg.png")).getImage();
}
g.drawImage(background, 0, 0, null);
}

The result is the same, no changes.

Then I read some documentation. I found this method:

scrollPane.getViewport().setBackground(Color c);

It works, but it accepts only color and I want to add image. Is there any way to do that? Do I need to subclass JViewport and use paintComponent ? If yes, then how to make getViewport() method return my custom subclassed version?

View Replies View Related

Setting Values In PDF Field?

Dec 12, 2014

I have a PDF file and I have a text file that contains this data. It has the name of a PDF field along with a database table column name.

Text file: pdfFieldEmployee=Employee; pdfFieldStartDate=StartDate; pdfFieldSalary=Salary; pdfFieldExempt=Exempt

I also have this hash map that contains the database table column names along with their corresponding values:

Employee, Don Parker
StartDate, 5/6/2000
Salary, $55000
Exempt, N

How would I read through the text file and the hash map and at the same time do this:

if the pdf field is equal to pdfFieldEmployee, then set pdfFieldEmployee equal to Don Parker.
if the pdf field is equal to pdfFieldStartDate, then set pdfFieldStartDate equal to 5/6/2000.

and so on and so on. I would prefer to do this with a loop because I think it would take less code than writing a bunch of if statements.

View Replies View Related

Getting And Setting Frame Name From Another Class

Aug 7, 2014

package com.simbaorka101.te.gui;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.event.DocumentListener;

[code]....

This is my frame class, now I want to be able to change the name of the frame, and get the name with frame.getName() in another class. But I'm not sure how to do this, i tried making a new frame in that class but i feel it's just another frame and not the one i made, also tried something like

public JFrame getFrame(){
this.getFrame();
}

and few variations but it was wrong.

View Replies View Related

What Does Setting Object Equal To Another Do

Mar 5, 2014

I've seen this done in code:

For example:

Java Code: BufferedImageOp op = new ConvolveOp() mh_sh_highlight_all('java');

What does this mean? Is it creating an object of convolveOP for the BufferedImage class?

What does it mean when you set an object from one class equal to another?

View Replies View Related







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