Results 1 to 3 of 3
Thread: Can someone check this over?
- 03-28-2011, 06:49 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 6
- Rep Power
- 0
Can someone check this over?
So a piece of my project is this:
One kilobyte = 1024 bytes. Write an interactive program that converts from bytes to KB. The program will prompt the user for the number of bytes to convert. The program will convert to kilobytes as a result with decimal places and also as a whole value with left over bytes in a separate variable. Also, the program will convert to bits (recall 8bits = 1byte). The program will show the KB result in two different ways (decimal and as a whole number) and also, it will show the equivalent of bits.
*Im kind of confused on the instructions and ive been sick so I have not been able to ask the teacher but this is what I came up with
Thanks again guys and gals!
* @(#)Project4.java
*
* Project4 application
*
* @author
* @version 1.00 2011/3/27
*/
import java.util.Scanner;
public class Project4 {
public static void main(String[] args) {
/** 1) We will declare 5 variables which will all carry double types but one int. double bits, bytes, kbDec, kbleft
* and int kbWhole
* 2) We will then make 1 user inputs to get the amount of bytes the user wants converted.
* 3) Once we are able to obtain the information from the user then we will calculate the decimal of the
* inputed value into kilobytes, the whole number into kilobytes, any left over bytes, and also the the bytes converted to bits.
* 4) Finally we have our output statement which will give the user the kilobytes in decimal form and whole form with left over bits.
* I will also be converting the bytes into bits for the user as well.
*/
//Title//
System.out.println("Converting bytes to Kilobytes\n\n");
//Declare//
double bytes;
double kbDec;
double kbLeft;
int kbWhole;
double bits;
Scanner keyboard = new Scanner(System.in);
//Initialize//
System.out.print("Please enter the number of bytes you want converted and hit enter = ");
bytes = keyboard.nextDouble();
//Calculate//
kbDec = bytes/1024;
kbWhole = (int)bytes/1024;
kbLeft = (int)bytes%1024;
bits = (double)bytes * 8;
//Display//
System.out.println("\n\n\nThe kilobytes converted in decimals is : " + kbDec + " kilobytes");
System.out.println("\nThe kilobytes coverted to a whole number is : " + kbWhole + " kilobytes");
System.out.println("\nThe left over bytes are : " + kbLeft + " bytes");
System.out.println("\nThe bytes converted into bits are : " + bits + " bits");
- 03-28-2011, 06:25 PM #2
Senior Member
- Join Date
- Apr 2010
- Location
- Dhaka,Bangladesh
- Posts
- 178
- Rep Power
- 0
So a piece of my project is this:
One kilobyte = 1024 bytes. Write an interactive program that converts from bytes to KB. The program will prompt the user for the number of bytes to convert. The program will convert to kilobytes as a result with decimal places and also as a whole value with left over bytes in a separate variable. Also, the program will convert to bits (recall 8bits = 1byte). The program will show the KB result in two different ways (decimal and as a whole number) and also, it will show the equivalent of bits.
*Im kind of confused on the instructions and ive been sick so I have not been able to ask the teacher but this is what I came up with
Thanks again guys and gals!
Your algo is okay in my opinion.Go through your algorithm.
- 03-29-2011, 09:07 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,458
- Rep Power
- 16
Similar Threads
-
How check box can disabled
By man4ish in forum AWT / SwingReplies: 3Last Post: 01-07-2010, 04:05 AM -
Don't know what to check for
By Chasingxsuns in forum New To JavaReplies: 8Last Post: 08-26-2009, 05:59 AM -
pls check it
By aRTx in forum New To JavaReplies: 0Last Post: 03-24-2009, 02:35 PM -
Check box tag
By elizaabru in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 08-26-2008, 02:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks