Working Through Printf And Void

Sep 1, 2014

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.
}

View Replies


ADVERTISEMENT

Printing 2 Decimal Places - Printf Not Working?

Mar 22, 2014

I need to print to 2 decimal places and I'm trying to use the printf method, but for some reason I keep getting an error. I've looked through my code, but unless I'm missing a small detail, it looks okay to me.

float sum = 0;
float avg = 0;
double[] rain = {0, 1.9, 1.5, 1.2, 1.1, 0.5, 0.03, 1.0};
 
//Calculate sum of rain.
for (int i = 1; i <= 7; i++) {
sum += rain[i];
 
[Code] ....

View Replies View Related

Int Variables And Printf In Java

Mar 22, 2014

I write the following statement:

int num1 = (int)( 1000 * ( generator.nextFloat() ) );
System.out.printf("%d", num1);

and I get an error!

The weirdest thing is that 'num1' does NOT show in variables window. How can it be?

View Replies View Related

JGrasp - Printf Left Justify?

Sep 6, 2014

We're learning printf with JGrasp as the environment at the moment. Heres the problem.

I have a string as this:

String header1 = new String ("Caswell Catering and Convention Service");

as for the printf line, its this:

System.out.printf ("%-5s/n", header 1);

The output is right justified no matter the use of the "-" or without and I can't seem to find the correct thing to do to make it left justified.

View Replies View Related

Format Output Correctly Using Printf Function

Nov 6, 2014

I have an output of three columns, Total Income | Tax Payable | Net Income... however to output this I have the following code:

System.out.println(" Total Income | Tax Payable | Net Income");
int i = 0;
 for (i=0; i <=18; i++){
if(incomes[i] < 0){
break;

[Code] ....

And the format of it comes out as: Screen Shot 2014-11-06 at 22.50.25.jpg

I'm getting very OCD about the format and I know there is a printf function which would solve this, however I don't really know how to use this correctly and it just messes up when I try to use it.

View Replies View Related

Using Printf Command - Java Automatically Moving To Next Line

Aug 4, 2014

I'm learning about the printf command, and when I have it, it is not letting me ad an input. Here is my quick little program:

import java.util.Scanner;
public class TestingPrintF {
public static void main(String[] args) {
// Create a Scanner
Scanner input = new Scanner(System.in);

[Code] ....

The first section works good, but when i move down to the second part it just automatically finishes without letting me enter a phrase.

View Replies View Related

What Is Different Between Void Main And Public Void Main

Sep 15, 2014

what is different between void main() and public void main()

View Replies View Related

Convert Java Code To Display Using Printf Statement With Two Decimal Places To Right

Feb 26, 2015

How i would convert this java code to display using the printf statement, with two decimal places to the right...here is the source code so far, but it has a few errors and needs to be reformated for printf

import java.util.Scanner; // scanner class
public class PROB3_CHAL15
{
public static void main(String[] args)
{
double checks =0,
totalfee =0,
fee = 10,
fee1 =.1,
fee2 = .08,
fee3 = .06,
fee4 = .04,
checkFee;
String input;
Scanner keyboard = new Scanner(System.in);
 
[code]...

View Replies View Related

When To And Not To Use Void

Apr 9, 2014

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?

void printStates() {
System.out.println("cadence:" +
cadence + " speed:" +
speed + " gear:" + gear);
}

View Replies View Related

Using String In A Void Or INT?

Apr 20, 2014

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"

View Replies View Related

How To Assert A Void Method

Nov 5, 2014

how to assert a void method like shown in the photos,

View Replies View Related

Declaring Parameters - Use Void For

Mar 1, 2015

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);
}
}

View Replies View Related

Incompatible Types / Void Cannot Be Converted To Int

Jul 29, 2014

package input;

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

unclosed string literal

View Replies View Related

Void And Static In Main Method?

Jan 7, 2014

What does void and static mean in the main method?

View Replies View Related

Invoke A Void Method From Another Class?

May 31, 2014

I'm pretty new to Java. I was working the project about gamble. I'm having trouble with invoking the void method from another class. This is what I have done so far.

There are two classes, and I'm trying to invoke gambleAnotherRound method from gambler class into highlighted part in casino class. So, what I want to do is when the program generates "else" part, it goes back into another gamble round.

public class gambler {
public void gambleAnotherRound(double dollarsBet) {
dollarsSpent += dollarsBet;
Random randomNumbers = new Random();
double randomDouble = randomNumbers.nextDouble();

[Code] ....

Below one is casino class.

// use a System.out.print statement to ask how much money each gambler should bet.
// Then declare a variable dollarsBet of type double, and set its value to the keyboard's
// keystroke (be sure to use keyboard.nextDouble()).
// If the user enters 0, then issue a break statement, so that the while loop terminates
// Else, invoke the gambleAnotherRound method of each Gambler, and pass it the variable dollarsBet

[code] ....

View Replies View Related

Variable Is Set Works / But Then In Void - Returns 0

Jun 13, 2014

The id variable is the problem Java Code: package com.cjburkey.games.boxee.objects;

import java.awt.Graphics;
import java.awt.Rectangle;
import com.cjburkey.games.boxee.GameState;
import com.cjburkey.games.boxee.resources.Images;
public class Block extends Rectangle {

[code]...

In the constructor, it returns corrent numbers, in the draw method, it returns 0. Why?

View Replies View Related

Call Void Method For Array

Mar 6, 2014

I am writing a program to take user input in order to create an array, then call a void method that will read in the numbers (from user's input) and fill the array.This method must use a loop to do this.(The array is to be passed to the void method as a parameter)

in theory, this should change the contents of the array, but without returning a result. Because it is a void method, the array is only passed through the method, not returned; Am I correct?How can I return the array and display it without having to change my method type?

Here is my code:

Java Code: package program7array;
import javax.swing.JOptionPane;

public class Program7Array
public static void main(String[] args) { // main method
int howMany = Integer.parseInt(JOptionPane.showInputDialog(null, // user decides how long array is
"How many numbers are there?"));
double [] numbersArray = new double[howMany]; // creating the array
makeArray(numbersArray, howMany); // calling the array

[code]...

View Replies View Related

Void Method Recursion Error

Jan 11, 2015

i'm trying to exit the recursion of a void method but some funny things are happening before and after the return statement.

public static void main(String args[])
{
//code
rec(x,y);
System.out.println("HEllooooooo");}
public static void rec(int x,int y)
{
try
{
System.out.println(x+" "+y+" "+check);
if(x==fx && y==fy)

[code]....

View Replies View Related

Type Mismatch - Cannot Convert From Void To JTextField

Jun 9, 2014

My GUI class:

import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JPasswordField;

[Code] ....

Eclipse error message:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Type mismatch: cannot convert from void to JTextField
 
at GUI.<init>(GUI.java:58)
at Apples.main(Apples.java:7)

I copied this from a thenewboston tutorial and he uses an old version of java but im pretty sure ive copied character for character!

View Replies View Related

Private Static Void Print Section

Dec 10, 2014

I have problems with private static void print section, something is missing? And in case 4, I want it to stop the program(end the loop) but it keeps going.

import java.util.Scanner;
import java.util.ArrayList;
public class Dogregister16 {
public static ArrayList<Dog> dogregister = new ArrayList();
private static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args) {
initiate();

[Code] ....

case 4:
System.exit(0);
System.out.println("Exit program");
}
}
}
}

View Replies View Related

Rectangle With Numbers - Result Type Is Void

Jun 12, 2014

I want to write a method which would give us a rectangle with numbers. The input is an integer which represents the length of a line in rectangle and the result type is void. The example for n=4 is:

3210
0321
1032
2103

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

Mockito / Powermock Private Void Method

Jul 29, 2014

I need to mock a private void method which takes no arguments using mockito and powermock.

The method belongs to a instance which is a spy.

I am working with an old project converting the unit tests from one testing framework to another.

View Replies View Related

Incompatible Types - Void Cannot Be Converted To String

Jul 26, 2014

I have coded three classes ,1 class containing the Main method. I have declared three private data fields in Staff class and two data fields in Address class. The problem is that I am assigning String type data field from the Staff and Address Class through the public set methods to String type array in a public void method in the Main class.

public static void main(String[] args){
// TODO code application logic here
System.out.println("-------------------------------------------------");
System.out.println("Press 1 - 6 To Perform Any One Following Action ");
System.out.println("1. Insert New Contact ");
System.out.println("2. Delete Contact By Name ");
System.out.println("3. Replace Info From Contact ");
System.out.println("4. Search Contact By Name ");
System.out.println("5. Show All Contacts ");
System.out.println("6. Exit Program ");

[Code] ....

View Replies View Related

Project Is Working On JFrame - But Not Working On JApplet

Apr 10, 2014

I am developing an application to share my client screen with server, it is working well on swing. But i want to develop as web application, i am trying to using applet. But i am facing the fallowing problem..,

1) The Applet screen also open and project also running well on server mechine. But unable to see the client screen on the server.

2) The problem may be to display the JDesktopPane or JInternalFrame.

My working Server Code extends withe JFrame..Java Code:

package remoteserver;
import java.awt.BorderLayout;
import java.awt.Container;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.JApplet;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

[code]....

View Replies View Related

Void Is Invalid Type For Variable Action Performed

May 1, 2015

I get an error in a program  "void is an invalid type for the variable action performed"
 
Here is the code of my program.

import java.awt.EventQueue; 
import javax.swing.JFrame;
import java.awt.Label;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.TextArea;

[Code] .....

View Replies View Related







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