hello folks, Here s d ansz for all the ten problems in java assignments1. As for as i concerned it z correct upto my knowledge. Reg compiling n running also it works good. I say u not to upload the same things directly. If u aware of java just edit as u wish and if u don't know anything abt java, jz change the class names(which s at 2nd o 3rd line of each prog : class jx(change this jx to other word) , words within inverted commas in output lines and variables.
System.out.println("Enter the constant rate of Rocket:"); System.out.println("Enter the time:");
Solutions:
Program1: Write a program to find the difference between sum of the squares and the square of the sums of n numbers?
import java.io.*;
import java.util.Scanner;
class j1
{
public static void main(String args[]) throws IOException
{
Scanner s=new Scanner(System.in);
System.out.println("How many numbers:");
int n=s.nextInt();
int a[]=new int[n];
int i, sqr, diff, count=0, plus=0;
System.out.print("Type the "+n + " Numbers \n");
for(i=0;i<n;i++)
{
a[i]=s.nextInt();
count+=(a[i]*a[i]);
plus+=a[i];
}
sqr=plus*plus;
diff=sqr-count;
System.out.print("\nSum of Squares of given "+n +"number is :"+count);
System.out.print("\nSquares of Sum of given "+n + "number is :"+sqr);
System.out.println("\nDifference between sum of the squares and \nthe square of the sum of given "+n + " number is :"+diff);
}}
Program 2: Develop a program that accepts the area of a square and will calculate its perimeter.
import java.util.*;
import java.text.*;
class j2
{
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();
System.out.println("Perimeter of Square is :"+df.format(4*Math.sqrt(area)));
}}
Program 3: Develop the program calculateCylinderVolume., which accepts radius of a cylinder's base disk and its height and computes the volume of the cylinder.
import java.util.*;
class j3
{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.print("Enter Radius: ");
double r=input.nextDouble();
System.out.print("Enter Height: ");
double h=input.nextDouble();
System.out.println("Volume of Cylinder: "+(Math.PI*r*r*h));
}}
Program 4: 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.
import java.util.*;
import java.text.*;
public class j4
{
public static void main(String[]args){
DecimalFormat df=new DecimalFormat("$##.00");
Scanner input=new Scanner(System.in);
System.out.print("Enter Number of Hours Worked: ");
double hours=input.nextDouble();
double pay=(hours*12)-(hours*12*0.15);
System.out.println("Net Pay is: "+df.format(pay));
}}
Program 5: 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.
import java.io.*;
class j5
{
public static void main(String[] s) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the number of customers");
int ticket=Integer.parseInt(br.readLine());
System.out.println("Total Income: "+((5*ticket)-(20+(0.5*ticket))));
}}
Program 6: Develop the program calculateCylinderArea, which accepts radius of the cylinder's base disk and its height and computes surface area of the cylinder.
Hint :surface area of a cylinder is 2pi*r2 + 2pi*R2
import java.util.*;
import java.text.*;
class j6
{
public static void main(String[] args)
{
DecimalFormat df = new DecimalFormat("##.00");
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 surfarea=2*Math.PI*r*(r+h);
System.out.println("Surface Area of Cylinder: "+df.format(surfarea));
}
}
Program 7: 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.
Hint: here surface means inner, outer , top n bottom 2pi*r*h + 2pi*R*h + 2(pi*R2-pi*r2)
import java.io.*;
class j7
{
public static void main(String[] args) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter inner radius");
double r=Integer.parseInt(br.readLine());
System.out.println("Enter thickness");
double t=Integer.parseInt(br.readLine());
System.out.println("Enter height");
double h=Integer.parseInt(br.readLine());
double R=r+t;
double surfacearea=((2*Math.PI*r*h)+(2*Math.PI*R*h)+((2*Math.PI)*((R*R)-(r*r))));
System.out.println("Total Suraface Area: "+(surfacearea));
}}
Program 8: 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.
Hint : Simple Physics laws of motion aptitude question
import java.util.*;
import java.text.*;
class j8
{
public static void main(String[] args)
{
DecimalFormat df = new DecimalFormat("##.00");
Scanner input=new Scanner(System.in);
double g=input.nextDouble();
double t=input.nextDouble();
double speed=g*t;
double height=0.5*speed*t;
System.out.println("Height that the rocket reaches in given time "+t + " is: "+df.format(height));
}}
Program 9: 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.
Hint :Simple question in confounding way-pythagorous theorem
import java.io.*;
class j9
{
public static void main(String[] args) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the speed of the Boat:");
double bs=Double.parseDouble(br.readLine());
System.out.println("Enter the speed of the River:");
double rs=Double.parseDouble(br.readLine());
System.out.println("Enter the width of the River :");
double width=Double.parseDouble(br.readLine());
double factor=rs/bs;
factor=(1/(1+factor*factor));
factor=Math.sqrt(factor);
System.out.println("Distance: "+(width/factor));
}}
Program 10: 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.
Hint : Simple interest=(P*N*R)/100
import java.io.*;
class j10
{
public static void main(String[] xxx) throws IOException
{
BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Principal amount:");
double pr=Integer.parseInt(input.readLine());
System.out.println("Enter the interest Rate (in %):");
double rate=Double.parseDouble(input.readLine());
System.out.println("Enter the total number of months:");
Double months=Double.parseDouble(input.readLine());
months=months/12;
double interest=0.01*(pr*rate*months);
System.out.println("Interest after "+months + " years are: "+interest);
System.out.println("Total Balance including principal at the end is :"+(pr+interest));
}
}
Thanks for uploading
ReplyDeleteDo upload 2nd assignment mate.... Thanx
ReplyDelete