Tuesday, June 3, 2008

I just started learning Java yesterday and was wondering if there was a method or something to determine if an input was a number- not another key press. (Like a letter- or symbol) I could make something to check for it- but if there s something that does it my program stays a bit more simple.

Thanks for the help. :)

I want to make a Font Preview with my fonts for a website..So people can type whatever phrase they want in the fonts listed and it will preview it for them...
Is there a java script or HTML code for this? If so - what is it? If not where to I go to get this? Also where do you place it...( Body- Head- etc)
Thanks

In other words- what functionality/advantages did Microsoft add to compete with Java or other languages? So that you can understand where I m coming from with this question: I am not much of a programmer but I was thrown onto a C# client/server project. I ve learned the basics of C# but i m trying to learn some theory as to the .Net environment.

How do you use the addition of String variables in a conversion from base 10 numbers to binary?

This is the assignment:
• Ask the user for a number in the decimal (base 10) number system. [2]
• Store this number into a variable with a suitable type and name [2]
• Take this number and convert it into binary (base 2) using the algorithm learned in the previous unit. â€" take the number- divide it by two- keep track of the remainder- continue until you reach a quotient of 0. [6]
• To find the remainder- you need to use the ‘mod’ function - %. 5%2=1 (5 divided by 2 is 2 remainder 1)
• It is possible to add to a variable of type String. (E.g. name = “C.I.”; name = “Lam” + name; c.print (name); - the output will be “LamC.I.”) â€" this is needed to keep track of your binary converted number

Can anyone explain how this can be done? Thanks ahead of time.
I have a bit of an understanding for the first few parts- it s only the string adding that is confusing me. My teacher said that 0 and 1 (the remainders of the mod to get to binary) should be treated as string values- and than get added together which kind of confuses me. I have- however managed to put together a program that gets the remainders- but the result comes out in the reversed order (for binary). Instead of 1011- I end up with 1101. That s basically the issue I m having with this
So how would I be able to go about implementing the addition of string values- to output the binary conversion from decimal (base 10)?

This is the part that s really confusing because I have integers which are used with the mod function to get the remainders- and then- I have to use those remainders by putting them together to get the binary number. But they re integer values- so I d have to make them string values?:S :S :S :S :S

Write a program to calculate the commission for a salesperson- given the amount of sales. The table below summarize the sales against commission rate. (Commission = Commission rate * total sales).

Sales:...........Commission Rate
<= 2000........0.02
2001-4000......0.04
4001-6000......0.07
>6000.............0.10


import java.util.Scanner;

class Calcommission {

public static void main(String Arg[ ]){

int sales;
double Commission=0;
double Commission_Rate=0;

Scanner sc = new Scanner(System.in);
System.out.println("sales: ");
sales = sc.nextInt();

if (sales >= 2000){
Commission_Rate = 0.02;
}else if (sales >= 2001 && sales == 4000) {
Commission_Rate = 0.04;
}else if (sales >= 4001 && sales == 6000){
Commission_Rate = 0.07;
}else if (sales > 6000) {
Commission_Rate = 0.10;
}

Commission = (Commission_Rate * sales);
System.out.println("Commission: ");
System.out.println("Commission_Rate");

}
}
when i tried to run the program- the value of commission did not come out by itself..only Commission: came out instead...i need the value of commission to come out by itself..pls help........

No comments: