Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. rite an application that displays your name using asterisks as an example to

ID: 3798073 • Letter: 1

Question

1. rite an application that displays your name using asterisks as an example to the use like: r; Then ask the user to enter a number between 0 and 9 to be displayed using asterisks. 2. Write an application that will generate a random number (integer) from 0 to 1000. The application should then ask the user to guess that number and display the following: a. If the user guesses a number that is smaller, it should ask the user to try a bigger number. b. If the user guesses a number that is bigger, it should ask the user to try a smaller number. c. If the user enters a value that is out of the range (not between 0 and 1000), the program should inform the user of the wrong choice, and ask the user to enter a valid number again the user guesses the number correctly, the program should display "Congratulations! You have guessed the number correct

Explanation / Answer

Ans 2.

package javaapplication8;

import java.util.Scanner;
import java.util.concurrent.ThreadLocalRandom;

/**
*
* @author Rashmi Tiwari
*/
public class JavaApplication8 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
  
int min=1;
int max=100;
int randomNum = ThreadLocalRandom.current().nextInt(min, max + 1);//ThreadLocalRandom will support after JDK 1.7 and Above
System.out.println("Guess A Number");
int num=sc.nextInt();
if(num>=0&&num<=1000){
if(num<randomNum){
System.out.println("Try Bigger Number");
}
else if(num>randomNum){
System.out.println("Try Smaller Number");
}
else {
System.out.println("Congratulations ! You have guessed the number correctly ");

}
}
else{
System.out.println("Enter valid number between 0 and 1000");
}
  
}
  
}

Ans 3

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package javaapplication8;

import java.util.Scanner;

/**
*
* @author Rashmi Tiwari
*/
public class CarRental {
  
public static void main(String args[]){
int rentPrice=0,brandPrice=0,typePrice=0,gpsPrice=0,colourPrice=0;
int choice;
Scanner sc=new Scanner(System.in);
System.out.println("Welcome to special car rental Portal");
System.out.println("Select a Car Brand");
System.out.println("1 Honda +50 QR/Day");
System.out.println("2 Toyota +70 QR/Day");
System.out.println("3 Audi +120 QR/Day");
System.out.println("4 BMW +140 QR/Day");
System.out.println("Enter your choice");
do
{
choice=sc.nextInt();
switch(choice){
case 1:
System.out.println("Selection is 1");
System.out.println("Honda is Selected");
brandPrice=50;
break;
case 2:
System.out.println("Selection is 2");
System.out.println("Toyota is Selected");
brandPrice=70;
break;
case 3:
System.out.println("Selection is 3");
System.out.println("Audi is Selected");
brandPrice=120;
break;
case 4:
System.out.println("Selection is 4");
System.out.println("BMW is Selected");
brandPrice=140;
break;
default:
System.out.println("Invalid Input");
System.out.println("Enter your choice for Car Brand Again");
  
}
}while(choice!=1&&choice!=2&&choice!=3&&choice!=4);
System.out.println("Please Select a Type");
System.out.println("1 4x4 +70 QR/Day");
System.out.println("2 Sedan +40 QR/Day");
System.out.println("3 Compact Car +10 QR/Day");
System.out.println("Enter your choice");
do
{
choice=sc.nextInt();

switch(choice){
case 1:
System.out.println("4x4 is Selected");
typePrice=70;
break;
case 2:
System.out.println("Sedan is Selected");
typePrice=40;
break;
case 3:
System.out.println("Compact Car is Selected");
typePrice=10;
break;
default:
System.out.println("Wrong Item,Please Enter right Selection");
System.out.println("Enter your choice for Car Type Again");
}
}while(choice != 1 && choice != 2 && choice != 3);
  
  
System.out.println("Would you like to have GPS");
System.out.println("1 Yes +20 QR/Day");
System.out.println("2 No +0 QR/Day");
System.out.println("Enter your choice");
  
do
{
choice=sc.nextInt();
switch(choice){
case 1:
System.out.println("Selection 1");
System.out.println("GPS is included");
gpsPrice=20;
break;
case 2:
System.out.println("Selection 2");
System.out.println("GPS is not included");
gpsPrice=0;
break;
default:
System.out.println("Invalid Choice");
System.out.println("Enter your choice for GPS Again");
  
}
  
}while(choice!=1&&choice!=2);
  
  
System.out.println("In which Colour you like to have a care");
System.out.println("1 Blue +10 QR/Day");
System.out.println("2 Black +20 QR/Day");
System.out.println("3 White +25 QR/Day");
System.out.println("Enter your choice");

do
{
choice=sc.nextInt();
switch(choice){
case 1:
System.out.println("Blue is selected");
colourPrice=10;
break;
case 2:
System.out.println("Black is selected");
colourPrice=20;
break;
case 3:
System.out.println("White is selected");
colourPrice=25;
break;   
default:
System.out.println("Invalid Choice");
System.out.println("Enter your choice for Car Colour Again");
  
}
  
}while(choice!=1&&choice!=2&&choice!=3);
  
rentPrice=brandPrice+typePrice+gpsPrice+colourPrice;
System.out.println("Thank you.Your total Daily Rate is"+rentPrice);
}
  
}

