JAVA/OOP/DATA STRUCTURE: Write a program to compute the total power generated by
ID: 3663175 • Letter: J
Question
JAVA/OOP/DATA STRUCTURE: Write a program to compute the total power generated by N cyberverns, where N is a number entered by the user. For each cybervern, ask for the input frequency, compute the power, and add that power to the total. Each time you ask the user to enter the frequency, if the user does not enter a positive number, display an error message and ask them again until they enter a positive number. (If the frequency is not positive, then do not compute the power and do not count that as one of the N cyberverns. Allow the user to enter N positive frequencies.) You do not need to check for a positive number for N - the number of cyberverns. Display the final total power (and do not display the cumulative total after each cybervern)
The power generated by a cybervern is:
p=M (PI) q^4
Where:
p= power (in kilowatts)
M= Murray's constant (5/7)
q= frequency (in megahertz)
PI= 3.14159....
Explanation / Answer
class power_cyber
{
public static void main(String args[])
{
int q,N;
double totpow=0, p;
Scanner scan = new Scanner(System.in);
System.out.println("Enter value for N");
N=scan.nextInt();
int i=1;
whilei<=N)
{
System.out.println("Enter Frequency");
q=scan.nextInt();
if(q<0)
{
System.out.println("Pl. enter positive frequency");
}
else
{
p=(5/7)*3.14159*(q*q*q*q);
System.out.println("Power for given frequency is " + p);
i++;
totpow=totpow+p;
}
}
System.out.println("Total Cybervern="+totpow);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.