I'm a newbie at java and I need help in coming up with the correct answer for this JOption java program. I enter in 2k, 30fps, 4min, 0seconds, and I should get 10.6842041GB (16.02630615GB total space needed). Please let me know if you have any advice on how I could fix this?

Thanks!
-A

import javax.swing.*;
import java.lang.*;
import java.io.*;

public class storageSP {

	public static void main(String[] args) {
		//declare variables
		int res;
		String kfilm;
		int cb;
		String sfps;
		int fps;
		int newNo;
		String sminutes;
		String sseconds;
		int minutes;
		int seconds;
		int minsec;
		int Bit;
		int Byte;
		int kbyte;
		int mbyte;
		int gbyte;
		int tbyte;
		//int pbyte; if needed in the future
		int istorage;
		float storage;
		double perc;
		double storagePt5;
		double dultStorage;
		int ultStorage;

		
		//#get k of film
		kfilm = JOptionPane.showInputDialog("Please enter film type 1k,2k, 4k, or 8k? ");
		
	    if (kfilm.equals("1k")){
	    	res = 1024*778;//796672
	    }
	    else if (kfilm.equals("2k")){
	    	res = 2048*1556;//3186688
	    }
	    else if (kfilm.equals("4k")){
	    	res = 4096*3112;//12746752
	    }
	    else if (kfilm.equals("8k")){
	    	res = 8192*6224;//50987008
	    }
	    else {
	    	res = 0;
	    }
		
	    cb = res*4;//#resolution of frame with RGBA channels
	    
		//get fps
		sfps = JOptionPane.showInputDialog("How many frames/second? 30 (COMMON - mono), 60 (stereo), or 24 (film)  ");
		fps = Integer.parseInt(sfps.trim());
		
		//newNo for Bits later
		newNo = cb*fps;
		
		//How long?
		sminutes = JOptionPane.showInputDialog("How many minutes? ");
		sseconds = JOptionPane.showInputDialog("How many seconds? ");
		minutes = Integer.parseInt(sminutes.trim());
		seconds = Integer.parseInt(sseconds.trim());
		
		if (minutes>0){
			minsec = minutes*60;
			minsec = minsec+seconds;
		}
		else {
		    minsec = seconds;
		}	
		
		//# Measurement in Bits, Bytes...etc
		Bit = newNo*minsec;
		Byte = Bit/8;
		kbyte = Byte/1024;
		mbyte = kbyte/1024;
		gbyte = mbyte/1024;
		tbyte = gbyte/1024;
		
		//# figure the bits, bytes, kbytes, mbytes, gbytes, tbytes, or pbytes needed
		if (Bit < 1024){
			JOptionPane.showMessageDialog(null, Bit + " Bits");
			istorage = Bit;
		}
		else if (Byte < 1024){
			JOptionPane.showMessageDialog(null, Byte + " Bytes");
			istorage = Byte;
		}
		else if (kbyte < 1024){
			JOptionPane.showMessageDialog(null, kbyte + " kB");
			istorage = kbyte;
		}
		else if (mbyte < 1024){
			JOptionPane.showMessageDialog(null, mbyte + " MB");
			istorage = mbyte;
		}
		else if (gbyte < 1024){
			JOptionPane.showMessageDialog(null, gbyte + " GB");
			istorage = gbyte;
		}
		else if (tbyte < 1024){
		    JOptionPane.showMessageDialog(null, tbyte + " Terabytes");
		    istorage = tbyte;
		}
		else{
			return;
		}
		
		storage = (float)istorage;
			
		//#need to ensure proper storage space
		JOptionPane.showMessageDialog(null, "PLEASE NOTE to add more storage space \nso the project runs more smoothly!!");
		
		//storagePt5=storage*.5
		perc = 0.5;
		storagePt5 = Math.floor(storage*perc);
		dultStorage = storage*storagePt5;
		ultStorage = (int)dultStorage;
		JOptionPane.showMessageDialog(null, "So try " + ultStorage);
	}
}

I should get 10.6842041GB (16.02630615GB total space needed).

What do you get? You don't show what the program currently outputs.
What is the program supposed to do?
What is the relationship between: k, fps, min and seconds?

I see that you are doing integer divisions. for example: gbyte = mbyte/1024

No rounding or remainders. 4/3 = 1

The program is suppose to output the space needed (in gigs, megs, whatever) for the digital film that has been produced. For instance, someone requested that they wanted enough hard drive space for a 2k, 4min, commercial.

1. We calculate 2k (which is 2048x1556 pixels).
2. Multiply by 4 channels.
3. Get the frames per second (common ans is 30fps)
4. Determine minutes and seconds of film (4min, 0 sec)
*The final result is in Bits now
5. Determine whether megs, gigs. etc
6. Add 50% to the result to get the space needed for the project

Final answer should be 16.02630615 GB
But, I get 17672 [in MG]

Can you show me the arithmetic equation that computes the value.
Did you see my comment about your code using integer arithmetic?

If you don't understand what I mean by integer arithmetic, put a
System.out.println("var=" + value);
statement after every computational step in the program.
Compare the printed results of each step with your manually computed values.
You should immediately see what's wrong.

I'm not sure what you mean by integer arithmetic? Do you mean int verses float or double?

Here is the calculation for the program:
2048(pix) x 1556(pix) x 4(chan) x 30(fps) x 4(min) x 60(to get sec) / 8(Bit) / 1024(kB) / 1024(MB) / 1024(for GB) = 10.68]
10.68 x .5 = 5.34
5.34+10.68 = 16.02

Thanks for your help!

this is the results of integer arithmetic: 4/3 = 1 NOT 1.33333
See added note on my previous posting about printing out results at each step.

Thank you so much, Norm! I changed everything to float ('cept for the percentage portion) and I'm almost there... the result is correct, now I'm on to my 'storage space needed for project' ultimate result. Thanks so much!!!:)

import javax.swing.*;

public class storageSP {

	public static void main(String[] args) {
		//declare variables
		float res;
		String kfilm;
		String sfps;
		float fps;
		String sminutes;
		String sseconds;
		float minutes;
		float seconds;
		float minsec;
		float Bit;
		float Byte;
		float kbyte;
		float mbyte;
		float gbyte;
		float tbyte;
		//int pbyte; if needed in the future
		float storage;
		double perc;
		double storagePt5;
		float ultStorage;

		
		//#get k of film
		kfilm = JOptionPane.showInputDialog("Please enter film type 1k,2k, 4k, or 8k? ");
		
	    if (kfilm.equals("1k")){
	    	res = 1024*778;//796672
	    }
	    else if (kfilm.equals("2k")){
	    	res = 2048*1556;//3186688
	    }
	    else if (kfilm.equals("4k")){
	    	res = 4096*3112;//12746752
	    }
	    else if (kfilm.equals("8k")){
	    	res = 8192*6224;//50987008
	    }
	    else {
	    	return;
	    }
	    
		//get fps
		sfps = JOptionPane.showInputDialog("How many frames/second? 30 (COMMON - mono), 60 (stereo), or 24 (film)  ");
		fps = Integer.parseInt(sfps.trim());
		
		//How long?
		sminutes = JOptionPane.showInputDialog("How many minutes? ");
		sseconds = JOptionPane.showInputDialog("How many seconds? ");
		minutes = Integer.parseInt(sminutes.trim());
		seconds = Integer.parseInt(sseconds.trim());
		
		if (minutes >0){
			minsec = minutes*60;
			minsec = minsec+seconds;
		}
		else {
		    minsec = seconds;
		}	
		
		//# Measurement in Bits, Bytes...etc
		Bit=res*4*fps*minsec;//resolution*4channels*fps*minutes and seconds
		Byte = Bit/8;
		kbyte = Byte/1024;
		mbyte = kbyte/1024;
		gbyte = mbyte/1024;
		tbyte = gbyte/1024;
		
		//# figure the bits, bytes, kbytes, mbytes, gbytes, tbytes, or pbytes needed
		if (Bit < 1024){
			JOptionPane.showMessageDialog(null, Bit + " Bits");
			storage = Bit;
		}
		else if (Byte < 1024){
			JOptionPane.showMessageDialog(null, Byte + " Bytes");
			storage = Byte;
		}
		else if (kbyte < 1024){
			JOptionPane.showMessageDialog(null, kbyte + " kB");
			storage = kbyte;
		}
		else if (mbyte < 1024){
			JOptionPane.showMessageDialog(null, mbyte + " MB");
			storage = mbyte;
		}
		else if (gbyte < 1024){
			JOptionPane.showMessageDialog(null, gbyte + " GB");
			storage = gbyte;
		}
		else if (tbyte < 1024){
		    JOptionPane.showMessageDialog(null, tbyte + " Terabytes");
		    storage = tbyte;
		}
		else{
			return;
		}
			
		//#need to ensure proper storage space
		JOptionPane.showMessageDialog(null, "PLEASE NOTE to add more storage space \nso the project runs more smoothly!!");
		
		//storagePt5=storage*.5
		perc = 0.5;
		storagePt5 = Math.floor(storage*perc);
		ultStorage = (float) (storage*storagePt5);
		JOptionPane.showMessageDialog(null, "So try " + ultStorage);
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.