Ans 1:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package javaapplication8;

/**
*
* @author Rashmi Tiwari
*/
import java.util.Scanner;
public class NamePrint {

  

static Scanner sc = new Scanner(System.in);
  
public static void main(String[] args)
{
System.out.print(" Enter no. of rows to display : ");
int rows = sc.nextInt();
System.out.println("Enter your name");
String name=sc.next();
for(int i=0;i<name.length();i++){
char ch = name.charAt(i);
ch = Character.toUpperCase(ch);
//System.out.print(" ");
switch(ch)
{
case 'A':
A obj = new A(rows);
case 'B':
B obj1 = new B(rows);
case 'C':
C obj2 = new C(rows);
case 'D':
D obj3 = new D(rows);
case 'E':
E obj4 = new E(rows);
case 'F':
F obj5 = new F(rows);
case 'G':
G obj6 = new G(rows);
case 'H':
H obj7 = new H(rows);
case 'I':
I obj8 = new I(rows);
case 'J':
J obj9 = new J(rows);
case 'K':
K obj10 = new K(rows);
case 'L':
L obj11 = new L(rows);
case 'M':
M obj12 = new M(rows);
case 'N':
N obj13 = new N(rows);
case 'O':
O obj14 = new O(rows);
case 'P':
P obj15 = new P(rows);
case 'Q':
Q obj16 = new Q(rows);
case 'R':
R obj17 = new R(rows);
case 'S':
S obj18 = new S(rows);
case 'T':
T obj19 = new T(rows);
case 'U':
U obj20 = new U(rows);
case 'V':
V obj21 = new V(rows);
case 'W':
W obj22 = new W(rows);
case 'X':
X obj23 = new X(rows);
case 'Y':
Y obj24 = new Y(rows);
case 'Z':
Z obj25 = new Z(rows);
}
}
}}
class A
{
A(int row)
{
if(row<5)
row=5;
if(row%2==0)
row++;
for(int i=0;i<row;i++)
{
char ch = ' ';
for(int j=0;j<row-i;j++)
{
if(j==row-(i+1))
System.out.print("*");
else
System.out.print(" ");
}
if(i==(row/2))
ch='*';
for(int k=0;k<(i*2)-1;k++)
System.out.print(ch);
ch=' ';
for(int l=0;l<row-i;l++)
{
if(i==0)
continue;
if(l==0)
System.out.print("*");
else
System.out.print(" ");
}
System.out.print(" ");
}

}
}
  
class B{
B(int row){
  
}
}
class C{
C(int row){
  
}
}
class D{
D(int row){
  
}
}
class E{
E(int row){
  
}
}
class F{
F(int row){
  
}
}
class G{
G(int row){
  
}
}
class H{
H(int row){
  
}
}
class I{
I(int row){
  
}
}
class J{
J(int row){
  
}
}
class K{
K(int row){
  
}
}
class L{
L(int row){
  
}
}
class M{
M(int row){
  
}
}
class N{
N(int row){
  
}
}
class O{
O(int row){
  
}
}
class P{
P(int row){
  
}
}
class Q{
Q(int row){
  
}
}
class R{
R(int row){
  
}
}
class S{
S(int row){
  
}
}
class T{
T(int row){
  
}
}
class U{
U(int row){
  
}
}
class V{
V(int row){
  
}
}
class W{
W(int row){
  
}
}
class X{
X(int row){
  
}
}
class Y{
Y(int row){
  
}
}
class Z{
Z(int row){
  
}
}

//In similar way we have to print all charcter