TRENDING NEWS

POPULAR NEWS

Java Simple Questions Need Help

Java simple questions!! need help!?

1.Say you are designing a program to store and retrieve the information of all the music CDs you have. It is a good design choice to write a single function that inputs the information of all CDs you have, sorts that information by artists’ names, and writes that information in a file.。
2.Say you are designing a program to store and retrieve the information of all the books you have. It is Not a good design choice to write a function that inputs the information of all books you have, a function that sorts that information by authors’ names, and another function writes that information in a file.
Q: What's the different between these two? And which one is true? Why???

3.Say you are designing a program to store the educational records of all students at the University of Nebraska – Lincoln. Say, you want to print out the grade (A, B, C, D) of a student in a course. Which one of the following would be a good design choice: (1) a function that calculates the grades of a student and a function that prints out the details of a student’s record or (2) write separate functions for calculating the different grades (A, B, C, D) and a function that prints out the details of a student’s record.
Q: Which method should I choose???

Java programming help? Simple question?

public int squareMax(int x, int y)
{
return Math.sqrt(Math.max(x, y));
}

the return value of this method is a int type value, but the result of the sentence "Math.sqrt(Math.max(x, y))" is a double.

given x = 8, y = 6
Math.sqrt(Math.max(8, 6)) = 2.8284....

suggestion:
1) you can make a type convert;
public int squareMax(int x, int y)
{
Double tmResult = new Double(Math.sqrt(Math.max(x, y)));

if(tmResult != null)
{
return tmResult.intValue();
}
else
{
return 0;
}
}


or
2) changing the definition of the method, let it return type is double.

public double squareMax(int x, int y)
{
return Math.sqrt(Math.max(x, y));
}

Need help with java programming....basic questions?

Which of the following identifiers are valid?
a
sales
sales&profit
int
inter
doubleSales
TAX_RATE
1stLetterChar
char

given three declared and initialized int variables a, b, c, which of the following statements are valid?
a = b;
a = 67;
b = 8.7;
a + b = 8;
a * b = 12;
c = a – b;
c = a / 2.3;
boolean t= a;

what is the output of this code sequence?
Int a = 6
System.out.println( a );

what is the output of this code sequence?
float a = 13f;
System.out.println( a );

what is the output of this code sequence?
Int a = 13 / 5;
System.out.println( a );

what is the output of this code sequence?
Int a = 13 % 5;
System.out.println( a );

what is the output of this code sequence?
int a = 4 + 6 / 2;
System.out.println( a );

what is the output of this code sequence?
double a = 12.0 / 5;
System.out.println( a );

what is the output of this code sequence?
int a = (int) 12.0 / 5;
System.out.println( a );

what is the output of this code sequence?
double a = (double) (12 / 5 );
System.out.println( a );

What is the output of this code sequence?
int a = 5;
a++;
System.out.println( a );

What is the output of this code sequence?
int a = 5;
System.out.println( --a );

I have some basic Java questions?

Great questions.Generally, a “variable” is just a reference to a memory location allocated in the computer memory. In response to your question, Yes, there are other types of variables in Java — generally classified based on their scopes and behaviors. Here are some other names:primitive variables (or simple variables)constants (final)static fields (class variables)non-static fields (instance variables)arguments (opposite parameters)Yes, Machine Language (ML) or Machine Code is a synonym for Binary Code.Some high-level languages may become obsolete, but I don’t believe control flow charts (UMLs) will replace high-level languages. I am not even sure if they ever can. UML is merely a modeling tool (perhaps a declarative language) to assist programmers during SDLC, especially in using OOP.Hope this helps answer your questions.All best,Christian

Need help writing this simple java program...?

import java.lang.Math;
import java.io.*;
import java.util.Scanner;

