You are on page 1of 9

PMSCS OOP 602

HW Chap 06
Name: Md. Jeyson Jaman Sawan
Roll: CSE202101001
Level 1 Programming Exercises★

06. Write a program to print out the numbers 10 through 49 in the following manner:

Solution:
07. A prime number is an integer greater than 1 and divisible by only itself and 1. The first seven
prime numbers are 2, 3, 5, 7, 11, 13, and 17. Write a method that returns true if its parameter is
a prime number. Using this method, write a program that repeatedly asks the user for input
and displays Prime if the input is a prime number and Not Prime, otherwise. Stop the repetition
when the input is a negative number.
Solution:
Level 2 Programming Exercises ★★
18. Write a method that returns the number of digits in an integer argument; for example, 23,498 has five
digits. Using this method, write a program that repeatedly asks for input and displays the number of digits
the input integer has. Stop the repetition when the input value is negative.

Solution:
24. Write a program that inputs N, where 3<= N <= 25, and outputs a cross. The following figure shows
the output when N is 5.

Solution:
package myutil;

public class Person {

private String name;

public Person( ) {

name = "Unknown";

public String getName() {

return name;

public void setName(String name) {

this.name = name;

}
package ch7_level01_14;

import myutil.Person;

public class Ch7_level01_14 {

public static void main(String[] args) {

Person obj= new Person();

obj.setName("JJ Sawan");

System.out.println(obj.getName());

package myutil;

public class MealCard {

private int points;

public MealCard(){

points=100;

public int getPoints(){

return points;

public void PurchasePoints(int p){

this.points= points+p;

public void FoodPurchase(int price){

if((this.points-price)>0){

this.points= points-price;
}

else

System.out.println("You are not allowed to purchase because your balance is negative");

package ch7_level01_14;

import java.util.Scanner;

import myutil.MealCard;

public class ch4_level02_16 {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

MealCard obj1=new MealCard();

int point, foodprice;

System.out.println("You have bought 1st food item. Price of this food item is: ");

foodprice=sc.nextInt();

obj1.FoodPurchase(foodprice);

System.out.println("You have bought 2nd food item. Price of this food item is: ");

foodprice=sc.nextInt();

obj1.FoodPurchase(foodprice);

System.out.println("Your Total Point: "+obj1.getPoints());

System.out.println("How much points you want to purchase? Amount:");

point=sc.nextInt();

obj1.PurchasePoints(point);

System.out.println("After adding points new new balance point: "+obj1.getPoints());


}

You might also like