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

1. Use the For the WHILE and the DO-WHile and find the sum of the numbers from 1

ID: 3622461 • Letter: 1

Question

1. Use the For the WHILE and the DO-WHile and find the sum of the numbers from 1 to 100.

You may do this in one program of 3 separate programs.

2.Find the largest number less that 100000 that is divisible by 7 11 13 and 17.
Use the modulus operator to do this.

Remember that only one number is the answer.

3.
Add the following 2 fields to the ParseEmpSolHW.java program found in the class files.

// double gpa;
// int age;
Note that the program already has the
String name;
String address;
fields all done so run the program first and then add the last 2 fields ONE AT A TIME !!!

ParseEmpSolHW.java:
// HERE'S YOUR TOOLKIT USE IT !!!!
/* i = Integer.parseInt(str);
if(i==-1) break;
l = Long.parseLong(str);
f = Float.valueOf(str).floatValue();
d = Double.valueOf(str).doubleValue();
b =Boolean.valueOf(str).booleanValue();
// as you will see you do the booleans
// like the floats and doubles !!!
// c= str[0];// nope this is C or C++
c = str.charAt(0);// correct way to read a character in Java
// zero is the first character of the string object.

System.out.println(i+" "+l+" "+f+" "+d+ " "+ c);
*/
import java.io.*;
class Emprec {
String name;
String address;
// double gpa;
// int age;
Emprec (String name,String address)
{
try{
this.name=name;
this.address=address;
} catch(NumberFormatException errmsg)
{
System.out.println("Invalid format"+ errmsg);
this.name = "";
// this.gpa = 0.0;
// this.age = 0;
}//catch
}//Emprec constructor !!!!
public String toString()
{
return
(" your name is "+ name+
" your address is "+ address);
}//toString
// see if you can get the boolean to load from a text file.
// what's missing ????
//methods !!!!
// constructors !!!
}// Emprec
class ParseEmpSolHW
{
public static void main(String args[])
throws IOException
{
BufferedReader inData = new BufferedReader(new InputStreamReader(System.in));
// create strings for the input data for the Emprec object
String str_name;
String str_address;
for(;;){
//READ THE FILE !!!!
str_name = inData.readLine();
if (str_name.equalsIgnoreCase("exit")) System.exit(0);
str_address = inData.readLine();
Emprec employee=new Emprec(str_name,str_address);
System.out.println(employee);
}//for
}//main
}//ParseEmpSol
// you may try this method System.exit(0);
// to exit from the program.



Explanation / Answer

//  save as ParseEmpSolHW.java   and run....
import java.io.IOException;

// Emprec class
class Emprec {
  String name;
  String address;
  double gpa;
  int age;


//Constructor with out arguments
  Emprec()
  {
    this.name="";
    this.address="";
    this.gpa=0.0;
    this.age=0;
  }


//Constructor with arguments
  Emprec(String name,String address,double gpa,int age)
  {
    this.name=name;
    this.address=address;
    this.gpa=gpa;
    this.age=age;
  }

//method to output result
public String toString()
{
  return (" your name is "+ name+
    " your address is "+ address +
    " your gpa is "+ gpa +
    " your age is "+ age + junk());
}//toString

String junk() {return(" Happy Birthday !!!");}

}

class ParseEmpSolHW
{
//this is the main class which contains public static void main()
//therefore your filename must be 'ParseEmpSolHW.java'
//this will not read form a file for that you must use fileReader class

  public static void main(String args[]) throws IOException
  {
    Emprec emp1 = new Emprec("Aswani","Andhra India", 12000.50,25);
    System.out.println(emp1.toString());
  }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote