Need Output To Display Whole Number

Dec 2, 2014

I need the output to display like this:

At Billy Goat's Restaurant, the price of our good tasting Hotdog is $1.50.

But it is output display is like this:

At Billy Goat's Restaurant, the price of our good tasting Hotdogis 1.5

In the second array i use a double, is that not correct?

import java.util.Scanner;
 public class FinalProject
{
public static void main(String[] args)
{
String[] FoodDescription = {"Hotdog", "Fries", "Hamburger", "Pepsi", "IceCream"};
double [] cost = {1.50,.80,2.25,1.00,.75};

[Code] ....

View Replies


ADVERTISEMENT

Display Some Messages On Output File In Display Head Function

Mar 18, 2014

Write a class named FileDisplay with the following methods:

1.) constructor: the class's constructor should take the name of a fil as an arugment.
2.) displayHead: This method should display only the first five lines of the file's contents

Here is the following code I have made so far

import java.io.*;
public class FileDisplay
{
private String filename;
 public FileDisplay(String Filename) throws IOException

[Code] ....

First, in my constructor I have taken in an argument and used that argument to open up an output file. Meanwhile, I'm trying to work n the displayhead method to print out information and to read data to. I haven't opened up my input file yet, but I'm not understand how can I read a print data to an output file. in

public void displayHead()
{FileWriter file=new FileWriter(Filename)}

do I make create another instance of the filewriter class to output data?

In simple words, suppose to I want to display some messages on my output file in the displayhead function. Since I already have opened up the file in the constructor, how do I combine that in this method...

View Replies View Related

Program Is To Accept Number And Display New Number After Removing All Zeros

Dec 29, 2014

ex
Sample input:2340980
Sample Output:23498

this is the program i have tried but is dosent work

import java.util.*;
class zero
{
public static void main(String args[])
{

[Code]....

View Replies View Related

ArrayList Output Display Without Brackets?

Feb 9, 2015

I'm trying to get my output to be displayed without the brackets.The output looks like this

22 ([1, 2, 11])
33 ([1, 3, 11])
44 ([1, 2, 4, 11, 22])
55 ([1, 5, 11])
66 ([1, 2, 3, 6, 11, 22, 33])
77 ([1, 7, 11])

But I want it to have no brackets displayed so it looks like this

22 (1, 2, 11)
33 (1, 3, 11)
44 (1, 2, 4, 11, 22)
55 (1, 5, 11)
66 (1, 2, 3, 6, 11, 22, 33)
77 (1, 7, 11)

import java.util.ArrayList;
public class Palindrome {
public static void main(String[] args) {
int e = 0;
// palindromic composite number
int drome = 0;

[Code] ....

View Replies View Related

Display User Input In Lower Case - Why No Output In Second TextField

Jun 2, 2014

I've done a lot of hardwork for this assignment but I don't know what's why the second textfield which is for output is blank.

All I want is to get the input from user in textfield a and display it in textfield b in lower case.

public void KeyPressed (KeyEvent ke) {
String letter2="";
if(ke.getKeyCode()==KeyEvent.VK_A)
{
letter2=letter2+"a";
btextfield.setText(letter2);

[Code] .....

View Replies View Related

Display Contents Of File In Reverse Order - Output To Console

Jun 24, 2014

Create a class that allows the user to select a file and output the contents of the file to the console. Recommend using a text file to display, java files are text files. You may want to put this code in a method to allow you to complete the remainder of this assignment without overwriting your code.

- You should ask the user to enter the full path to your file to make certain you are processing the correct file.

- Modify your code/add a method to display the contents of the file in reverse order. You do not need to reverse the characters on each line but simply output the lines of the file in reverse order.

Hint: read the content of the file into an ArrayList and then traverse the ArrayList.

this is what i go so far.

package classActivity;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Select
{
public static String enterFilePath()

[Code] ....

View Replies View Related

Program Should Output Depending On Input Number

Apr 15, 2014

The program should has the output depending the number I'll input. (The number should be from 1-9) . This is the program's output should be:

Input number: 4

Output:
# # # 1 # # # # #
# # # 2 # # # # #
# # # 3 # # # # #
1 2 3 4 5 6 7 8 9
# # # 5 # # # # #
# # # 6 # # # # #
# # # 7 # # # # #
# # # 8 # # # # #
# # # 9 # # # # #

(Example 2):
Input numbers: 8

Output:
# # # # # # # 1 #
# # # # # # # 2 #
# # # # # # # 3 #
# # # # # # # 4 #
# # # # # # # 5 #
# # # # # # # 6 #
# # # # # # # 7 #
1 2 3 4 5 6 7 8 9
# # # # # # # 9 #

(Example 3):
Input number: 5

Output:
# # # # 1 # # # #
# # # # 2 # # # #
# # # # 3 # # # #
# # # # 4 # # # #
1 2 3 4 5 6 7 8 9
# # # # 6 # # # #
# # # # 7 # # # #
# # # # 8 # # # #
# # # # 9 # # # #

I'm not asking the code to make this program, I have trouble to understand the algorithm to make this program ...

View Replies View Related

Produce Similar Output For N Characters Where N Is A Odd Number

Apr 25, 2014

1.Write a program to produce a similar output for n characters, where n is a odd number. The below output is for n=7.

Java Code:

A B C D E F G F E D C B A
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
mh_sh_highlight_all('java');

View Replies View Related

Type Casting - Getting Number With Two Decimal Places As Output?

Jun 7, 2013

"Type Casting" .... So the question is "How am I getting a number with two decimal places as output?"

import java.util.Scanner;
public class SalesTax
{
public static void main(String[] args) {
double purchase, tax;
Scanner input = new Scanner(System.in);
System.out.print("Enter purchase amount: ");
purchase = input.nextDouble();
tax = purchase * 0.06;
System.out.println("Sales Tax: $" + (int)(tax * 100) / 100.0); +//this will give two decimal places??+
}
}

View Replies View Related

Display All Odd Number Between 1 And 15

Nov 16, 2014

Write a program that will display all the odd number between 1 and 15. here is the code that i use :

Scanner scan = new Scanner (System.in);
int i, num=0, count_odd = 0;
for(i=1; i<=15; i++) {
System.out.println("please enter number ");
num = scan.nextInt();

[Code] ....

View Replies View Related

Random Phone Number Generator - Include Dashes In The Output

Apr 11, 2011

I've been working on a personal project again in Unit 3 of my text book and this time they want me to make a random phone number generator. Here's the actual directions:

"Write an application that creates and prints a random phone number of the form XXX-XXX-XXXX.

Include the dashes in the output.

Do not let the first three digits contain an 8 or 9 (but don't be more restrictive than that), and make sure that the second set of three digits is not greater than 742.

Think through the easiest way to construct the phone number. Each digit does not have to be determined separately."

With this assignment I came across 2 problems:

1. What I tried was that since the first 3 numbers have to be a random number with no 8's or 9's I tried doing this algorithm:

int first0, first1, first2, second, third, random0;
first0 = generator.nextInt (999);
random0 = generator.nextInt (8);
first1 = first0.replace('8', random0);
first2 = first1.replace('9' random0);

The problem is that Java won't allow me to generate random numbers this way. Are there any easier ways of generating numbers that doesn't contain specific number (such as 8 or 9 in this case?)

2. I was thinking about this throughout the whole project and what if I generate a number such as 27 (less than 3 or 4 digit number) rather than 3 or 4 digit numbers? How would it show 0027 or 027 instead of 27 for the phone numbers?

import java.util.Random;
public class pp0303 {
public static void main (String[] args){
Random generator = new Random();
int first0, first1, first2, second, third, random0;

[Code] ....

RESULTS:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Cannot invoke replace(char, int) on the primitive type int
Cannot invoke replace(char) on the primitive type int
Syntax error on token "random0", delete this token
at pp0303.main(pp0303.java:15)

View Replies View Related

JOption Pane - Output Number With Greatest Value From User Input

Nov 7, 2014

Using JOptionPane,ask for 10 numbers from the user.Use an array to store the values of these 10 numbers.Output on the screen the number with the greatest value.

View Replies View Related

Prompt User To Input Integer And Then Output Both Digits Of Number And Their Sum

Jun 7, 2015

Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits. 
 
Now I have a code for spacing out the integers, and I have a separate code for adding the digits. But I am not sure how to merge them together. Both of them work independently
 
Spacing code:
import java.util.*;
public class SumoftheIntegers
{
static Scanner console=new Scanner(System.in);
public static void main(String []args) {
int num1, test, rem;
int counter = 0;

[Code]...

Now the sum of the integers code:
 
import java.util.Scanner;
public class sum
{
    public static void main(String[] args)
    {
        // Create a Scanner
        Scanner input = new Scanner(System.in);
// Enter amount
        System.out.print("Enter an integer: ");
        int integer = input.nextInt();

[Code]...

View Replies View Related

Swing/AWT/SWT :: Display Images According To Number?

Mar 27, 2014

The code below is just the GUI for a slot machine. Currently when play is clicked it displays the random number, I'm trying to make it so each random number displays an image in the GUI instead. For example if the random numbers were 2,2,3 it would display Cherry, Cherry, Bells. I started changing field1 to the image but realised I was on the wrong track as it would just display the same image not one allocated to a number. I've left in what I started doing.

how to do it?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SlotMachineGUI {
JPanel mainPanel;
SlotMachine slotEngine;

[code]....

View Replies View Related

Display Serial Number Using Two Threads

Jun 4, 2014

Aim : display a serial number using two thread Say (odd numbers)t1=1,3,5,7....99, and (even no) t2=2,4,6,8......100

How to resolve this problem ?

output will be:
1
2
3
:
100

View Replies View Related

How To Display Number Series In Ascending Order

Aug 9, 2014

tfrreee i want to display given series in ascending order in java prog here is an error : E:Javajdkin>java ascend 505671Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7 at ascend.main(ascend.java:9)

Java Code:

class ascend
{
public static void main (String args[])
{
int s[]={ 50,71,81,21,7};
int i;
for(i=0;i<=s.length;i++)

[Code]...

View Replies View Related

Display Ten Digit Phone Number As Both String And Long

Feb 17, 2014

I'm trying to output a ten digit phone number as a string on one file, and write another program to write it as a long because I don't know what value I need to use in order to get the code to run properly on either one.

View Replies View Related

Build A GUI That Will Initially Display A Window With X Number Of Buttons

Apr 30, 2014

I've chosen to build a GUI that will initially display a window with 'x' number of buttons for different subject areas of physics (kinematics, waves, sound, circuits...etc). I would like to use an Actionlistener for each button so that when its pressed, the JFrame will extend a sidepanel or expand the JFrame with a new JPanel that contains variable Jtextfields so the user can enter data to calculate.

I'd like to know if its possible to do this with the JFrame or should I just open a new window altogether? I have some other features I plan to add to the program, but this is where I am right now.

how difficult is it to add a banner image and imageIcon? By banner image I mean create a Jpanel that will contain a header for the window and will have some cool physics jpg image.

View Replies View Related

How To Format Methods To Display Number With 1-2 Decimal Places

May 8, 2014

I am working with a program I wrote for class. I got it to compile and do what I want, But I was wondering how I can format my methods to to display a decimal with 1-2 decimal places. Would I create a method in my NumberAnalysis class to do it for me? Or would I declare an instance of the DecimalFormat class in my main method?

import java.util.Scanner; //Needed for Scanner Class
import java.io.*; //Need for File and IOException
import java.text.DecimalFormat;
public class Ex8_11 { 
public static void main(String[] args) throws IOException{
{
DecimalFormat decformatter = new DecimalFormat("#0.00");
 
[Code] .....

This is my output:

Lowest Number: 1.09
Highest Number: 82.76
Total Number: 367.89000000000004
Total Average Number: 30.657500000000002

Think I just solved the answer to my own question, I did it by declaring double variables in my main method and called the methods and instantiated the variables into the methods... Is there a better way to do this?

package lesson4.skowronek;
 import java.util.Scanner; //Needed for Scanner Class
import java.io.*; //Need for File and IOException
import java.text.DecimalFormat;
public class Ex8_11 {
public static void main(String[] args) throws IOException{
 
[Code] ....

View Replies View Related

Take User Input And Display Sum Of Digits Of Entered Number

Nov 6, 2014

I have returned with yet another problem but I think this one might be a bit easier to fix.

So the whole MO of this program is to take user input, and display the sum of the digits of the number they entered. I am supposed to do this by utilizing methods. So far this is what I have and when I compile it tells me that it "cannot find symbol", which I don't understand as I define what "m" is in the for loop. The other error is that it says:

"Exercise6_2.java:22: error: incompatible types: possible lossy conversion from long to int
return result;
^

I don't understand why it's giving me this error nor do I understand why result seems to inherently be an int. (Also the public static int sumDigits(long n) method was given to me by the book so that is what I am supposed to use).

import java.util.Scanner;
public class Exercise6_2 {
public static void main(String[] args) { 
Scanner input = new Scanner(System.in);
System.out.println("Enter a integer");
long n = input.nextLong();

[Code]...

View Replies View Related

Generate QR Code From Input Text And Display Information About Input / Output Bits

Nov 12, 2014

I am trying to write a program that will generate a QR Code from an input text and also display some information about the input/output bits. So far I have created the frame and what to do next. And I'm not sure if I am on the right track since my level of programming is not that great. By the way, I am using zxing libraries from GitHub. I know, there are plenty of generators online for the QR Code, but that is not what I am looking for. As you can see on the attached image, I am more interested in the efficiency of encoding 2D data. Also, I noticed that almost all the online projects regarding 2D codes are for Android. Which is not very useful.

// QR Code Generator
package qrcode;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;

[Code]....

View Replies View Related

Java Programming To Input Number And Display All Its Prime Digit?

Jan 9, 2015

I am new to java programming and using bluej for programming and i have tried this question what i have have given in title ... how to find out the errors in the following program:-

class Primedig {
public void getinput(int n) {
int ctr=0;
while(n!=0) {
int r=n%10;
for(int i=1;i<=r;i++)

[code] .....

output:-

For example input is 243 the output comes only 3 not 2& 3 both.

View Replies View Related

Count Number Of Characters Contained In Both Strings And Display Results

May 2, 2014

I have been working on this for hours and cannot get it to work properly. The program is to count the number of characters contained in both strings and display the results. It is also to display the final statement, but only once. This version has a complete statement for each matching character.

import java.util.Scanner;
public class CountMatches {
public static void main(String[] args) {
String firstStr = ("");
String s1 = firstStr;

[Code] ....

View Replies View Related

Ask User To Enter Number From 1 To 10 And Program Will Display Roman Numeral

Feb 6, 2014

I am trying to write a program that asks the user to enter a number from 1 through 10 and then the program will display the roman numeral for that number.

I am also adding a error message in which i haven't yet because im still trying to figure out how to the program will do the roman numeral.'

I have used the if and else if. but when i input a number it just repeats the number back to me.

The program cimpiles but it doesn't do what i want. here is what i have so far. how can i get the program to display the roman numeral after the number is entered.

import javax.swing.JOptionPane;
public class Romannumeral
{
public static void main(String[] args)
{
double number;
 
[Code] .....

View Replies View Related

Count And Display Number Of Times Specified Character Appears In String

Mar 7, 2014

Write a program using a while-loop (and a for-loop) that asks the user to enter a string, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the string. (So, you will have two separate program codes, one using a while-loop and the other one using a for-loop.)

Example:
Enter a string: "Hello, JAVA is my favorite programming language."
Enter a character: e
The number of times the specified character appears in the string: 3

I don't even know where to begin I've only got this

import java.util.Scanner;
 public class letterCounter {
 public static void main(String [] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a string");
String myString = sc.nextLine();
System.out.println("Enter a letter");
String letter = sc.nextLine();
}
}

View Replies View Related

Store Name SD Array And Display Room And Floor Number Whose Name Is Entered

Sep 12, 2014

I have to store the name SD array and display the room and floor no. whose name is entered but i am having a problem with the logic part. The answer is coming to be wrong

import java .io.*;
class hotel
{
public static void main()throws IOException {
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(read);
String ar[][] = new String[5][10];

[Code] ....

View Replies View Related







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