Posted in : Java Beginners

Write a program to find the difference between sum of the squares and the square of the sums of n numbers?

Develop a program that accepts the area of a square and will calculate its perimeter.

Develop the program calculateCylinderVolume., which accepts radius of a cylinder's base disk and its height and computes the volume of the cylinder.

Utopias tax accountants always use programs that compute income taxes even though the tax rate is a solid, never-changing 15%. Define the program calculateTax which determines the tax on the gross pay. Define calculateNetPay that determines the net pay of an employee from the number of hours worked. Assume an hourly rate of $12.

An old-style movie theater has a simple profit program. Each customer pays $5 per ticket. Every performance costs the theater $20, plus $.50 per attendee. Develop the program calculateTotalProfit that consumes the number of attendees (of a show) and calculates how much income the show earns.

Develop the program calculateCylinderArea, which accepts radius of the cylinder's base disk and its height and computes surface area of the cylinder.

Develop the program calculatePipeArea. It computes the surface area of a pipe, which is an open cylinder. The program accpets three values: the pipes inner radius, its length, and the thickness of its wall.

Develop the program calculateHeight, which computes the height that a rocket reaches in a given amount of time. If the rocket accelerates at a constant rate g, it reaches a speed of g · t in t time units and a height of 1/2 * v * t where v is the speed at t.

Develop a program that computes the distance a boat travels across a river, given the width of the river, the boat's speed perpendicular to the river, and the river's speed. Speed is distance/time, and the Pythagorean Theorem is c2 = a2 + b2.

Develop a program that accepts an initial amount of money (called the principal), a simple annual interest rate, and a number of months will compute the balance at the end of that time. Assume that no additional deposits or withdrawals are made and that a month is 1/12 of a year. Total interest is the product of the principal, the annual interest rate expressed as a decimal, and the number of years.

Mail me at nitesh_loveguy@yahoo.co.in as soon as possible. Thanks.

View Answers

December 16, 2010 at 3:27 PM

Hi Friend,

Try the following code:

1)

import java.util.*; class FindDifference { public static void main(String[] args) { int sum=0,sum1=0,sum2=0; Scanner input=new Scanner(System.in); System.out.println("Enter value of n: "); int n=input.nextInt(); for(int i=1;i<=n;i++){ int sq=i*i; sum1+=sq; } //System.out.println(sum1); for(int i=1;i<=n;i++){ sum+=i; } sum2=sum*sum; //System.out.println(sum2); int diff=0; if(sum1>sum2){ diff=sum1-sum2; } else{ diff=sum2-sum1; } System.out.println(diff); } }

2)

import java.util.*; import java.text.*; class PerimeterOfSquare{ public static void main(String[] args) { DecimalFormat df = new DecimalFormat("##.00"); Scanner input=new Scanner(System.in); System.out.println("Enter Area of Square:"); double area=input.nextDouble(); double side=Math.sqrt(area); System.out.println("Side of Square is: "+df.format(side)); double perimeter=4*side; System.out.println("Perimeter of Square is: "+df.format(perimeter)); } } 3) import java.util.*; import java.text.*; class CalculateCyliderVolume { public static void main(String[] args) { DecimalFormat df = new DecimalFormat("##.00"); double PI=3.14; Scanner input=new Scanner(System.in); System.out.print("Enter Radius: "); double r=input.nextDouble(); System.out.print("Enter Height: "); double h=input.nextDouble(); double volume=PI*r*r*h; System.out.println("Volume of Cylinder: "+df.format(volume)); } }

December 16, 2010 at 4:12 PM

continue..

4)

import java.util.*; import java.text.*; public class CalculateNetPay { public static void main(String[]args){ double taxRate=0.15; double hourlyRate=12; DecimalFormat df=new DecimalFormat("$##.00"); Scanner input=new Scanner(System.in); System.out.print("Enter Number of Hours Worked: "); double hrs=input.nextDouble(); double gp=hrs*hourlyRate; double tax=gp*taxRate; double netpay=gp-tax; System.out.println("Net Pay is: "+df.format(netpay)); } }

5)

import java.util.*; import java.text.*; class CalculateTotalProfit{ public static void main(String[] args) { DecimalFormat df=new DecimalFormat("$##.00"); double theaterCost=20; Scanner input=new Scanner(System.in); System.out.println("Enter Number of Customers: "); double cus=input.nextDouble(); double earnFromTickets=5*cus; double attendeesCost=cus*0.50; double cost=attendeesCost+theaterCost; double profit=earnFromTickets-cost; System.out.println("Total Profit: "+df.format(profit)); } }

6)

import java.util.*; import java.text.*; class CalculateCylinderArea { public static void main(String[] args) { DecimalFormat df = new DecimalFormat("##.00"); double pi=3.14; Scanner input=new Scanner(System.in); System.out.print("Enter Radius: "); double r=input.nextDouble(); System.out.print("Enter Height: "); double h=input.nextDouble(); double v1=2*pi*r*r; double v2=2*pi*r*h; double surfaceArea=v1+v2; System.out.println("Surface Area of Cylinder: "+df.format(surfaceArea)); } }

Thanks

December 16, 2010 at 5:54 PM

Hi Friend,

Try the following code:

import java.awt.*; import javax.swing.*; import java.awt.event.*; class TotalInterest extends JFrame{ TotalInterest(){ JLabel lab1=new JLabel("Principal"); final JTextField text1=new JTextField(20); JLabel lab2=new JLabel("Rate of Interest"); final JTextField text2= new JTextField(20); JLabel lab3=new JLabel("Number of Months"); final JTextField text3=new JTextField(20); JButton b=new JButton("Get"); b.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ double p=Double.parseDouble(text1.getText()); double r=Double.parseDouble(text2.getText())/100; double t=Double.parseDouble(text3.getText())/12; double interest=p*r*t; JOptionPane.showMessageDialog(null, "Total Interest is: "+interest); } }); setLayout(null); lab1.setBounds(10,10,100,20); text1.setBounds(150,10,200,20); lab2.setBounds(10,40,100,20); text2.setBounds(150,40,200,20); lab3.setBounds(10,70,120,20); text3.setBounds(150,70,200,20); b.setBounds(150,110,70,20); add(lab1); add(text1); add(lab2); add(text2); add(lab3); add(text3); add(b); setVisible(true); setSize(400,200); } public static void main(String[] args){ new TotalInterest(); } }

Thanks

December 16, 2010 at 6:53 PM

this is not fair... this is your 1st assignment of TCS and u r searching answeres here n there...this will not help u... it's very basic assignment and try urself... its not compulsory to submit assignment... if u'll not learn this u'll really face the big problems.

Now its ur choice what do u want... getting some help n searching for all solutions r 2 diff things... so study... dont waste ur time..

Related Tutorials/Questions & Answers: