3.write an algorithem and the java program that declars aminutes variable that r
ID: 3621352 • Letter: 3
Question
3.write an algorithem and the java program that declars aminutes variable that represents minutes worked on ajob and reads avalue using Dialog Box .use time as the clas name Display the value in hours and minutes. for example 197mintes becomes 3 hours ad 17 minutes save the program as time java.4. Write an algorithem aprogram that reads an integer between0 and 1000 and adds all the digits in the integer . for example if an integer is 932 the sum of all it is 14
hints ; use the % operator to extract digits and use the / operator to remove the extracted digits. for instance,932%10=2 and 932/10 =93
5.Write an algorthim ten ajava program that plays aword game with the user the program shoud ask the user to enter the following ;
His or her name
His or her age
the name of acity
the name of acollage
aprofession
after the user has entered there items the program should display the following story inserting the user's input into appropriate location.
there once was aperson name NAME who lived in CITY. at the age of AGE,NAME went to college at COLLEGE.NAME graduated and went to work as a PROFESSION
Explanation / Answer
Dear, 3. import java.io.*; // needed for file classes import javax.swing.JOptionPane; public class time { public static void main( String args[] ) { String str; int aminutes,hours,min; //Inputting aminutes value using box str = JOptionPane.showInputDialog("Enter Minutes:"); aminutes=Integer.parseInt(str); hours=aminutes/60; min=aminutes%60; System.out.println(aminutes+"minutes becomes "+hours+"hours and "+min+"minutes"); System.exit(0); } } 4. import java.io.*; // needed for file classes import javax.swing.JOptionPane; public class Sum { public static void main( String args[] ) { String str; int number,sum=0; //Inputting aminutes value using box str = JOptionPane.showInputDialog("Enter an integer between 0 and 1000 :"); number=Integer.parseInt(str); //Summing all digits logic while(number>0) { sum=sum+number%10; number=number/10; } System.out.println("Sum of all is:"+sum); System.exit(0); } } 5. import java.io.*; // needed for file classes import java.util.Scanner; //program uses class scanner public class story { public static void main( String args[] ) { //Create a Scanner to obtain input from the command // window Scanner input=new Scanner(System.in); String name,city,college,proff; int age; //inputting System.out.print("His or her Name: "); //prompt name=input.nextLine(); System.out.print("His or her age: "); age=input.nextInt(); System.out.print("the name of city: "); city=input.nextLine(); System.out.print("Name of college: "); college=input.nextLine(); System.out.print("Profession: "); proff=input.nextLine(); System.out.println("There once was aperson name "+name+" who lived in "+city+". at the age of "+age+","+name+" went to college at "+college+ "graduated and went to work as a"+proff); System.exit(0); } } Hope this will help you..
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.