
Find all the practical at one place of Gujarat Technological University(GTU) With Solutions.
Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts
Sunday, June 30, 2019
Prepare an activity diagram for computing a restaurant bill, there should be charge for each delivered item. The total amount should be subject to tax and service charge of 18% for group of six and more. For smaller groups there should be a blank entry. Any coupons or gift certificates submitted by the customer should be subtracted

Categorize the following relationships into generalization, aggregation or association
A country has a capital city
A dining philosopher uses a fork
A file is an ordinary file or a directory file
Files contains records
A polygon is composed of an ordered set of points
A drawing object is text, a geometrical object, or a group
A person uses a computer language on a object
Modems and keyboards are input/output devices
Classes may have several attributes
A person plays for a team in a certain year
A route connects two cities
A student takes a course from a professor
Refine the student manager program to manipulate the student information from files by using the DataInputStream and DataOutputStream. Assume suitable data
import java.io.*;
public class Dataio {
public static void main(String args[]) throws IOException {
DataInputStream dataIS = new DataInputStream(new FileInputStream("stdinfo.txt"));
DataOutputStream dataOS = new DataOutputStream(new FileOutputStream("newstdinfo.txt"));
// manipulate the student information from files
String str;
while ((str = dataIS.readLine()) != null) {
String upper = str.toUpperCase();
System.out.println(upper);
dataOS.writeBytes(upper + " ,");
}
dataIS.close();
dataOS.close();
}
}
Refine the student manager program to manipulate the student information from files by using the BufferedReader and BufferedWriter
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
public class Student {
public static void main(String[] argv) throws Exception {
BufferedReader bufRead = new BufferedReader(new FileReader("stdinfo.txt"));
BufferedWriter bufWrite = new BufferedWriter(new FileWriter("newstdinfo.txt"));
int i;
// manipulate the student information from files
do {
i = bufRead.read();
if (i != -1) {
if (Character.isUpperCase((char) i)) {
bufWrite.write(Character.toLowerCase((char) i));
} else {
bufWrite.write((char) i);
}
}
} while (i != -1);
bufRead.close();
bufWrite.close();
}
}
Create a class called Student. Write a student manager program to manipulate the student information from files by using FileInputStream and FileOutputStream
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class Student {
public static void main(String[] args) {
System.out.println("-------Writing Data in File-------");
try {
FileOutputStream fout = new FileOutputStream("stdinfo.txt");
String str = "Nmae : Sachin, Stream : Computer Engineering, Sem : 5th Sem";
byte b[] = str.getBytes();
fout.write(b);
fout.close();
System.out.println("successful write.");
} catch (Exception e) {
System.out.println(e);
}
System.out.println("-------Retrive Data From File-------");
try {
FileInputStream fin = new FileInputStream("stdinfo.txt");
int i = 0;
while ((i = fin.read()) != -1) {
System.out.print((char) i);
}
fin.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
Write an interactive program to print a diamond shape. For example, if user enters the number 3
import java.util.Scanner;
public class demo {
public static void main(String[] args) {
int i, j, k;
Scanner scan = new Scanner(System.in);
int no = scan.nextInt();
for (i = 0; i < no; i++) {
for (j = (no / 2) + 1; j >= i; j--) {
System.out.print(" ");
}
for (k = 0; k <= i; k++) {
System.out.print("* ");
}
System.out.println();
}
for (i = 0; i < no; i++) {
System.out.print(" ");
for (j = 0; j <= i; j++) {
System.out.print(" ");
}
for (k = no - 1; k > i; k--) {
System.out.print("* ");
}
System.out.println();
}
}
}
Saturday, October 6, 2018
Write an interactive program to print a string entrered in a pyramid form. For instance, the string "stream"
public class Program_9 {
public static void main(String[] args) {
int i, j, k;
String str = "Stream";
for (i = 0; i < str.length(); i++) {
for (j = (str.length() / 2) + 1; j >= i; j--) {
System.out.print(" ");
}
for (k = 0; k <= i; k++) {
System.out.print(str.charAt(k) + " ");
}
System.out.println();
}
}
}
Sunday, September 23, 2018
Create a class which ask the user to enter a sentence, and it should display count of each vowel type in the sentence. The program should continue till user enters a word “quit”.
import java.util.Scanner;
public class Program_8 {
public static void main(String[] args) {
System.out.println("Enter the word 'quit' to end this program.");
String str;
int x = 0, A = 0, E = 0, I = 0, O = 0, U = 0;
char ch;
Scanner in = new Scanner(System.in);
while (x < 1) {
str = in.next();
if (str.equals("quit")) {
x++;
in.close();
break;
} else {
for (int i = 0; i < str.length(); i++) {
ch = str.charAt(i);
if (ch == 'a' || ch == 'A') {
A++;
} else if (ch == 'e' || ch == 'E') {
E++;
} else if (ch == 'i' || ch == 'I') {
I++;
} else if (ch == 'o' || ch == 'O') {
O++;
} else if (ch == 'u' || ch == 'U') {
U++;
}
}
}
}
System.out.println("Vowels A or a: " + A + "\nVowels E or e: " + E + "\nVowels I or i: " + I);
System.out.println("Vowels O or o: " + O + "\nVowels U or u: " + U + "\nTotal Vowels: " + (A + E + I + O + U));
}
}
Friday, September 21, 2018
Write a program to find that given number or string is palindrome or not.
import java.util.Scanner;
public class Program_7 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String str = scan.next();
String rvs = new StringBuffer(str).reverse().toString();
if(str.equals(rvs)){
System.out.println("It is palindrome");
}
else{
System.out.println("It is not palindrome");
}
}
}
Write a program to count the number of words that start with capital letters.
import java.util.Scanner;
public class Program_6 {
public static void main(String[] args) {
int count = 0;
Scanner scan = new Scanner(System.in);
String str = scan.next();
for (int i = 0; i < str.length(); i++) {
if (Character.isUpperCase(str.charAt(i))) {
count++;
}
}
System.out.println("No of Capital Letters:" + count);
}
}
Tuesday, September 18, 2018
Write a program to accept a line and check how many consonants and vowels are there in line
import java.io.*;
class Program_1
{
public static void main(String args[]) throws IOException
{
String str;
int vowels = 0, consonants = 0;
char ch;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a Line : ");
str = br.readLine();
for(int i = 0; i < str.length(); i ++)
{
ch = str.charAt(i);
if(ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' ||
ch == 'I' || ch == 'o' || ch == 'O' || ch == 'u' || ch == 'U')
vowels ++;
else if(Character.isAlphabetic(ch))
consonants ++;
}
System.out.println("Vowels : " + vowels);
System.out.println("Consonants : " + consonants);
}
}
Write a program to find length of string and print second half of the string.
import java.util.Scanner;
public class Program_4 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String str = scan.next();
System.out.println("Lenght of String : "+str.length());
System.out.println("Print second half : "+str.substring(str.length()/2));
}
}
Write a program to enter two numbers and perform mathematical operations on them.
import java.util.Scanner;
public class Program_3 {
public static void main(String[] args) {
int number1,number2,result;
Scanner scan = new Scanner(System.in);
number1 = scan.nextInt();
number2 = scan.nextInt();
result = number1 + number2;
System.out.println("Sum of two number : "+result);
}
}
Write a program that calculate percentage marks of the student if marks of 6 subjects are given.
import java.util.Scanner;
public class Program_2 {
public static void main(String[] args) {
int marks[] = new int[7];
int total = 0;
float percentage = 0;
Scanner scan = new Scanner(System.in);
for (int i = 1; i <= 6; i++) {
marks[i] = scan.nextInt();
}
for (int i = 1; i <= 6; i++) {
total = total + marks[i];
}
percentage = (total * 100) / 600;
System.out.println("Students percentage = " + percentage);
}
}
Friday, September 14, 2018
Write a program to convert rupees to dollar. 60 rupees=1 dollar
import java.util.Scanner;
public class Program_1 {
public static void main(String[] args) {
int rupees;
double dollar;
Scanner scan = new Scanner(System.in);
rupees = scan.nextInt();
dollar = rupees / 60;
System.out.println(rupees + " Rupees = " + dollar + " Dollar");
}
}
import java.util.Scanner;
public class Program_1 {
public static void main(String[] args) {
int rupees;
double dollar;
Scanner scan = new Scanner(System.in);
rupees = scan.nextInt();
dollar = rupees / 60;
System.out.println(rupees + " Rupees = " + dollar + " Dollar");
}
}
Subscribe to:
Posts (Atom)
-
import java.util.Scanner; public class Program_1 { public static void main(String[] args) { int rupees; doub...
-
Video Tutorial Pre-requiredment of DVWA installation Required install Xmapp or Wamp server click there name for Download Soft...















