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) {
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 have following Cipher Code and test for it. But I am getting following exception.
Java Code:
java.lang.IllegalStateException: Cipher not initialized at javax.crypto.Cipher.checkCipherState(Cipher.java:1672) at javax.crypto.Cipher.doFinal(Cipher.java:2079) at com.anjib.util.CipherUtil.encrypt(CipherUtil.java:67) at com.anjib.util.CipherTest.testEncryptDecrypt(CipherTest.java:23) mh_sh_highlight_all('java'); Java Code: public class CipherUtil { private static Logger log = Logger.getLogger(CipherUtil.class);
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.
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();
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
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();
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 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. */
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 am new to Java and I am trying to use values that are set for cases in the switch operator.
The first menu ask for you to pick a product and each product has a price on it.
The second menu ask you to pick a state with each state having a decimal value on it.
The third is asking you to put the number of cases and each case is 12 items.
A key note to remember is that each part that a person is choosing is on a different instance!
Here is an example of what i am trying to do.
Menu 1: I picked case 1 that is Computer and it is worth 1000 Menu 2: I picked case 1 that is CT and it's tax is 7.5
Third choice: I picked case 1 and that has 12 items
I want the subtotal witch is: (1000 * 12)
Subtotal in this situation is: 120000
Next i need the total value which is based on what state they picked for the tax percent value picked from the state menu case: (12000 * 0.075 + 120000)
Total value is: 129000
I will post the code I have but based on the choices a person makes will determine the values and I need those values set in the cases to put in a math equation. The problem I am having is retrieving these numbers form the cases inside the menu options and they are on a different instance. So How can I do this in Java code?
Here is the code:
This is menu 1
Java Code:
import java.util.*; //scanners and more class menu{ public void display_menu() { System.out.println ("Please select your product"); //Gives user direction System.out.println ( "1)
There are few modules in our application whose performance degrade with time when 50-100 simultaneous users are working on them at a given instance.The memory allocations are taken care of to allow maximum data.My issue to where to start finding the root cause.
I am currenlty using JvisualVM for profiling and finding memory leaks..Do i need to Simualte 50-100 virtual users and start finding the memory leaks with JvisualVM or working with a single user would do ?
Looking for some simple use cases for servlet filters other than tracking requests ? I was thinking of using a filter to filter out offensive language from entered text. Would that be a good use case ?
I'm a new Java user and I'm trying to code a simple login page. In first page (NewFile.jsp) users should enter their username and password and should click on "login", or click on "sign up".
1.) If user enters his username and password correctly, a login page (LoginPage.jsp) appears and says "welcome null" but it should show the name of that user instead of null.
2.) In that login page there is an edit button to edit profile information. When I clicked on it, every information is "null" and when I edit them and click on "Submit" button;
HTTP Status 404 - type Status report message description The requested resource () is not available. GlassFish Server Open Source Edition 3.1.2
that message appears.
3.) If I click on "Sign Up" button at the beginning, a registration jsp (SignUpPage.jsp) appears. After filling up text boxes and clicking on "Submit", same Status 404 screen appears.
I created a mysql database called "loginpage" using xampp. In that database there is a table called "users" and it has un, pass, name, surname, email and degree attributes.
I know void means it doesn't return anything but to me when I think it doesn't return anything it just does equations and other things. So why can you use this? Or is Void like returning input such as a Scanner?
I am trying to make a custom texture system for a block in Minecraft, I am not too advanced with Java and am not sure how to make this work the way I want it to.
Java Code:
/** The list of the types of step blocks. */ public static final String[] blockStepTypes = new String[] {"stone", "sand", "wood", "cobble", "brick", "smoothStoneBrick", "netherBrick", "quartz"}; private Icon missing; private Icon icon1; /** * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata */
[code]....
Alright, so basically I figured I could just tell the code to see if the block is made out of Stone, then to set the texture to Stone, or if it's made out of Sand, then set it to Sand.What I usually get is Eclipse telling me to "insert '!= null' check", "insert '!= null' check", and then just error out saying "Opperator != is undefined for the argument type(s) boolean null"
I have a program that I have created from scratch called Product and I also created a Tester program to test my theory. The only problem that I have is that I am getting an error with this statement System.out.printf statement. The statement needs to print out "Program [name = HP ENVY x360 TouchSmart, price = $xxxxxx". The error states that "The method printf(String, Object...) in the PrintStream is not applicable for the arguments (String, String, void).
Which tells me that it is referencing back to the class file where I have
public void applyDiscount(double percent) { percent = price - (price * percent); //establishing the discount }
The lines of code in my tester file are (partly displayed)
String formatString = "Product[name = %s, price = %.2f]"; System.out.printf(formatString, product.getName(), product.getPrice()) //user input the discount amount System.out.println("Enter discount percentage [0 - 100]: %.2f "); double discount = user_input.nextDouble(); System.out.printf(formatString, product.getName(), product.applyDiscount(discount)); //This is the line giving me an error. }
I want to have parameters that I use the "void" for, in other words it doesn't return anything.
class code { void go() { int TestStuff t = new TestStuff(); t.takeTwo(12,34) } void takeTwo (int x, int y) { int z = x + y; System.out.println("Total is:" + z); } }
import javax.swing.JOptionPane; public class Input { public static void main(String[] args) { int user; user = JOptionPane.showMessageDialog(null, "Enter Your Age""); ERROR IS HERE if(user <= 18) { JOptionPane.showMessageDialog(null, "User is legit"); } else { JOptionPane.showMessageDialog(null, "User is not legit"); } } }
I'm getting this error message :
incompatible types: void cannot be converted to int