Write A Program That Prompts User For 3 Double Numbers

Feb 15, 2015

So i need to write a program that prompts the user for 3 double numbers x, y, z that outputs 2x^3 + 3y^5 + 3x^3y^2 +xyz with

(1) 4 digits precision
(2) with a ',' to separate thousands
(3) all digits of the result including the precision are put to 20 positions (from right to left)

I am not really sure what it is suppose to look like or how to start it.how to mix Math.pow with multivariable and printf.

View Replies


ADVERTISEMENT

Write A Program Which Prompts User To Enter 4 Grades Between 0 And 100

Sep 2, 2014

I'm using Jgrasp and my prompt is asking me to write a program where the program prompts the user to enter 4 grades between 0 and 100. And you have to display the grades, and the program has to calculate the minimum grade, the maximum grade and the average.I'm just having problems with the max?

// Import Java Scanner.
import java.util.Scanner;
// Name Class.
public class Practice_4_1

[code]...

View Replies View Related

Write A Program That Prompts User To Enter Two Positive Integers And Prints Their Sum

Jan 9, 2015

Write a program (TwoIntegers.java) that prompts the user to enter two positive integers and prints their sum (by addition), product (by multiplication), difference (by subtraction), quotient (by division), and remainder (by modulation). When the user enters 5 and 3, the output from your program should look exactly like the following:

Enter two positive integers: 5 3
The sum is 8.
The product is 15.
The difference is 2.
The quotient is 1.
The remainder is 2.

