0% found this document useful (0 votes)
316 views3 pages

TCS 28 December Proctored Assessment Java Solutions: Program 1

The document contains code for two Java programs. The first program counts the number of characters and spaces in a given string. The second program defines a Movie class with properties like name, genre, budget. It takes movie details as input, stores in Movie objects, filters by genre and checks if each movie's budget is high or low.

Uploaded by

Jeevan Sai Maddi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
316 views3 pages

TCS 28 December Proctored Assessment Java Solutions: Program 1

The document contains code for two Java programs. The first program counts the number of characters and spaces in a given string. The second program defines a Movie class with properties like name, genre, budget. It takes movie details as input, stores in Movie objects, filters by genre and checks if each movie's budget is high or low.

Uploaded by

Jeevan Sai Maddi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

TCS 28th December Proctored Assessment Java

Solutions
(+919637737966)

Program 1:
import java.util.Scanner;

public class Solution {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
str = str.toLowerCase();
int c = 0, s = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) >= 97 && str.charAt(i) <= 122) {
c++;
} else if (str.charAt(i) == ' ') {
s++;
}
}
System.out.println("No of character: " + c + " and spaces: " +
s);
sc.close();
}
}

Output:
Example 1:
Welcome to java
No of Characters: 13 and no. of spaces: 2

Example 2:
h@llo world
No of character: 9 and spaces: 1

Program 2:

import java.util.Scanner;

public class Solution {

public static void main(String[] args) {


// TODO Auto-generated method stub
Movie[] m = new Movie[4];
Scanner sc = new Scanner(System.in);
for (int i = 0; i < m.length; i++) {
String a = sc.next();
String b = sc.next();
String c = sc.next();
int d = sc.nextInt();
m[i] = new Movie(a, b, c, d);
}
String s = sc.next();
Movie[] res = isBudget(m, s);
for (Movie x : res) {
if (x.budget > 80000000)
System.out.println("High Budget Movie");
else
System.out.println("Low Budget Movie");
}
sc.close();
}

public static Movie[] isBudget(Movie[] m, String s) {


// TODO Auto-generated method stub
Movie[] res;
int j = 0;
for (Movie x : m) {
if (x.genre.equals(s))
j++;
}
res = new Movie[j];
for (Movie x : m) {
if (x.genre.equals(s))
res = m;
}
return res;
}

class Movie {
String movieName;
String movieProduction;
String genre;
int budget;

public Movie(String movieName, String movieProduction, String genre,


int budget) {
super();
this.movieName = movieName;
this.movieProduction = movieProduction;
this.genre = genre;
this.budget = budget;
}

public String getMovieName() {


return movieName;
}

public void setMovieName(String movieName) {


this.movieName = movieName;
}

public String getMovieProduction() {


return movieProduction;
}

public void setMovieProduction(String movieProduction) {


this.movieProduction = movieProduction;
}

public String getGenre() {


return genre;
}

public void setGenre(String genre) {


this.genre = genre;
}

public int getBudget() {


return budget;
}

public void setBudget(int budget) {


this.budget = budget;
}

Output:
ironman
marvel
action
80522000
superman
dc
action
75005100
avengers
marvel
action
90001200
batman
dc
action
45000000
action
High Budget Movie
Low Budget Movie
High Budget Movie
Low Budget Movie

You might also like