public class ComputeMarkup {

/* This program reads a sequence of sales prices input
by the user, and will display the markup and wholesale
cost values for each sale. At the end, the program
displays the total sales and the total markup.
*/

public static void main(String[] args) {

double salesPrice; // The price input by the user.
double wholesalePrice;
double markupAmount;
double totalSales; // The sum of the positive integers.

Scanner in = new Scanner(System.in); // The Scanner class is new in Java 1.5

/* Initialize the sum */
totalSales = 0;

/* Read and process the user's input. */
System.out.println("Enter your first book sales price: ");
salesPrice = in.nextDouble();

// Do this until a 0 price is entered.
while (salesPrice != 0) {
totalSales += salesPrice; // Add salesPrice to running total.

// salesPrice = wholesalePrice * 110 percent (1.1)
wholesalePrice = Math.round(salesPrice / 1.1 * 100) / 100.0;
markupAmount = Math.round((salesPrice - wholesalePrice) * 100) / 100.0;

// Print out the data
System.out.println ( " The markup is " + markupAmount);
System.out.println ( " The wholesale amount is " + wholesalePrice);

// Get the next book sale price
System.out.println("Enter your next book sales price ( or 0.0 to end) ");
salesPrice = in.nextDouble();
}

/* Display the summary. */
System.out.println ( " The total of all books sold is " + totalSales);
markupAmount = Math.round(totalSales / 11.0 * 100) / 100.0;
System.out.println ( " The total markup amount is " + markupAmount);

} // end main()

}


================ Output from a run ==========
run:
Enter your first book sales price:
100
The markup is 9.09
The wholesale amount is 90.91
Enter your next book sales price ( or 0.0 to end)
99
The markup is 9.0
The wholesale amount is 90.0
Enter your next book sales price ( or 0.0 to end)
0
The total of all books sold is 199.0
The total markup amount is 18.09

Help me PLEASE , with JAVA , should be simple?

1)Given an int variable datum that has already been declared, write a few statements that read an integer value from standard input into this variable.
2) Write the definition of a method printAttitude , which has an int parameter and returns nothing. The method prints a message to standard output depending on the value of its parameter.
If the parameter equals 1 , the method prints disagree
If the parameter equals 2 , the method prints no opinion
If the parameter equals 3 , the method prints agree
In the case of other values, the method does nothing.

Each message is printed on a line by itself.
3) Write the definition of a method min that has two int parameters and returns the smaller.
4)
Assume that the int variables i and j have been declared, and that n has been declared and initialized.

Using for loops (you may need more than one), write code that will cause a triangle of asterisks of size n to be output to the screen.

Simple Java assistance needed!?

Hi there, for my computer science course I have been given the following question. Other people I ask say the answer is A, but wouldn't there be an error because there is not a declaration for array p?

Please help! I am really confused on this. A or E?

Suppose that p is a two-dimensional array with elements of type int. Which of the statements below best describes the effect of the following code?

int i = 0;

while ( i < p[ 0 ].length )
{
p[ 0 ][ i ] = 0;
i++;
}

A. All the elements in the first row are assigned 0.

B. All the elements in the last row are assigned 0.

C. All the elements in the first column are assigned 0.

D. All the elements in the last column are assigned 0.

E. An error is reported.

I need help writing a simple java program!?

Ok here is the question:

Write a simple program that asks for the names of three runners and the time, in minutes, it took each of them to finish the race. The program should display the names of the runners in the order that they finished.

Please help, i need to have this turned in by midnight! Thanks.

Will someone help me with Java? It's a simple program that involves string and wrappers.?

public static void main(String[] args) {

Scanner in=new Scanner(System.in);
System.out.println("enter two points coordinates ");
String input=in.nextLine();
String stringNumbers[]=input.split(" ");
int x1=Integer.parseInt(stringNumbers[0]),
y1=Integer.parseInt(stringNumbers[1]),
x2=Integer.parseInt(stringNumbers[2]),
y2=Integer.parseInt(stringNumbers[3]);

System.out.print("Distance :"+Math.sqrt(Math.pow((x2-x1),2) + Math.pow((y2-y1),2)));


}

TRENDING NEWS