import java.util.Scanner;
public class TwoIntegers {
public static void main(String[] args) {
System.out.println("Enter two positive integers: ");
Scanner userInput = new Scanner("System.in");
int integer1 = userInput.nextInt();
int integer2 = userInput.nextInt();

[code]....

View Replies View Related

Write A Program That Prompts User To Enter A Password And Displays Valid Password

Dec 3, 2014

My homework is asking me to write a program that prompts the user to enter a password and displays "valid password" if the rule is followed or "invalid password"

Sample
enter a string for password: wewewx
valid password

It's being graded on
Design of my GUI
Dialog box
User friendliness
Creativity

My current issues with the current code I have written is simply the password doesn't work unless it starts with 2 digits, the other order it displays as wrong. and I have no idea how to add a GUI.

import java.util.*;
import java.lang.String;
import java.lang.Character;

[code]....

View Replies View Related

Program That Prompts The User To Enter Loan Amount And Years

Oct 21, 2014

so I had to make a program that prompts the user to enter a loan amount and the years for the loan and I have the conversions and everything my only issue is that when the chart pops up it just looks like a bunch of numbers and its missing the column headers

for example

Interest Rate Monthly Payment Total Payment

import java.util.Scanner; 
public class InterestRate { 
public static void main(String[] args) { 
double monthlypayment = 0; 
double totalpayment = 0; 
Scanner input = new Scanner(System.in);
System.out.println("Enter Loan Amount");

[Code]...

View Replies View Related

Java Program That Randomly Generates Five-digit Lottery Number And Prompts User For Input

Sep 25, 2014

Write a Java program that randomly generates a five-digit lottery number and prompts the user to enter a five-digit number. Each digit in the number is in the range between 0~9. The program should determine which prize the user wins according to the following rule:

• The user wins the first prize if the user input matches all five digits in the lottery number in exact order.
• The user wins the second prize if the user input matches any four digits in the lottery number in exact positions.
• The user wins the third prize if the user input matches any three digits in the lottery number in its exact position.
• The user wins the fourth prize if the user input matches any two digits in the lottery number in its exact position.
• The user wins the fifth prize if the user input matches any one digit in the lottery number in its exact position.

and here is my code. I cant get it to print the right statements.

import java.util.Scanner;
import java.util.Random;
class Hw5 {
static int getPrize(int g1, int g2, int g3, int g4, int g5,
int u1, int u2, int u3, int u4, int u5) {
//code for determining the prize comparing (g1, g2, g3, g4, g5) to (u1, u2, u3, u4, u5)
if (u1 == g1 && u2 == g2 && u3 == g3 && u4 == g4 && u5 == g5)

[code]....

View Replies View Related

Program That Takes User Odd Number And Print Prime Numbers Lower Than User Input

Nov 4, 2014

I have been struggling with this program for weeks. This program is supposed to take a user's inputted odd number and then print out all prime numbers lower than that number.

public class PrimeNumber
{
Scanner scan = new Scanner(System.in);
int userNum;
String neg;

public void getUserNum()

[code]...

View Replies View Related

Write A Program That Find The Sum Of Two Numbers 62 And 99?

Jan 23, 2015

I have to write a program that find the sum of two numbers 62 and 99 and stores them in a variable named total. However, I have one error that I just can't get rid of and can't tell what it is. I'm using jGrasp and here's what it says:

Programming Challenge #5.java:14: error: class SumofTwoNumbs is public, should be declared in a file named SumofTwoNumbs.java
public class SumofTwoNumbs {
^
1 error
  ----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

and here: is my code:

import java.util.Scanner; 
/*
* 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.
*/
 /**
// This program has variable of several of the integer types.
public class SumofTwoNumbs {
public static void main(String[] args) {

[code]....

View Replies View Related

Write A Program That Takes Two Numbers And Multiplies Them

Jul 8, 2014

I am trying to write a program that takes two numbers and multiplies them. I got this idea from this running conversion program

import java.util.Scanner;
public class Convert
{
public static void main (String [] args)
{
Scanner reader = new Scanner (System.in);
double farenheit;
double celsius;

[code]...

i am getting a cant find symbol for the output = (alpha*beta) line..Also, am I using the reader object correctly ? hould I create two reader objects as there are 2 inputs needed?

View Replies View Related

Write A Program Where User Inputs A Month Between 1-12

Sep 21, 2014

I have an assignment where I'm supposed to write a program where the user inputs a month between 1-12 and then the right amount number in every month. I've tweaked the code a bunch of times, but I keep getting this error message:

insert "}" to complete StatementKALENDER_3.java
insert "}" to complete BlockKALENDER_3.java

The code:

import java.util.*;
import java.util.Scanner;
public class KALENDER_3
}
public static void main(String[] args){
Scanner scanner = new Scanner (System.in);
System.out.print("Skriv ett manadsnummer: ");

[code].....

I think I have just forgot to put in a few { } symbols, maybe an open loop?

View Replies View Related

Write A Program That Reads From User Several Lines Of Input

Mar 24, 2014

a. Assume that we have a list of employees' names of a company and their ages. Write a program that reads from the user several lines of input. Each line includes an employee's name and his/her age (as an integer). The program should calculate and print the following:

- The average age of all employees (rounded to 2 decimal places).
- The oldest employee and his/her age.

Hints:

You could assume that the user will insert valid data and at least one employee.
You could assume that the oldest employee is only one person.
User could stop the program via entering the word "end" as an employee's name.

Sample Input and Output: In each line, insert an employee's name and his/her age To halt the program, insert "end" as an employee's name

Adam 30
Tom 41
Ted 45
Karl 30
end

The average age of all employees is 36.50.The oldest employee is Hisham whose age is 45

View Replies View Related

Write A Program In Which User Will Select A Text File

Mar 30, 2015

i am trying to write a program in which the user will select a text file(which contains information that the graphical output will be based). I have successfully set up my file chooser however when i select the text file,i do not get any graphical out put. please see attached .zip file for code.

View Replies View Related

Write Java Program That Asks User For List Of Names?

May 21, 2015

I am trying to write a java program that asks the user for a list of names (one per line) until the user enters a blank line. At that point the program should print out the list of names entered, where each name is listed only once (i.e., uniquely) no matter how many times the user entered the name in the program. I am supposed to use an ArrayList for this problem.

My idea for a solution is to create an ArrayList<String>, read each name, i.e., line, entered and then to see if that name is already in the ArrayList. I created a for loop to check each element in the ArrayList but when I try to assign an element to a string variable I get the error "Type mismatch: cannot convert from Object to String". Not sure why that is happening because the ArrayList is defined as a String list.

Here is the code so far.

/*
* File: UniqueNames.java
*/
import acm.program.*;
import java.util.*;

[Code].....

View Replies View Related

ProductCatalog That Prompts User To Enter Number Of Products

Feb 11, 2015

Write a program called ProductCatalog that prompts the user to enter the number of products in the product catalog. The program should then prompt the user for the name and the price of each product in the product catalog. Once all of the products have been entered, the program should output the product information (name and price) of the most expensive product in the catalog. Your solution must use a for loop repetition structure and should use the Product class included in labfiles05.zip to keep track of the product with the highest price. Here is sample output:

Enter the number of products: 3
Enter the name of product 1: iPod
Enter the price of product 1: 158.99Enter the name of product 2: iPad
Enter the price of product 2: 518.99
Enter the name of product 3: iPadMini
Enter the price of product 3: 304.49
Most Expensive: Product [name=iPad, price=518.99]

Your solution should not use an array to keep track of all the product information entered.

I am having trouble with my code, with the For loop and then calling the methods from the Product class into the ProductCatalog. How should I approach this program.

Here is the Product program.

public class Product
{
private String name;
private double price;
public Product(String theName, double thePrice) {
name = theName;
price = thePrice;

[Code]...

Here is the ProductCatalog class where I call the methods from Product class. The For loop is what I am having trouble with as well.
 
import java.util.Scanner;
public class ProductCatalog
{
public static void main(String[] args) {
double number;
String product = " ";
double productCount = 0;

[Code]...

View Replies View Related

Application That Prompts User To Enter Personal Details

Feb 18, 2014

Create a Java application that prompts the user to enter their personal details: First name, last name, gender, address, suburb, postcode, and phone number. Then the program displays all of your personal details to the screen as illustrated. Name the file PersonDetails.jav

package exe
import java.util.*;
public class Review2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your full name: ");
String name = scanner.next();

[Code]...

If you cant tell straight away how i have stuffed up, what is happening is this;

When i am promoted to enter my name, 'John Smith'. The word 'John' would be stored in the name variable, while 'Smith' is stored under gender, so the next prompt is then 'Whats your address?'

So its only assigning one word per variable, now as far i understand, a string should not work that way. So where is my mistake?

View Replies View Related

Prompts User To Enter 5 Test Scores And Their Names - Calculate And Display Average

Sep 24, 2014

Using Bluejay. Need code that prompts user to enter 5 test scores and their names. Calculate the average and display.

First initial and last name , 5 test scores, and average

View Replies View Related

Program Prompts For A Line Of Text

Jun 2, 2014

Write a program that reads in a line of text and then outputs that line of text first in all uppercase letters and then in all lowercase letters.

INPUT and PROMPTS. The program prompts for a line of text as follows: "Enter the text: " and then reads in an entire line of text as a String .

OUTPUT . There are four lines of output . The first line is "The text in all upper case is: ". The second line is the line that was read in, displayed in all uppercase. The third line is "The text in all lower case is: " and the fourth line is the original line that was read in, displayed in all lowercase.

CLASS NAMES. Your program class should be called ShoutAndWhisper.

[import java.util.Scanner;
public class ShoutAndWhisper
{
public static void main(String[] args)
{
Scanner scannerObject = new Scanner(System.in);

[code]....

View Replies View Related

User Input Random Numbers Then Program Sort Them In Different Ways - Missing Return Statement

Apr 7, 2014

I have been assigned to write a program that has a user input random numbers then the program is to sort them in different ways. I have the coding for the different sorts but, I have an error saying that I am missing a return statement in the "Bubble" method. I am trying to return "arr[i]" in the "for loop" which gives me this error, and when I try to take the "return arr[i]" outside of the "for()" loop the error reads the it cannot locate variable "i".

import java.awt.* ;
import java.awt.event.*;
import javax.swing.*;
public class SwingSorts extends JFrame implements ActionListener
{
JRadioButton bubble;
JRadioButton selection;

[Code] .....

View Replies View Related

Round Up Double Numbers To Desired Value?

Mar 28, 2015

I have a double/big decimal value with 2 decimal places....What I want is that if decimal value is .01 - .49, it should round up to 0.50.

Then if decimal value is between 0.51 - 0.98, it will round up to 0.99.

Is there a function in double that can do this? How can I do this?

View Replies View Related

How To Print Double With 2 Decimal Numbers

May 3, 2014

I am trying to cast an integer into a double. it works but I need two decimal number after the dot and for example I can print 7.51 but how can I get it to print 7.50 and not 7.5

public int compareTo(Money o){
int d1 = (this.dollars * 100) + this.cents;
int d2 = (o.dollars * 100) + o.cents;
return d1 - d2;
}

On my main method I have

public static void main(String[] args){
Money money1 = new Money(10, 49);
Money money2 = new Money(2, 99);
System.out.println("result: " + "$" + (double)money1.compareTo(money2)/100);
}

It prints 7.5 but I want it to print 7.50, how do I do this .....

View Replies View Related

User To Enter 10 Numbers And At The End Prints Out Distinct And Non-repeated Numbers

Nov 23, 2014

I have to make a program that prompts the user to enter 10 numbers and at the end it prints out the distinct numbers and then the other numbers that weren't repeated...

I have the part where it prints out the distinct numbers but I stuck on how to make it print out the other numbers that didn't repeat...

import javax.swing.JOptionPane;
public class DistinctNumbers {
public static void main(String[] args) { 
String getInput;
int input;
int[] numbers = new int[10];

[Code] ....

View Replies View Related

Convert Strings To Double Numbers - Exception When Non-numeric Entered

Nov 11, 2014

So I have to convert strings to double numbers and there can be no exception.

The strings that aren't numbers or do not fit into a set criteria have to be discarded.

When I try to write this I get an exception when a non-numeric is entered and the code stops.

What can I do? Also, am I finding the average of the array correctly?

import java.util.*;
public class Grades{
public static void main(String args[]){
int arraycount = 0;
final int SIZE = 10;
int validArraycount = 0;
final int ValidArraySize = 10;

[Code] ......

View Replies View Related

Attempted User Input Using A Double

Jan 13, 2015

For some reason, the below code is not working out for me. I thought I had the scanner right and Eclipse is only throwing an error on the last line that states "else(ernie == 0)". What am I missing here?

Basically just trying to take user input, incorporate some if and else if statements to return a line based on if the condition is met.

Java Code:

import java.util.Scanner;
//Importing the scanner now for user input
public class Ernie {
public static void main(String[] args) {
double ernie;

[Code] .....

View Replies View Related

User Option - Enter Either Int Or Double

Apr 21, 2014

I'm trying to write a program where the user has the option to enter either an int or double but whatever input I enter just gets cast to a double. Do I even have the right Idea by using if else statements?

import java.util.*;
public class VS
{
public static void main(String[] args) {
Scanner Input = new Scanner(System.in);
System.out.println("Please enter a number");
if (Input.hasNextDouble()) {

[Code] ....

View Replies View Related

Calculate Distance Between Two Points - All Numbers And Return Values Should Be Of Type Double

Jul 8, 2014

Write method distance to calculate the distance between two points (x1, y1) and (x2, y2). All numbers and return values should be of type double. Incorporate this method into an application that enables the user to enter the coordinates of the points.

Hints:

- The distance between two points can be calculated by taking the square root of

( x2 - x1 )2 + ( y2 - y1 )2

- Use Math class methods to compute the distance.

- Your output should appear as follows:

Type the end-of-file indicator to terminate

On UNIX/Linux/Mac OS X type <ctrl> d then press Enter

On Windows type <ctrl> z then press Enter

Or Enter X1: 1

Enter Y1: 1

Enter X2: 4

Enter Y2: 5

Distance is 5.000000

Type the end-of-file indicator to terminate

On UNIX/Linux/Mac OS X type <ctrl> d then press Enter

On Windows type <ctrl> z then press Enter

Or Enter X1: ^Z

View Replies View Related

Double RelativeFrequency Value Which Does Calculation / End Result Is Number With Lots Of Decimal Numbers

Nov 24, 2014

for (int i = 0; i < letters.length; i++) {
double relativeFreq = (onesAverage()/letters[i]);
char a = characters.charAt(i);
double j = score[i];
System.out.printf();//ToDo

Above is my current code. Basically- There is a string called characters of length 26 (1 char for each letter in alphabet), a double relativeFrequency value which does a calculation and the end result is a number with lots of decimal numbers. The score array has set double values within the array.

What I want to do is create a print f statement where I print out each of the values I initialized above WITH specific amounts of spaces in between. So it should be in this order:

a (spaces) j (spaces) relativeFreq (newLine).

Between J and relativeFreq there should be 4 spaces, however if the value in relativeFreq is greater than 10 (it won't be greater than 100)- then there should be 3 spaces. Everytime I try to create a printf statement my code ends up crooked for some of the values.

for (int i = 0; i < letters.length; i++) {
double relativeFreq = (onesAverage()/letters[i]);
char a = characters.charAt(i);
double j = score[i];
System.out.printf("%c %.4s %.4s%n",a, j, relativeFreq);

View Replies View Related







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