Docsity

Java Programs for Triangle Perimeter, Tuition Fee Calculation, and Student Scores, Assignments of Cooperative Governance

Toggle sidebar
bg1
Question 3.9:
package parach1;
import java.util.Scanner;
public class Parach1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter three edges of the triangle: " );
int edge1 = input.nextInt();
int edge2 = input.nextInt();
int edge3 = input.nextInt();
if((edge1+edge2)>edge3 && (edge1+edge3)>edge2 && (edge2+edge3)>edge1){
int perimeter = edge1 + edge2 + edge3;
System.out.println("The perimeter is " + perimeter);
}
else
System.out.println("Invalid Input");
}
}
Output:
pf3
pf4
pf5

Partial preview of the text

Download Java Programs for Triangle Perimeter, Tuition Fee Calculation, and Student Scores and more Assignments Cooperative Governance in PDF only on Docsity!

Question 3.9:

package parach1; import java.util.Scanner; public class Parach1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter three edges of the triangle: " ); int edge1 = input.nextInt(); int edge2 = input.nextInt(); int edge3 = input.nextInt(); if((edge1+edge2)>edge3 && (edge1+edge3)>edge2 && (edge2+edge3)>edge1){ int perimeter = edge1 + edge2 + edge3; System.out.println("The perimeter is " + perimeter); } else System.out.println("Invalid Input"); } }

Output:

Invalid Output:

Question 5.7:

package parach1; import java.util.Scanner; public class Parach1 { public static void main(String[] args) {Scanner input = new Scanner(System.in); System.out.print("Enter tuition fee: "); double fees = input.nextDouble(); System.out.print("Enter the percentage increase per year: "); double increase = input.nextDouble(); double fee10 = 0; double totalFee = 0; int i=0; while(i<=14){ fees+= fees*(increase/100); if(i==10){ fee10 = fees; } else if(i>10){ totalFee+= fee10;

int i=1; while (i <= num) { System.out.print("Enter name of student " + i + ": "); n = input.next(); System.out.print("Enter score of student " + i + ": "); sc = input.nextDouble(); if (i == 1) { name1 = n; score1 = sc; } else if (i == 2 && sc < score1) { name2 = n; score2 = sc; } else if (i == 2 && sc > score1) { name2 = name1; score2 = score1; name1 = n; score1 = sc; } else if (i > 2 && sc > score1) { name2 = name1; score2 = score1; name1 = n; score1 = sc; } else if (i > 2 && sc > score2 && sc < score1) { name2 = n; score2 = sc; } i++;

System.out.println("FIRST: " + name1 + " SCORE: "

  • score1 + " SECOND: " + name2 + " SCORE: " + score2); } }

Output: