Writing A Method To Add Fractions
Apr 4, 2014
Okay so I have to write a method to compute the following series: m(i)= 1/3 + 2/5 +....+ (i / 2i+1) and write a test program that displays a table " i = m(i)" 1=0.3333 2=0.7333....all the way down to 20 which is 9.2480. I have written something and cannot seem to get the sum of the fractions to display .
public class ExtraCredit1
{
public static void main(String[] args)
{
double num;
double sum = 1;
[Code] ....
View Replies
ADVERTISEMENT
May 27, 2014
I have to write a method called censor that gets an array of strings from the user as an argument and then returns an array of strings that contains all of the original strings in the same order except those with length of 4. For example if cat, dog, moose, lazy, with was entered, then it would return the exact same thing except for the words with and lazy.
Currently, my code so far just prints [Ljava.lang.String;@38cfdf and im stuck.
import java.util.Scanner;
public class censorProgram {
public static void main (String args[]){
Scanner input = new Scanner (System.in);
System.out.println ("How many words would you like to enter?");
int lineOfText = input.nextInt();
[Code] ....
I have to make new string array in the method and return words without four letters in the main method
View Replies
View Related
Jan 13, 2014
I was writing a method to read a file. I did not think it through and gave the return type as void and modifier as static but I am not sure if it has to be void. How do you decide the return type of the method? Is there a good rule of thumb in such cases? Also, does the use of static needs to be done sparingly?
View Replies
View Related
Apr 3, 2014
how to sum up two numbers of fractions?
View Replies
View Related
Jan 29, 2014
I have the following code Java (is it just a meaningless example ), my question is: if I wanted to insert a code to multiply two fraction into moltiplicaPer() metod What should I write?
public class Frazione {
private int num;
private int den;
Frazione() {
num = 0;
den = 1;
[Code] ....
View Replies
View Related
Aug 5, 2014
I am currently working on a java project, this involves me writing some code for a project, below are my attempts at coding so far:
/**
* Prints out details of all animal in the zoo.
*
*/
public void printAllAnimals() {
System.out.println("
Details for all animals in Zoo " + zooId);
System.out.println( "==================================");
[code]....
I currently cannot get the printallanimals() method to work as it should when executing the method printallanimals it just opens a filedialog box, when it is suppose to use the Collection object c,so that animals stored in the zoo can easily be checked.
View Replies
View Related
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
Apr 19, 2015
The question is write to a method symmetric that accepts a stack of integers as a parameter and replaces the stack contents with itself plus a symmetrical version of itself (the same elements in the opposite order).
For example, suppose a variable s stores the following elements:
bottom [10, 50, 19, 54, 30, 67] top
After a call of symmetric(s),the stack would store the following elements
bottom [10, 50, 19, 54, 30, 67, 67, 30, 54, 19, 50, 10] top
Note that the symmetric version is added on to the top of what was originally in the stack. The bottom half of the stack contains the original numbers in the same order.
If your method is passed an empty stack, the result should be an empty stack.
If your method is passed a null stack, your method should throw an IllegalArgumentException.
a) Write the method symmetric using one temporary stack and one temporary queue.
/> Re-write the method using only one temporary Queue.
What I have done so far is
public static Stack symmetric(Stack s1){
Stack s2 =new Stack();
int theTop=0;
if(s1.isEmpty()){
return s1;
[Code] .....
Its not working.
View Replies
View Related
Jun 7, 2014
I'm trying to write an indexOf() method that will return every time a value occurs in a linked list. I need to use my user-created linked list not the built in Java linked list. For example in a linked list of characters: "i, p, z, z, n, d, p, z" when I search for "z" it should return position variables for 3, 4, and 8. Currently what I have is obviously only returning the first instance.how I can return more than one instance?
public int indexOf(char input) {
LLNode currentNode = this.first;
int position =1;
boolean found = false;
[code]...
View Replies
View Related
Oct 29, 2014
// Lab09ast.java
import java.util.Scanner;
public class Lab9a {
static int ReducedNum, ReducedDen; // numerator and denominator of the rational number
public static void main (String args[]) {
enterData();
Rational r = new Rational(ReducedNum,ReducedDen);
r.displayData();
[Code] .....
The code already displays a fraction that is entered by the user in decimal format but I also need to reduce the fraction using gfc. I have tried a lot of different things, but it will only display null or infinity/infinity.
View Replies
View Related
Mar 8, 2014
I'm just not noticing why it won't display the answer. I'm trying to solve this book problem......
"Write a for loop that calculates the total of the follower series of numbers:
1/30 + 2/29 + 3/28......+30/1"
Here is what I have..
public static void main(String[] args) {
double total = 0;
for (double a = 1, b = 30; b < 1; a++, b--) {
total += (a / b);
}
System.out.println(total);
}
}
When launched, the output is 0.0. I tried changing the variables a and b to doubles but didn't change anything...
View Replies
View Related
Mar 27, 2014
I was wondering if you use an IDE when writing programs?Can you use J frame when using command line or is it just used with an IDE and do you go into framing in the book?I have taken programming classes and I am still stuck.
View Replies
View Related
Mar 13, 2015
I'm using opencsv and I want to write two arrays into a csv file and each array should be in a column. For example:
Column1 Column2
2423542 2332332
5242324 4343434
4242352 7565656
4343434 6565656
public class Writer {
[Code] ....
With my code the arrays are all in one column. What do I have to change that my output will be in two columns?
View Replies
View Related
Jul 10, 2014
I am using a FileOutputStream to write a file but it is not writing data to destination file from source
Here is my code
package org.kishor.outputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class WriteToaFile {
public static void main(String args[]) throws IOException
{
FileOutputStream fout = null;
[code]...
find a bug where i am wrong why data is not on output file?
View Replies
View Related
May 17, 2014
I have copied a wav file as explained in [URL] ..... When trying to play my new file, it runs but no sound is hear. My reading and writing class is as explained in another post in the site:
This is the function that reads the file:
// read a wav file into this class
public boolean read(DataInputStream inFile) {
myData = null;
byte[] tmpInt = new byte[4];
byte[] tmpShort = new byte[2];
[Code] ....
I can't hear the copied wav file, but still the wav file is correctly copied...
View Replies
View Related
Sep 8, 2014
I am writing a program in Java where a user adds 1 stamp on a letter for every five sheets of paper in it (or fraction thereof)For example, I if I have 11 sheets of paper, I add 3 stamps. If the total number of stamps is more than 3, they don't send it.
I need to ask the user how many sheets of paper they have, and then calculate the appropriate number of stamps based on the formula above. I just don't know how to write the math formula to calculate this, i'm stuck. So far I have:
package test;
import java.util.Scanner;
public class LetterMailing {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
int numSheets;
[Code] .....
What should I do next?
View Replies
View Related
Sep 9, 2014
I've looked at multiple sources and everyone is saying different stuff. Which one should I be using? FileWriter/FileReader, other people was saying PrintWriter, and one even said : "Formatter" which is the one I'm doubting mostly. My purposes for writing files is for like saving maps, saving high scores, etc.
View Replies
View Related
Apr 11, 2014
I'm working on assignment for a class where I'm creating a home utility auditor. Basically the user has to pick from a list of appliances and then input various fields to calculate a total cost. When the user chooses "washer" from the list of appliances, they must enter in values for 2 separate fields, and will then click calculate to get total cost. I've been trying to implement this through an if, else statement, but it's not wanting to calculate a total cost and I'm running into errors. I've put the code below.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// The calculate button will multiply the 3 fields that the user inputs:
//cost*Kw used*hours used=total cost of operation
float num1,num2, num3, result;
//now, parse the text to a type float
num1= Float.parseFloat (costField.getText ());
[Code] ......
View Replies
View Related
Jan 10, 2014
I have accountsData.txt file in my default package, this is the file it should be writing to and reading from.
There is an ATM class, which has the main in it. From here the program is supposed to work like an atm, you type in your account number and can withdraw or deposit. It is supposed to then write the changes to the file.
//Read from a file.
public void loadAccounts(String inputFileName) throws IOException
{
Scanner fin = new Scanner(new File(inputFileName));
// Variables to store the values.[/color]
int account = 0;
double balance = 0.0;
[Code] .....
View Replies
View Related
Nov 11, 2014
public class Tester
{
public static void main(String[] args)
{
Product p1 = new Product();
p1.loadFromFile("Monitor.pr");
System.out.println("Actual: " + p1.toString());
System.out.println("Expected: Product [id=12345, name=Monitor, description=A freakin great monitor!]");
p1.setId(11111);
p1.setName("another product");
p1.setDescription("Description of another product!");
[code]....
The expected output is what my program should be doing and the actual output is what it's doing instead. As you can see, my code works for the middle test. But I cannot understand why it won't load the first fileFor the second half, the id and the quantity are separated by a comma... I'm not really sure how to deal with that. As you can see, I tried using a delimiter, but it doesn't seem to be doing any good.
View Replies
View Related
Nov 26, 2014
for x = 0 to 9
set stars = "*"
set count = 0
while count < x
stars = stars + "*"
count = count + 1
endwhile
display stars
endfor
I need to change this pseudocode to Java, but I'm new, been trying for ages but can't get it right.
View Replies
View Related
Feb 11, 2014
Recently I discovered power of Java, I'm coming from Perl, Python world so I'm at very beginning. I have firm understanding of OOP and I'm ready for new challenges. I have question regarding writing to database performance and theory.
Basically as my personal project I'm trying to write some small program or addon which will enable me to write concurrently to database. Let's say that I have some software and that has FIFO output to database in single stream, but since the output interface is not fast enough congestion can occur if the input to the system is high.
I would like to extend that software with addon which will take that one output stream and create 2,3,4 concurrent input streams towards database. API from that software is provided so I can redirect output to third-party extensions and apps.
View Replies
View Related
May 1, 2015
I thought you can use PrintWriter to write to the console but when I run the following code I only get "abc" printed to the console.
import java.io.*;
class Class1{
public static void main(String...abc) throws Exception{
PrintWriter writer = new PrintWriter(System.out);
writer.println("test");
System.out.println("abc");
}
}
View Replies
View Related
Mar 30, 2015
I realized I wasn't capitalizing certain things, and when I did it i was able to run the compiler. is there a utility or tool that auto formats the capitalization and such? I read kathy mentioning about eclipse I installed I don't know where that feature is.
View Replies
View Related
Oct 19, 2014
how to print from bluej onto actual paper? how to do the formatting and configuration etc.
View Replies
View Related
Dec 15, 2014
I need to write a program that, when a button is pressed, will add the user input to a table AND write it to a sequential data file. I have everything done accept for how to write the data sequentially(all input data on the same line in the file). The following is part of the code:
private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {
DefaultTableModel dtm = (DefaultTableModel)jTable1.getModel();
dtm.addRow(new Object[]{donorName.getText(),charityName.getText(),donationAmmount.getText()});
//Adds user input to the table
try
{
FileWriter writer = new FileWriter("FundraisingInformation.txt",true);//Creates file or adds to it
BufferedWriter bw = new BufferedWriter(writer);
[code].....
I would need the file output to be in the following format:
donorName charityName donationAmmount
As I said, using the .write(bw) i know how to make it look like:
donorName
charityName
donationAmmount
View Replies
View Related